Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CcConfigProviderTest.php
Go to the documentation of this file.
1 <?php
7 
8 class CcConfigProviderTest extends \PHPUnit\Framework\TestCase
9 {
13  protected $model;
14 
18  protected $ccConfigMock;
19 
23  protected $assetSourceMock;
24 
25  protected function setUp()
26  {
27  $this->ccConfigMock = $this->createMock(\Magento\Payment\Model\CcConfig::class);
28  $this->assetSourceMock = $this->createMock(\Magento\Framework\View\Asset\Source::class);
29  $this->model = new \Magento\Payment\Model\CcConfigProvider(
30  $this->ccConfigMock,
31  $this->assetSourceMock
32  );
33  }
34 
35  public function testGetConfig()
36  {
37  $imagesDirectoryPath = __DIR__ . '/../../../view/base/web/images/cc/';
38  $expectedResult = [
39  'payment' => [
40  'ccform' => [
41  'icons' => [
42  'vi' => [
43  'url' => 'http://cc.card/vi.png',
44  'width' => getimagesize($imagesDirectoryPath . 'vi.png')[0],
45  'height' => getimagesize($imagesDirectoryPath . 'vi.png')[1]
46  ],
47  'ae' => [
48  'url' => 'http://cc.card/ae.png',
49  'width' => getimagesize($imagesDirectoryPath . 'ae.png')[0],
50  'height' => getimagesize($imagesDirectoryPath . 'ae.png')[1]
51  ]
52  ]
53  ]
54  ]
55  ];
56 
57  $ccAvailableTypesMock = [
58  'vi' => [
59  'fileId' => 'Magento_Payment::images/cc/vi.png',
60  'path' => $imagesDirectoryPath . 'vi.png',
61  'url' => 'http://cc.card/vi.png'
62  ],
63  'ae' => [
64  'fileId' => 'Magento_Payment::images/cc/ae.png',
65  'path' => $imagesDirectoryPath . 'ae.png',
66  'url' => 'http://cc.card/ae.png'
67  ]
68  ];
69  $assetMock = $this->createMock(\Magento\Framework\View\Asset\File::class);
70 
71  $this->ccConfigMock->expects($this->once())->method('getCcAvailableTypes')->willReturn($ccAvailableTypesMock);
72 
73  $this->ccConfigMock->expects($this->atLeastOnce())
74  ->method('createAsset')
75  ->withConsecutive(
76  [$ccAvailableTypesMock['vi']['fileId']],
77  [$ccAvailableTypesMock['ae']['fileId']]
78  )->willReturn($assetMock);
79  $this->assetSourceMock->expects($this->atLeastOnce())
80  ->method('findSource')
81  ->with($assetMock)
82  ->willReturnOnConsecutiveCalls(
83  $ccAvailableTypesMock['vi']['path'],
84  $ccAvailableTypesMock['ae']['path']
85  );
86  $assetMock->expects($this->atLeastOnce())
87  ->method('getSourceFile')
88  ->willReturnOnConsecutiveCalls(
89  $ccAvailableTypesMock['vi']['path'],
90  $ccAvailableTypesMock['ae']['path']
91  );
92  $assetMock->expects($this->atLeastOnce())
93  ->method('getUrl')
94  ->willReturnOnConsecutiveCalls(
95  $ccAvailableTypesMock['vi']['url'],
96  $ccAvailableTypesMock['ae']['url']
97  );
98 
99  $this->assertEquals($expectedResult, $this->model->getConfig());
100  }
101 }
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60