CcConfigProviderTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Payment\Test\Unit\Model;
  7. class CcConfigProviderTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \Magento\Payment\Model\CcConfigProvider
  11. */
  12. protected $model;
  13. /**
  14. * @var \PHPUnit_Framework_MockObject_MockObject
  15. */
  16. protected $ccConfigMock;
  17. /**
  18. * @var \PHPUnit_Framework_MockObject_MockObject
  19. */
  20. protected $assetSourceMock;
  21. protected function setUp()
  22. {
  23. $this->ccConfigMock = $this->createMock(\Magento\Payment\Model\CcConfig::class);
  24. $this->assetSourceMock = $this->createMock(\Magento\Framework\View\Asset\Source::class);
  25. $this->model = new \Magento\Payment\Model\CcConfigProvider(
  26. $this->ccConfigMock,
  27. $this->assetSourceMock
  28. );
  29. }
  30. public function testGetConfig()
  31. {
  32. $imagesDirectoryPath = __DIR__ . '/../../../view/base/web/images/cc/';
  33. $expectedResult = [
  34. 'payment' => [
  35. 'ccform' => [
  36. 'icons' => [
  37. 'vi' => [
  38. 'url' => 'http://cc.card/vi.png',
  39. 'width' => getimagesize($imagesDirectoryPath . 'vi.png')[0],
  40. 'height' => getimagesize($imagesDirectoryPath . 'vi.png')[1]
  41. ],
  42. 'ae' => [
  43. 'url' => 'http://cc.card/ae.png',
  44. 'width' => getimagesize($imagesDirectoryPath . 'ae.png')[0],
  45. 'height' => getimagesize($imagesDirectoryPath . 'ae.png')[1]
  46. ]
  47. ]
  48. ]
  49. ]
  50. ];
  51. $ccAvailableTypesMock = [
  52. 'vi' => [
  53. 'fileId' => 'Magento_Payment::images/cc/vi.png',
  54. 'path' => $imagesDirectoryPath . 'vi.png',
  55. 'url' => 'http://cc.card/vi.png'
  56. ],
  57. 'ae' => [
  58. 'fileId' => 'Magento_Payment::images/cc/ae.png',
  59. 'path' => $imagesDirectoryPath . 'ae.png',
  60. 'url' => 'http://cc.card/ae.png'
  61. ]
  62. ];
  63. $assetMock = $this->createMock(\Magento\Framework\View\Asset\File::class);
  64. $this->ccConfigMock->expects($this->once())->method('getCcAvailableTypes')->willReturn($ccAvailableTypesMock);
  65. $this->ccConfigMock->expects($this->atLeastOnce())
  66. ->method('createAsset')
  67. ->withConsecutive(
  68. [$ccAvailableTypesMock['vi']['fileId']],
  69. [$ccAvailableTypesMock['ae']['fileId']]
  70. )->willReturn($assetMock);
  71. $this->assetSourceMock->expects($this->atLeastOnce())
  72. ->method('findSource')
  73. ->with($assetMock)
  74. ->willReturnOnConsecutiveCalls(
  75. $ccAvailableTypesMock['vi']['path'],
  76. $ccAvailableTypesMock['ae']['path']
  77. );
  78. $assetMock->expects($this->atLeastOnce())
  79. ->method('getSourceFile')
  80. ->willReturnOnConsecutiveCalls(
  81. $ccAvailableTypesMock['vi']['path'],
  82. $ccAvailableTypesMock['ae']['path']
  83. );
  84. $assetMock->expects($this->atLeastOnce())
  85. ->method('getUrl')
  86. ->willReturnOnConsecutiveCalls(
  87. $ccAvailableTypesMock['vi']['url'],
  88. $ccAvailableTypesMock['ae']['url']
  89. );
  90. $this->assertEquals($expectedResult, $this->model->getConfig());
  91. }
  92. }