CheckmoTest.php 3.39 KB
Newer Older
Ketan's avatar
Ketan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\OfflinePayments\Test\Unit\Block\Info;

use Magento\Framework\View\Element\Template\Context;
use Magento\OfflinePayments\Block\Info\Checkmo;
use Magento\Payment\Model\Info;
use PHPUnit_Framework_MockObject_MockObject as MockObject;

/**
 * CheckmoTest contains list of test for block methods testing
 */
class CheckmoTest extends \PHPUnit\Framework\TestCase
{
    /**
     * @var Info|MockObject
     */
    private $info;

    /**
     * @var Checkmo
     */
    private $block;

    /**
     * @inheritdoc
     */
    protected function setUp()
    {
        $context = $this->getMockBuilder(Context::class)
            ->disableOriginalConstructor()
            ->setMethods([])
            ->getMock();

        $this->info = $this->getMockBuilder(Info::class)
            ->disableOriginalConstructor()
            ->setMethods(['getAdditionalInformation'])
            ->getMock();

        $this->block = new Checkmo($context);
    }

    /**
     * @covers \Magento\OfflinePayments\Block\Info\Checkmo::getPayableTo
     * @param array $details
     * @param string|null $expected
     * @dataProvider getPayableToDataProvider
     */
    public function testGetPayableTo($details, $expected)
    {
        $this->info->expects(static::at(0))
            ->method('getAdditionalInformation')
            ->with('payable_to')
            ->willReturn($details);
        $this->block->setData('info', $this->info);

        static::assertEquals($expected, $this->block->getPayableTo());
    }

    /**
     * Get list of variations for payable configuration option testing
     * @return array
     */
    public function getPayableToDataProvider()
    {
        return [
            ['payable_to' => 'payable', 'payable'],
            ['', null]
        ];
    }

    /**
     * @covers \Magento\OfflinePayments\Block\Info\Checkmo::getMailingAddress
     * @param array $details
     * @param string|null $expected
     * @dataProvider getMailingAddressDataProvider
     */
    public function testGetMailingAddress($details, $expected)
    {
        $this->info->expects(static::at(1))
            ->method('getAdditionalInformation')
            ->with('mailing_address')
            ->willReturn($details);
        $this->block->setData('info', $this->info);

        static::assertEquals($expected, $this->block->getMailingAddress());
    }

    /**
     * Get list of variations for mailing address testing
     * @return array
     */
    public function getMailingAddressDataProvider()
    {
        return [
            ['mailing_address' => 'blah@blah.com', 'blah@blah.com'],
            ['mailing_address' => '', null]
        ];
    }

    /**
     * @covers \Magento\OfflinePayments\Block\Info\Checkmo::getMailingAddress
     */
    public function testConvertAdditionalDataIsNeverCalled()
    {
        $mailingAddress = 'blah@blah.com';
        $this->info->expects(static::at(1))
            ->method('getAdditionalInformation')
            ->with('mailing_address')
            ->willReturn($mailingAddress);
        $this->block->setData('info', $this->info);

        // First we set the property $this->_mailingAddress
        $this->block->getMailingAddress();

        // And now we get already setted property $this->_mailingAddress
        static::assertEquals($mailingAddress, $this->block->getMailingAddress());
    }
}