<commit_before><commit_msg>[klarna] add tests for status action.<commit_after><?php
namespace Payum\Klarna\Invoice\Tests\Action;

use Payum\Core\Request\GetHumanStatus;
use Payum\Klarna\Invoice\Action\StatusAction;

class StatusActionTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @test
     */
    public function shouldImplementsActionInterface()
    {
        $rc = new \ReflectionClass('Payum\Klarna\Invoice\Action\StatusAction');

        $this->assertTrue($rc->implementsInterface('Payum\Core\Action\ActionInterface'));
    }

    /**
     * @test
     */
    public function couldBeConstructedWithoutAnyArguments()
    {
        new StatusAction;
    }

    /**
     * @test
     */
    public function shouldSupportGetStatusWithArrayAsModel()
    {
        $action = new StatusAction();

        $this->assertTrue($action->supports(new GetHumanStatus(array())));
    }

    /**
     * @test
     */
    public function shouldNotSupportAnythingNotGetStatus()
    {
        $action = new StatusAction;

        $this->assertFalse($action->supports(new \stdClass()));
    }

    /**
     * @test
     */
    public function shouldNotSupportGetStatusWithNotArrayAccessModel()
    {
        $action = new StatusAction;

        $this->assertFalse($action->supports(new GetHumanStatus(new \stdClass)));
    }

    /**
     * @test
     *
     * @expectedException \Payum\Core\Exception\RequestNotSupportedException
     */
    public function throwIfNotSupportedRequestGivenAsArgumentOnExecute()
    {
        $action = new StatusAction;

        $action->execute(new \stdClass());
    }

    /**
     * @test
     */
    public function shouldMarkAsNew()
    {
        $action = new StatusAction;

        $action->execute($getStatus = new GetHumanStatus(array()));

        $this->assertTrue($getStatus->isNew());
    }

    /**
     * @test
     */
    public function shouldMarkFailedIfErrorCodeSet()
    {
        $action = new StatusAction;

        $action->execute($getStatus = new GetHumanStatus(array(
            'error_code' => 'aCode',
        )));

        $this->assertTrue($getStatus->isFailed());
    }

    /**
     * @test
     */
    public function shouldMarkCanceledIfCanceledPropertySet()
    {
        $action = new StatusAction;

        $action->execute($getStatus = new GetHumanStatus(array(
            'canceled' => true,
        )));

        $this->assertTrue($getStatus->isCanceled());
    }

    /**
     * @test
     */
    public function shouldMarkSuccessIfInvoiceNumberSet()
    {
        $action = new StatusAction;

        $action->execute($getStatus = new GetHumanStatus(array(
            'invoice_number' => 'aNumber',
        )));

        $this->assertTrue($getStatus->isSuccess());
    }

    /**
     * @test
     */
    public function shouldMarkPendingIfStatusAccepted()
    {
        $action = new StatusAction;

        $action->execute($getStatus = new GetHumanStatus(array(
            'status' => \KlarnaFlags::ACCEPTED,
        )));

        $this->assertTrue($getStatus->isPending());
    }

    /**
     * @test
     */
    public function shouldMarkPendingIfStatusPending()
    {
        $action = new StatusAction;

        $action->execute($getStatus = new GetHumanStatus(array(
            'status' => \KlarnaFlags::PENDING,
        )));

        $this->assertTrue($getStatus->isPending());
    }

    /**
     * @test
     */
    public function shouldMarkFailedIfStatusDenied()
    {
        $action = new StatusAction;

        $action->execute($getStatus = new GetHumanStatus(array(
            'status' => \KlarnaFlags::DENIED,
        )));

        $this->assertTrue($getStatus->isFailed());
    }

    /**
     * @test
     */
    public function shouldMarkUnknownIfStatusUnknown()
    {
        $action = new StatusAction;

        $action->execute($getStatus = new GetHumanStatus(array(
            'status' => 'unknown',
        )));

        $this->assertTrue($getStatus->isUnknown());
    }
}
{'fraction_non_alphanumeric': 0.13624937154348918, 'fraction_numerical': 0.0, 'mean_word_length': 2.310316139767055, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7128588', 'n_tokens_mistral': 1154, 'n_tokens_neox': 1123, 'n_words': 171}