Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CcTest.php
Go to the documentation of this file.
1 <?php
8 
9 class CcTest extends \PHPUnit\Framework\TestCase
10 {
14  protected $model;
15 
19  protected $objectManager;
20 
24  protected $paymentConfig;
25 
29  protected $localeDate;
30 
31  protected function setUp()
32  {
33  $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
34  $this->paymentConfig = $this->createMock(\Magento\Payment\Model\Config::class);
35  $this->localeDate = $this->createMock(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::class);
36  $context = $this->createPartialMock(\Magento\Framework\View\Element\Template\Context::class, ['getLocaleDate']);
37  $context->expects($this->any())
38  ->method('getLocaleDate')
39  ->will($this->returnValue($this->localeDate));
40  $this->model = $this->objectManager->getObject(
41  \Magento\Payment\Block\Info\Cc::class,
42  [
43  'paymentConfig' => $this->paymentConfig,
44  'context' => $context
45  ]
46  );
47  }
48 
52  public function testGetCcTypeName($configCcTypes, $ccType, $expected)
53  {
54  $this->paymentConfig->expects($this->any())
55  ->method('getCcTypes')
56  ->will($this->returnValue($configCcTypes));
57  $paymentInfo = $this->createPartialMock(\Magento\Payment\Model\Info::class, ['getCcType']);
58  $paymentInfo->expects($this->any())
59  ->method('getCcType')
60  ->will($this->returnValue($ccType));
61  $this->model->setData('info', $paymentInfo);
62  $this->assertEquals($expected, $this->model->getCcTypeName());
63  }
64 
68  public function getCcTypeNameDataProvider()
69  {
70  return [
71  [['VS', 'MC', 'JCB'], 'JCB', 'JCB'],
72  [['VS', 'MC', 'JCB'], 'BNU', 'BNU'],
73  [['VS', 'MC', 'JCB'], null, 'N/A'],
74  ];
75  }
76 
80  public function testHasCcExpDate($ccExpMonth, $ccExpYear, $expected)
81  {
82  $paymentInfo = $this->createPartialMock(\Magento\Payment\Model\Info::class, ['getCcExpMonth', 'getCcExpYear']);
83  $paymentInfo->expects($this->any())
84  ->method('getCcExpMonth')
85  ->will($this->returnValue($ccExpMonth));
86  $paymentInfo->expects($this->any())
87  ->method('getCcExpYear')
88  ->will($this->returnValue($ccExpYear));
89  $this->model->setData('info', $paymentInfo);
90  $this->assertEquals($expected, $this->model->hasCcExpDate());
91  }
92 
96  public function hasCcExpDateDataProvider()
97  {
98  return [
99  [0, 1, true],
100  [1, 0, true],
101  [0, 0, false]
102  ];
103  }
104 
108  public function testGetCcExpMonth($ccExpMonth, $expected)
109  {
110  $paymentInfo = $this->createPartialMock(\Magento\Payment\Model\Info::class, ['getCcExpMonth']);
111  $paymentInfo->expects($this->any())
112  ->method('getCcExpMonth')
113  ->will($this->returnValue($ccExpMonth));
114  $this->model->setData('info', $paymentInfo);
115  $this->assertEquals($expected, $this->model->getCcExpMonth());
116  }
117 
121  public function ccExpMonthDataProvider()
122  {
123  return [
124  [2, '02'],
125  [12, '12']
126  ];
127  }
128 
133  {
134  $paymentInfo = $this->createPartialMock(\Magento\Payment\Model\Info::class, ['getCcExpMonth', 'getCcExpYear']);
136  ->expects($this->any())
137  ->method('getCcExpMonth')
138  ->willReturn($ccExpMonth);
140  ->expects($this->any())
141  ->method('getCcExpYear')
142  ->willReturn($ccExpYear);
143  $this->model->setData('info', $paymentInfo);
144 
145  $this->localeDate
146  ->expects($this->exactly(2))
147  ->method('getConfigTimezone')
148  ->willReturn('America/Los_Angeles');
149 
150  $this->assertEquals($ccExpYear, $this->model->getCcExpDate()->format('Y'));
151  $this->assertEquals($ccExpMonth, $this->model->getCcExpDate()->format('m'));
152  }
153 
157  public function getCcExpDateDataProvider()
158  {
159  return [
160  [3, 2015],
161  [12, 2011],
162  [01, 2036]
163  ];
164  }
165 }
$paymentInfo
$ccExpYear
Definition: info.phtml:18
$ccExpMonth
Definition: info.phtml:17
testHasCcExpDate($ccExpMonth, $ccExpYear, $expected)
Definition: CcTest.php:80
testGetCcTypeName($configCcTypes, $ccType, $expected)
Definition: CcTest.php:52
$ccType
Definition: info.phtml:16
testGetCcExpDate($ccExpMonth, $ccExpYear)
Definition: CcTest.php:132
testGetCcExpMonth($ccExpMonth, $expected)
Definition: CcTest.php:108