Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
InfoTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class InfoTest extends \PHPUnit\Framework\TestCase
11 {
15  protected $_object;
16 
20  protected $_storeManager;
21 
25  protected $_eventManager;
26 
30  protected $_escaper;
31 
32  protected function setUp()
33  {
34  $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
35  $this->_storeManager = $this->getMockBuilder(
36  \Magento\Store\Model\StoreManager::class
37  )->setMethods(
38  ['getStore']
39  )->disableOriginalConstructor()->getMock();
40  $this->_eventManager = $this->getMockBuilder(
41  \Magento\Framework\Event\ManagerInterface::class
42  )->setMethods(
43  ['dispatch']
44  )->disableOriginalConstructor()->getMock();
45  $this->_escaper = $helper->getObject(\Magento\Framework\Escaper::class);
46  $context = $helper->getObject(
47  \Magento\Framework\View\Element\Template\Context::class,
48  [
49  'storeManager' => $this->_storeManager,
50  'eventManager' => $this->_eventManager,
51  'escaper' => $this->_escaper
52  ]
53  );
54  $this->_object = $helper->getObject(\Magento\Payment\Block\Info::class, ['context' => $context]);
55  }
56 
65  public function testGetIsSecureMode($isSecureMode, $methodInstance, $store, $storeCode, $expectedResult)
66  {
67  if (isset($store)) {
68  $methodInstance = $this->_getMethodInstanceMock($store);
69  }
70 
71  if (isset($storeCode)) {
72  $storeMock = $this->_getStoreMock($storeCode);
73  $this->_storeManager->expects($this->any())->method('getStore')->will($this->returnValue($storeMock));
74  }
75 
76  $paymentInfo = $this->getMockBuilder(\Magento\Payment\Model\Info::class)
77  ->disableOriginalConstructor()->getMock();
78  $paymentInfo->expects($this->any())->method('getMethodInstance')->will($this->returnValue($methodInstance));
79 
80  $this->_object->setData('info', $paymentInfo);
81  $this->_object->setData('is_secure_mode', $isSecureMode);
82  $result = $this->_object->getIsSecureMode();
83  $this->assertEquals($result, $expectedResult);
84  }
85 
89  public function getIsSecureModeDataProvider()
90  {
91  return [
92  [false, true, null, null, false],
93  [true, true, null, null, true],
94  [null, false, null, null, true],
95  [null, null, false, null, false],
96  [null, null, true, 'default', true],
97  [null, null, true, 'admin', false]
98  ];
99  }
100 
105  protected function _getMethodInstanceMock($store)
106  {
107  $methodInstance = $this->getMockBuilder(
108  \Magento\Payment\Model\Method\AbstractMethod::class
109  )->setMethods(
110  ['getStore']
111  )->disableOriginalConstructor()->getMock();
112  $methodInstance->expects($this->any())->method('getStore')->will($this->returnValue($store));
113  return $methodInstance;
114  }
115 
120  protected function _getStoreMock($storeCode)
121  {
122  $storeMock = $this->getMockBuilder(\Magento\Store\Model\Store::class)->disableOriginalConstructor()->getMock();
123  $storeMock->expects($this->any())->method('getCode')->will($this->returnValue($storeCode));
124  return $storeMock;
125  }
126 
130  public function testGetInfoThrowException()
131  {
132  $this->_object->setData('info', new \Magento\Framework\DataObject([]));
133  $this->_object->getInfo();
134  }
135 
136  public function testGetSpecificInformation()
137  {
138  $paymentInfo = $this->getMockBuilder(\Magento\Payment\Model\Info::class)
139  ->disableOriginalConstructor()->getMock();
140 
141  $this->_object->setData('info', $paymentInfo);
142  $result = $this->_object->getSpecificInformation();
143  $this->assertNotNull($result);
144  }
145 
149  public function testGetValueAsArray($value, $escapeHtml, $expected)
150  {
151  $result = $this->_object->getValueAsArray($value, $escapeHtml);
152  $this->assertEquals($expected, $result);
153  }
154 
158  public function getValueAsArrayDataProvider()
159  {
160  return [
161  [[], true, []],
162  [[], false, []],
163  ['string', true, [0 => 'string']],
164  ['string', false, ['string']],
165  [['key' => 'v"a!@#%$%^^&&*(*/\'\]l'], true, ['key' => 'v&quot;a!@#%$%^^&amp;&amp;*(*/&#039;\]l']],
166  [['key' => 'val'], false, ['key' => 'val']]
167  ];
168  }
169 }
testGetIsSecureMode($isSecureMode, $methodInstance, $store, $storeCode, $expectedResult)
Definition: InfoTest.php:65
$helper
Definition: iframe.phtml:13
$paymentInfo
$storeCode
Definition: indexer.php:15
$value
Definition: gender.phtml:16
testGetValueAsArray($value, $escapeHtml, $expected)
Definition: InfoTest.php:149