コード例 #1
0
 /**
  * @param array $attributeData
  * @param array $expected
  *
  * @dataProvider dataProviderEncryptionData
  * @return void
  */
 public function testHandle($attributeData, $expected)
 {
     $fieldName = 'value';
     list($key, $dbValue, $initVector, $encryptedValue, $cypher, $mode) = array_values($attributeData);
     list($decryptedValue, $newValue) = array_values($expected);
     /** @var \Migration\ResourceModel\Record|\PHPUnit_Framework_MockObject_MockObject $recordToHandle */
     $recordToHandle = $this->getMock('Migration\\ResourceModel\\Record', ['getValue', 'setValue', 'getFields'], [], '', false);
     $recordToHandle->expects($this->once())->method('getValue')->with($fieldName)->willReturn($dbValue);
     $recordToHandle->expects($this->once())->method('setValue')->with($fieldName, $newValue);
     $recordToHandle->expects($this->once())->method('getFields')->will($this->returnValue([$fieldName]));
     $oppositeRecord = $this->getMockBuilder('Migration\\ResourceModel\\Record')->disableOriginalConstructor()->getMock();
     $crypt = $this->getMock('\\Magento\\Framework\\Encryption\\Crypt', ['decrypt'], [$key, $cypher, $mode, $initVector], '', true);
     $crypt->expects($this->once())->method('decrypt')->with(base64_decode((string) $encryptedValue))->willReturn($decryptedValue);
     $this->configReader->expects($this->once())->method('getOption')->with(self::CRYPT_KEY)->will($this->returnValue($key));
     $this->cryptFactory->expects($this->once())->method('create')->with(['key' => $key, 'cipher' => $cypher, 'mode' => $mode, 'initVector' => $initVector])->will($this->returnValue($crypt));
     $this->encryptor->expects($this->once())->method('encrypt')->with($decryptedValue)->willReturn($newValue);
     $handler = new \Migration\Handler\Settings\Encrypt($this->encryptor, $this->cryptFactory, $this->configReader);
     $handler->setField($fieldName);
     $handler->handle($recordToHandle, $oppositeRecord);
 }
 public function testUpgradeCustomerPassword()
 {
     $customerId = '1';
     $password = '******';
     $passwordHash = 'hash:salt:999';
     $model = $this->getMockBuilder('Magento\\Customer\\Model\\Customer')->disableOriginalConstructor()->setMethods(['getId'])->getMock();
     $customer = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMockForAbstractClass();
     $customerSecure = $this->getMockBuilder('Magento\\Customer\\Model\\Data\\CustomerSecure')->disableOriginalConstructor()->setMethods(['getPasswordHash', 'setPasswordHash'])->getMock();
     $model->expects($this->exactly(2))->method('getId')->willReturn($customerId);
     $this->customerRepository->expects($this->once())->method('getById')->with($customerId)->willReturn($customer);
     $this->customerRegistry->expects($this->once())->method('retrieveSecureData')->with($customerId)->willReturn($customerSecure);
     $customerSecure->expects($this->once())->method('getPasswordHash')->willReturn($passwordHash);
     $this->encryptorMock->expects($this->once())->method('validateHashVersion')->with($passwordHash)->willReturn(false);
     $this->encryptorMock->expects($this->once())->method('getHash')->with($password, true)->willReturn($passwordHash);
     $customerSecure->expects($this->once())->method('setPasswordHash')->with($passwordHash);
     $this->customerRepository->expects($this->once())->method('save')->with($customer);
     $event = new \Magento\Framework\DataObject();
     $event->setData(['password' => 'password', 'model' => $model]);
     $observerMock = new \Magento\Framework\Event\Observer();
     $observerMock->setEvent($event);
     $this->model->execute($observerMock);
 }