ChannelDataBuilderTest.php 2.63 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
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\Braintree\Test\Unit\Gateway\Request;

use Magento\Braintree\Gateway\Request\ChannelDataBuilder;
use Magento\Framework\App\ProductMetadataInterface;
use Magento\Payment\Gateway\Config\Config;
use PHPUnit_Framework_MockObject_MockObject as MockObject;

/**
 * Class PaymentDataBuilderTest
 *
 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
 */
class ChannelDataBuilderTest extends \PHPUnit\Framework\TestCase
{
    /**
     * @var ProductMetadataInterface|MockObject
     */
    private $productMetadata;

    /**
     * @var Config|MockObject
     */
    private $config;

    /**
     * @var ChannelDataBuilder
     */
    private $builder;

    /**
     * @inheritdoc
     */
    protected function setUp()
    {
        $this->productMetadata = $this->getMockBuilder(ProductMetadataInterface::class)
            ->disableOriginalConstructor()
            ->getMock();
        $this->config = $this->getMockBuilder(Config::class)
            ->disableOriginalConstructor()
            ->getMock();
        $this->builder = new ChannelDataBuilder($this->productMetadata, $this->config);
    }

    /**
     * @param string $edition
     * @param array $expected
     * @covers \Magento\Braintree\Gateway\Request\ChannelDataBuilder::build
     * @dataProvider buildDataProvider
     */
    public function testBuild($edition, array $expected)
    {
        $buildSubject = [];

        $this->config->method('getValue')
            ->with(self::equalTo('channel'))
            ->willReturn(null);

        $this->productMetadata->method('getEdition')
            ->willReturn($edition);

        self::assertEquals($expected, $this->builder->build($buildSubject));
    }

    /**
     * Checks a case when a channel provided via payment method configuration.
     */
    public function testBuildWithChannelFromConfig()
    {
        $channel = 'Magento2_Cart_ConfigEdition_BT';

        $this->config->method('getValue')
            ->with(self::equalTo('channel'))
            ->willReturn($channel);

        $this->productMetadata->expects(self::never())
            ->method('getEdition');

        self::assertEquals(
            [
                'channel' => $channel
            ],
            $this->builder->build([])
        );
    }

    /**
     * Get list of variations for build test
     * @return array
     */
    public function buildDataProvider()
    {
        return [
            ['FirstEdition', ['channel' => 'Magento2_Cart_FirstEdition_BT']],
            ['SecondEdition', ['channel' => 'Magento2_Cart_SecondEdition_BT']],
        ];
    }
}