12 class InfoTest extends \PHPUnit\Framework\TestCase
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();
44 $this->objectManagerHelper =
new ObjectManagerHelper($this);
45 $this->info = $this->objectManagerHelper->getObject(
48 'context' => $this->contextMock,
49 'registry' => $this->registryMock,
50 'paymentData' => $this->paymentHelperMock,
51 'encryptor' => $this->encryptorInterfaceMock
64 $this->assertNull($this->info->getData($keyCc));
67 $this->info->setData($keyCcEnc, $keyCcEnc);
68 $this->encryptorInterfaceMock->expects($this->once())->method(
'decrypt')->with($keyCcEnc)->will(
69 $this->returnValue($keyCc)
71 $this->assertEquals($keyCc, $this->info->getData($keyCc));
82 [
'cc_number',
'cc_number_enc'],
83 [
'cc_cid',
'cc_cid_enc']
90 $this->info->setData(
'method',
$method);
92 $this->methodInstanceMock->expects($this->once())
93 ->method(
'setInfoInstance')
96 $this->paymentHelperMock->expects($this->once())
97 ->method(
'getMethodInstance')
99 ->willReturn($this->methodInstanceMock);
101 $this->info->getMethodInstance();
107 $this->info->setData(
'method',
$method);
109 $this->paymentHelperMock->expects($this->at(0))
110 ->method(
'getMethodInstance')
112 ->willThrowException(
new \UnexpectedValueException());
114 $this->methodInstanceMock->expects($this->once())
115 ->method(
'setInfoInstance')
118 $this->paymentHelperMock->expects($this->at(1))
119 ->method(
'getMethodInstance')
121 ->willReturn($this->methodInstanceMock);
123 $this->info->getMethodInstance();
132 $this->info->setData(
'method',
false);
133 $this->info->getMethodInstance();
138 $code =
'real_method';
139 $this->info->setData(
'method',
$code);
141 $this->paymentHelperMock->expects($this->once())->method(
'getMethodInstance')->with(
$code)->will(
142 $this->returnValue($this->methodInstanceMock)
145 $this->methodInstanceMock->expects($this->once())->method(
'setInfoInstance')->with($this->info);
146 $this->assertSame($this->methodInstanceMock, $this->info->getMethodInstance());
149 $this->assertSame($this->methodInstanceMock, $this->info->getMethodInstance());
155 $encryptedData =
'd1a2t3a4';
157 $this->encryptorInterfaceMock->expects($this->once())->method(
'encrypt')->with(
$data)->will(
158 $this->returnValue($encryptedData)
160 $this->assertEquals($encryptedData, $this->info->encrypt(
$data));
166 $encryptedData =
'd1a2t3a4';
168 $this->encryptorInterfaceMock->expects($this->once())->method(
'decrypt')->with($encryptedData)->will(
169 $this->returnValue(
$data)
171 $this->assertEquals(
$data, $this->info->decrypt($encryptedData));
179 $this->info->setAdditionalInformation(
'object',
new \StdClass());
189 $this->info->setAdditionalInformation($key,
$value);
190 $this->assertEquals(
$value ? [$key =>
$value] : $key, $this->info->getAdditionalInformation());
201 [[
'key1' =>
'data1',
'key2' =>
'data2'],
null],
210 $this->info->setAdditionalInformation($key,
$value);
211 $this->assertEquals(
$value, $this->info->getAdditionalInformation($key));
217 $data = [
'key1' =>
'data1',
'key2' =>
'data2'];
218 $this->info->setAdditionalInformation(
$data);
223 $this->info->unsAdditionalInformation(
'key1')->getAdditionalInformation()
227 $this->assertEmpty($this->info->unsAdditionalInformation()->getAdditionalInformation());
232 $this->assertFalse($this->info->hasAdditionalInformation());
234 $data = [
'key1' =>
'data1',
'key2' =>
'data2'];
235 $this->info->setAdditionalInformation(
$data);
236 $this->assertFalse($this->info->hasAdditionalInformation(
'key3'));
238 $this->assertTrue($this->info->hasAdditionalInformation(
'key2'));
239 $this->assertTrue($this->info->hasAdditionalInformation());
244 $data = [
'key1' =>
'data1',
'key2' =>
'data2'];
245 $this->info->setData(
'additional_information',
$data);
247 $this->assertEquals(
$data, $this->info->getAdditionalInformation());
testGetAdditionalInformationByKey()
additionalInformationDataProvider()
testGetMethodInstanceWithNoMethod()
testHasAdditionalInformation()
testUnsAdditionalInformation()
testSetAdditionalInformationException()
testGetMethodInstanceWithUnrealMethod()
testGetMethodInstanceWithRealMethod()
testInitAdditionalInformationWithUnserialize()
testSetAdditionalInformationMultipleTypes($key, $value=null)
testGetMethodInstanceRequestedMethod()
testGetDataCcNumber($keyCc, $keyCcEnc)