CcTest.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Payment\Test\Unit\Block\Info;
  7. class CcTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \Magento\Payment\Block\Info\Cc
  11. */
  12. protected $model;
  13. /**
  14. * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
  15. */
  16. protected $objectManager;
  17. /**
  18. * @var \Magento\Payment\Model\Config|\PHPUnit_Framework_MockObject_MockObject
  19. */
  20. protected $paymentConfig;
  21. /**
  22. * @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface|\PHPUnit_Framework_MockObject_MockObject
  23. */
  24. protected $localeDate;
  25. protected function setUp()
  26. {
  27. $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  28. $this->paymentConfig = $this->createMock(\Magento\Payment\Model\Config::class);
  29. $this->localeDate = $this->createMock(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::class);
  30. $context = $this->createPartialMock(\Magento\Framework\View\Element\Template\Context::class, ['getLocaleDate']);
  31. $context->expects($this->any())
  32. ->method('getLocaleDate')
  33. ->will($this->returnValue($this->localeDate));
  34. $this->model = $this->objectManager->getObject(
  35. \Magento\Payment\Block\Info\Cc::class,
  36. [
  37. 'paymentConfig' => $this->paymentConfig,
  38. 'context' => $context
  39. ]
  40. );
  41. }
  42. /**
  43. * @dataProvider getCcTypeNameDataProvider
  44. */
  45. public function testGetCcTypeName($configCcTypes, $ccType, $expected)
  46. {
  47. $this->paymentConfig->expects($this->any())
  48. ->method('getCcTypes')
  49. ->will($this->returnValue($configCcTypes));
  50. $paymentInfo = $this->createPartialMock(\Magento\Payment\Model\Info::class, ['getCcType']);
  51. $paymentInfo->expects($this->any())
  52. ->method('getCcType')
  53. ->will($this->returnValue($ccType));
  54. $this->model->setData('info', $paymentInfo);
  55. $this->assertEquals($expected, $this->model->getCcTypeName());
  56. }
  57. /**
  58. * @return array
  59. */
  60. public function getCcTypeNameDataProvider()
  61. {
  62. return [
  63. [['VS', 'MC', 'JCB'], 'JCB', 'JCB'],
  64. [['VS', 'MC', 'JCB'], 'BNU', 'BNU'],
  65. [['VS', 'MC', 'JCB'], null, 'N/A'],
  66. ];
  67. }
  68. /**
  69. * @dataProvider hasCcExpDateDataProvider
  70. */
  71. public function testHasCcExpDate($ccExpMonth, $ccExpYear, $expected)
  72. {
  73. $paymentInfo = $this->createPartialMock(\Magento\Payment\Model\Info::class, ['getCcExpMonth', 'getCcExpYear']);
  74. $paymentInfo->expects($this->any())
  75. ->method('getCcExpMonth')
  76. ->will($this->returnValue($ccExpMonth));
  77. $paymentInfo->expects($this->any())
  78. ->method('getCcExpYear')
  79. ->will($this->returnValue($ccExpYear));
  80. $this->model->setData('info', $paymentInfo);
  81. $this->assertEquals($expected, $this->model->hasCcExpDate());
  82. }
  83. /**
  84. * @return array
  85. */
  86. public function hasCcExpDateDataProvider()
  87. {
  88. return [
  89. [0, 1, true],
  90. [1, 0, true],
  91. [0, 0, false]
  92. ];
  93. }
  94. /**
  95. * @dataProvider ccExpMonthDataProvider
  96. */
  97. public function testGetCcExpMonth($ccExpMonth, $expected)
  98. {
  99. $paymentInfo = $this->createPartialMock(\Magento\Payment\Model\Info::class, ['getCcExpMonth']);
  100. $paymentInfo->expects($this->any())
  101. ->method('getCcExpMonth')
  102. ->will($this->returnValue($ccExpMonth));
  103. $this->model->setData('info', $paymentInfo);
  104. $this->assertEquals($expected, $this->model->getCcExpMonth());
  105. }
  106. /**
  107. * @return array
  108. */
  109. public function ccExpMonthDataProvider()
  110. {
  111. return [
  112. [2, '02'],
  113. [12, '12']
  114. ];
  115. }
  116. /**
  117. * @dataProvider getCcExpDateDataProvider
  118. */
  119. public function testGetCcExpDate($ccExpMonth, $ccExpYear)
  120. {
  121. $paymentInfo = $this->createPartialMock(\Magento\Payment\Model\Info::class, ['getCcExpMonth', 'getCcExpYear']);
  122. $paymentInfo
  123. ->expects($this->any())
  124. ->method('getCcExpMonth')
  125. ->willReturn($ccExpMonth);
  126. $paymentInfo
  127. ->expects($this->any())
  128. ->method('getCcExpYear')
  129. ->willReturn($ccExpYear);
  130. $this->model->setData('info', $paymentInfo);
  131. $this->localeDate
  132. ->expects($this->exactly(2))
  133. ->method('getConfigTimezone')
  134. ->willReturn('America/Los_Angeles');
  135. $this->assertEquals($ccExpYear, $this->model->getCcExpDate()->format('Y'));
  136. $this->assertEquals($ccExpMonth, $this->model->getCcExpDate()->format('m'));
  137. }
  138. /**
  139. * @return array
  140. */
  141. public function getCcExpDateDataProvider()
  142. {
  143. return [
  144. [3, 2015],
  145. [12, 2011],
  146. [01, 2036]
  147. ];
  148. }
  149. }