Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
InfoTest Class Reference
Inheritance diagram for InfoTest:

Public Member Functions

 testGetDataCcNumber ($keyCc, $keyCcEnc)
 
 ccKeysDataProvider ()
 
 testGetMethodInstanceWithRealMethod ()
 
 testGetMethodInstanceWithUnrealMethod ()
 
 testGetMethodInstanceWithNoMethod ()
 
 testGetMethodInstanceRequestedMethod ()
 
 testEncrypt ()
 
 testDecrypt ()
 
 testSetAdditionalInformationException ()
 
 testSetAdditionalInformationMultipleTypes ($key, $value=null)
 
 additionalInformationDataProvider ()
 
 testGetAdditionalInformationByKey ()
 
 testUnsAdditionalInformation ()
 
 testHasAdditionalInformation ()
 
 testInitAdditionalInformationWithUnserialize ()
 

Protected Member Functions

 setUp ()
 

Protected Attributes

 $info
 
 $objectManagerHelper
 
 $contextMock
 
 $registryMock
 
 $paymentHelperMock
 
 $encryptorInterfaceMock
 
 $methodInstanceMock
 

Detailed Description

Definition at line 12 of file InfoTest.php.

Member Function Documentation

◆ additionalInformationDataProvider()

additionalInformationDataProvider ( )

Prepared data for testSetAdditionalInformationMultipleTypes

Returns
array

Definition at line 198 of file InfoTest.php.

199  {
200  return [
201  [['key1' => 'data1', 'key2' => 'data2'], null],
202  ['key', 'data']
203  ];
204  }

◆ ccKeysDataProvider()

ccKeysDataProvider ( )

Returns array of Cc keys which needs prepare logic

Returns
array

Definition at line 79 of file InfoTest.php.

80  {
81  return [
82  ['cc_number', 'cc_number_enc'],
83  ['cc_cid', 'cc_cid_enc']
84  ];
85  }

◆ setUp()

setUp ( )
protected

Definition at line 35 of file InfoTest.php.

36  {
37  $this->contextMock = $this->createMock(\Magento\Framework\Model\Context::class);
38  $this->registryMock = $this->createMock(\Magento\Framework\Registry::class);
39  $this->paymentHelperMock = $this->createPartialMock(\Magento\Payment\Helper\Data::class, ['getMethodInstance']);
40  $this->encryptorInterfaceMock = $this->createMock(\Magento\Framework\Encryption\EncryptorInterface::class);
41  $this->methodInstanceMock = $this->getMockBuilder(\Magento\Payment\Model\MethodInterface::class)
42  ->getMockForAbstractClass();
43 
44  $this->objectManagerHelper = new ObjectManagerHelper($this);
45  $this->info = $this->objectManagerHelper->getObject(
46  \Magento\Payment\Model\Info::class,
47  [
48  'context' => $this->contextMock,
49  'registry' => $this->registryMock,
50  'paymentData' => $this->paymentHelperMock,
51  'encryptor' => $this->encryptorInterfaceMock
52  ]
53  );
54  }

◆ testDecrypt()

testDecrypt ( )

Definition at line 163 of file InfoTest.php.

164  {
165  $data = 'data';
166  $encryptedData = 'd1a2t3a4';
167 
168  $this->encryptorInterfaceMock->expects($this->once())->method('decrypt')->with($encryptedData)->will(
169  $this->returnValue($data)
170  );
171  $this->assertEquals($data, $this->info->decrypt($encryptedData));
172  }

◆ testEncrypt()

testEncrypt ( )

Definition at line 152 of file InfoTest.php.

153  {
154  $data = 'data';
155  $encryptedData = 'd1a2t3a4';
156 
157  $this->encryptorInterfaceMock->expects($this->once())->method('encrypt')->with($data)->will(
158  $this->returnValue($encryptedData)
159  );
160  $this->assertEquals($encryptedData, $this->info->encrypt($data));
161  }

◆ testGetAdditionalInformationByKey()

testGetAdditionalInformationByKey ( )

Definition at line 206 of file InfoTest.php.

207  {
208  $key = 'key';
209  $value = 'value';
210  $this->info->setAdditionalInformation($key, $value);
211  $this->assertEquals($value, $this->info->getAdditionalInformation($key));
212  }
$value
Definition: gender.phtml:16

◆ testGetDataCcNumber()

testGetDataCcNumber (   $keyCc,
  $keyCcEnc 
)

@dataProvider ccKeysDataProvider

Parameters
string$keyCc
string$keyCcEnc

Definition at line 61 of file InfoTest.php.

62  {
63  // no data was set
64  $this->assertNull($this->info->getData($keyCc));
65 
66  // we set encrypted data
67  $this->info->setData($keyCcEnc, $keyCcEnc);
68  $this->encryptorInterfaceMock->expects($this->once())->method('decrypt')->with($keyCcEnc)->will(
69  $this->returnValue($keyCc)
70  );
71  $this->assertEquals($keyCc, $this->info->getData($keyCc));
72  }

◆ testGetMethodInstanceRequestedMethod()

testGetMethodInstanceRequestedMethod ( )

Definition at line 136 of file InfoTest.php.

137  {
138  $code = 'real_method';
139  $this->info->setData('method', $code);
140 
141  $this->paymentHelperMock->expects($this->once())->method('getMethodInstance')->with($code)->will(
142  $this->returnValue($this->methodInstanceMock)
143  );
144 
145  $this->methodInstanceMock->expects($this->once())->method('setInfoInstance')->with($this->info);
146  $this->assertSame($this->methodInstanceMock, $this->info->getMethodInstance());
147 
148  // as the method is already stored at Info, check that it's not initialized again
149  $this->assertSame($this->methodInstanceMock, $this->info->getMethodInstance());
150  }
$code
Definition: info.phtml:12

◆ testGetMethodInstanceWithNoMethod()

testGetMethodInstanceWithNoMethod ( )

@expectedException \Magento\Framework\Exception\LocalizedException @expectedExceptionMessage The payment method you requested is not available.

Definition at line 130 of file InfoTest.php.

131  {
132  $this->info->setData('method', false);
133  $this->info->getMethodInstance();
134  }

◆ testGetMethodInstanceWithRealMethod()

testGetMethodInstanceWithRealMethod ( )

Definition at line 87 of file InfoTest.php.

88  {
89  $method = 'real_method';
90  $this->info->setData('method', $method);
91 
92  $this->methodInstanceMock->expects($this->once())
93  ->method('setInfoInstance')
94  ->with($this->info);
95 
96  $this->paymentHelperMock->expects($this->once())
97  ->method('getMethodInstance')
98  ->with($method)
99  ->willReturn($this->methodInstanceMock);
100 
101  $this->info->getMethodInstance();
102  }
$method
Definition: info.phtml:13

◆ testGetMethodInstanceWithUnrealMethod()

testGetMethodInstanceWithUnrealMethod ( )

Definition at line 104 of file InfoTest.php.

105  {
106  $method = 'unreal_method';
107  $this->info->setData('method', $method);
108 
109  $this->paymentHelperMock->expects($this->at(0))
110  ->method('getMethodInstance')
111  ->with($method)
112  ->willThrowException(new \UnexpectedValueException());
113 
114  $this->methodInstanceMock->expects($this->once())
115  ->method('setInfoInstance')
116  ->with($this->info);
117 
118  $this->paymentHelperMock->expects($this->at(1))
119  ->method('getMethodInstance')
120  ->with(Method\Substitution::CODE)
121  ->willReturn($this->methodInstanceMock);
122 
123  $this->info->getMethodInstance();
124  }
$method
Definition: info.phtml:13

◆ testHasAdditionalInformation()

testHasAdditionalInformation ( )

Definition at line 230 of file InfoTest.php.

231  {
232  $this->assertFalse($this->info->hasAdditionalInformation());
233 
234  $data = ['key1' => 'data1', 'key2' => 'data2'];
235  $this->info->setAdditionalInformation($data);
236  $this->assertFalse($this->info->hasAdditionalInformation('key3'));
237 
238  $this->assertTrue($this->info->hasAdditionalInformation('key2'));
239  $this->assertTrue($this->info->hasAdditionalInformation());
240  }

◆ testInitAdditionalInformationWithUnserialize()

testInitAdditionalInformationWithUnserialize ( )

Definition at line 242 of file InfoTest.php.

243  {
244  $data = ['key1' => 'data1', 'key2' => 'data2'];
245  $this->info->setData('additional_information', $data);
246 
247  $this->assertEquals($data, $this->info->getAdditionalInformation());
248  }

◆ testSetAdditionalInformationException()

testSetAdditionalInformationException ( )

@expectedException \Magento\Framework\Exception\LocalizedException

Definition at line 177 of file InfoTest.php.

178  {
179  $this->info->setAdditionalInformation('object', new \StdClass());
180  }

◆ testSetAdditionalInformationMultipleTypes()

testSetAdditionalInformationMultipleTypes (   $key,
  $value = null 
)

@dataProvider additionalInformationDataProvider

Parameters
mixed$key
mixed$value

Definition at line 187 of file InfoTest.php.

188  {
189  $this->info->setAdditionalInformation($key, $value);
190  $this->assertEquals($value ? [$key => $value] : $key, $this->info->getAdditionalInformation());
191  }
$value
Definition: gender.phtml:16

◆ testUnsAdditionalInformation()

testUnsAdditionalInformation ( )

Definition at line 214 of file InfoTest.php.

215  {
216  // set array to additional
217  $data = ['key1' => 'data1', 'key2' => 'data2'];
218  $this->info->setAdditionalInformation($data);
219 
220  // unset by key
221  $this->assertEquals(
222  ['key2' => 'data2'],
223  $this->info->unsAdditionalInformation('key1')->getAdditionalInformation()
224  );
225 
226  // unset all
227  $this->assertEmpty($this->info->unsAdditionalInformation()->getAdditionalInformation());
228  }

Field Documentation

◆ $contextMock

$contextMock
protected

Definition at line 21 of file InfoTest.php.

◆ $encryptorInterfaceMock

$encryptorInterfaceMock
protected

Definition at line 30 of file InfoTest.php.

◆ $info

$info
protected

Definition at line 15 of file InfoTest.php.

◆ $methodInstanceMock

$methodInstanceMock
protected

Definition at line 33 of file InfoTest.php.

◆ $objectManagerHelper

$objectManagerHelper
protected

Definition at line 18 of file InfoTest.php.

◆ $paymentHelperMock

$paymentHelperMock
protected

Definition at line 27 of file InfoTest.php.

◆ $registryMock

$registryMock
protected

Definition at line 24 of file InfoTest.php.


The documentation for this class was generated from the following file: