CcConfigTest.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. use Magento\Framework\Exception\LocalizedException;
  8. class CcConfigTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /** @var \Magento\Payment\Model\CcConfig */
  11. protected $model;
  12. /** @var \Magento\Payment\Model\Config|\PHPUnit_Framework_MockObject_MockObject */
  13. protected $configMock;
  14. /** @var \Magento\Framework\View\Asset\Repository|\PHPUnit_Framework_MockObject_MockObject */
  15. protected $repositoryMock;
  16. /** @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject */
  17. protected $requestMock;
  18. /** @var \Magento\Framework\UrlInterface|\PHPUnit_Framework_MockObject_MockObject */
  19. protected $urlMock;
  20. /** @var \Psr\Log\LoggerInterface|\PHPUnit_Framework_MockObject_MockObject */
  21. protected $loggerMock;
  22. protected function setUp()
  23. {
  24. $this->configMock = $this->createMock(\Magento\Payment\Model\Config::class);
  25. $this->repositoryMock = $this->createMock(\Magento\Framework\View\Asset\Repository::class);
  26. $this->requestMock = $this->createMock(\Magento\Framework\App\RequestInterface::class);
  27. $this->urlMock = $this->createMock(\Magento\Framework\UrlInterface::class);
  28. $this->loggerMock = $this->createMock(\Psr\Log\LoggerInterface::class);
  29. $this->model = new \Magento\Payment\Model\CcConfig(
  30. $this->configMock,
  31. $this->repositoryMock,
  32. $this->requestMock,
  33. $this->urlMock,
  34. $this->loggerMock
  35. );
  36. }
  37. public function testGetCcAvailableTypes()
  38. {
  39. $data = [1, 2, 3];
  40. $this->configMock->expects($this->once())
  41. ->method('getCcTypes')
  42. ->willReturn($data);
  43. $this->assertEquals($data, $this->model->getCcAvailableTypes());
  44. }
  45. public function testGetCcMonths()
  46. {
  47. $data = [1, 2, 3];
  48. $this->configMock->expects($this->once())
  49. ->method('getMonths')
  50. ->willReturn($data);
  51. $this->assertEquals($data, $this->model->getCcMonths());
  52. }
  53. public function testGetCcYears()
  54. {
  55. $data = [1, 2, 3];
  56. $this->configMock->expects($this->once())
  57. ->method('getYears')
  58. ->willReturn($data);
  59. $this->assertEquals($data, $this->model->getCcYears());
  60. }
  61. public function testHasVerification()
  62. {
  63. $this->assertEquals(true, $this->model->hasVerification());
  64. }
  65. public function testGetCvvImageUrl()
  66. {
  67. $params = ['_secure' => true];
  68. $fileId = 'Magento_Checkout::cvv.png';
  69. $fileUrl = 'file url';
  70. $this->requestMock->expects($this->once())
  71. ->method('isSecure')
  72. ->willReturn(true);
  73. $this->repositoryMock->expects($this->once())
  74. ->method('getUrlWithParams')
  75. ->with($fileId, $params)
  76. ->willReturn($fileUrl);
  77. $this->assertEquals($fileUrl, $this->model->getCvvImageUrl());
  78. }
  79. public function getViewFileUrlWithException()
  80. {
  81. $params = ['a' => 'b'];
  82. $paramsSecure = ['a' => 'b', '_secure' => false];
  83. $fileId = 'file id';
  84. $fileUrl = 'exception url';
  85. $this->requestMock->expects($this->once())
  86. ->method('isSecure')
  87. ->willReturn(false);
  88. $exception = new LocalizedException('message');
  89. $this->repositoryMock->expects($this->once())
  90. ->method('getUrlWithParams')
  91. ->with($fileId, $paramsSecure)
  92. ->willThrowException($exception);
  93. $this->loggerMock->expects($this->once())
  94. ->method('critical')
  95. ->with($exception);
  96. $this->urlMock->expects($this->once())
  97. ->method('getUrl')
  98. ->with('', ['_direct' => 'core/index/notFound'])
  99. ->willReturn($fileUrl);
  100. $this->assertEquals($fileUrl, $this->model->getViewFileUrl($fileId, $params));
  101. }
  102. }