Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
EncryptionUpdateTest.php
Go to the documentation of this file.
1 <?php
7 declare(strict_types=1);
8 
10 
13 
14 class EncryptionUpdateTest extends \PHPUnit\Framework\TestCase
15 {
16  const TEST_CC_NUMBER = '4111111111111111';
17 
23  public function testReEncryptCreditCardNumbers()
24  {
26 
28  $encyptor = $objectManager->get(\Magento\Framework\Encryption\EncryptorInterface::class);
29 
31  $resource = $objectManager->create(\Magento\Sales\Model\ResourceModel\Order\Payment\EncryptionUpdate::class);
32  $resource->reEncryptCreditCardNumbers();
33 
35  $collection = $objectManager->create(\Magento\Sales\Model\ResourceModel\Order\Payment\Collection::class);
36  $collection->addFieldToFilter('cc_number_enc', ['notnull' => true]);
37 
38  $this->assertGreaterThan(0, $collection->getTotalCount());
39 
41  foreach ($collection->getItems() as $payment) {
42  $this->assertEquals(
43  static::TEST_CC_NUMBER,
44  $encyptor->decrypt($payment->getCcNumberEnc())
45  );
46 
47  $this->assertStringStartsWith('0:' . Encryptor::CIPHER_LATEST . ':', $payment->getCcNumberEnc());
48  }
49  }
50 }
$objectManager
Definition: bootstrap.php:17
$resource
Definition: bulk.php:12
$payment
Definition: order.php:17