diff --git a/app/code/Magento/Customer/Model/AccountManagement.php b/app/code/Magento/Customer/Model/AccountManagement.php index 500a104861d3bd1f8e74d1454c24dddf30adeab8..06be21a82e3c108edd8838b8834c7b1ac1676051 100644 --- a/app/code/Magento/Customer/Model/AccountManagement.php +++ b/app/code/Magento/Customer/Model/AccountManagement.php @@ -513,6 +513,13 @@ class AccountManagement implements AccountManagementInterface $customer->setStoreId($storeId); } + // Update 'created_in' value with actual store name + if ($customer->getId() === null) { + $storeName = $this->storeManager->getStore($customer->getStoreId()) + ->getName(); + $customer->setCreatedIn($storeName); + } + $customerAddresses = $customer->getAddresses() ?: []; $customer->setAddresses(null); try { diff --git a/app/code/Magento/Customer/Test/Unit/Model/AccountManagementTest.php b/app/code/Magento/Customer/Test/Unit/Model/AccountManagementTest.php index d5fc01b379051a1a0f0fe415e6d88c7a4528627f..62d7232bda0f2145e84cb56a94970882295f366a 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/AccountManagementTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/AccountManagementTest.php @@ -265,7 +265,7 @@ class AccountManagementTest extends \PHPUnit_Framework_TestCase ->method('getDefaultStore') ->willReturn($store); $customer = $this->getMockBuilder('Magento\Customer\Api\Data\CustomerInterface')->getMock(); - $customer->expects($this->once()) + $customer->expects($this->atLeastOnce()) ->method('getId') ->willReturn($customerId); $customer->expects($this->once()) @@ -341,7 +341,7 @@ class AccountManagementTest extends \PHPUnit_Framework_TestCase ->method('getDefaultStore') ->willReturn($store); $customer = $this->getMockBuilder('Magento\Customer\Api\Data\CustomerInterface')->getMock(); - $customer->expects($this->once()) + $customer->expects($this->atLeastOnce()) ->method('getId') ->willReturn($customerId); $customer->expects($this->once()) @@ -478,6 +478,61 @@ class AccountManagementTest extends \PHPUnit_Framework_TestCase $this->accountManagement->createAccountWithPasswordHash($customer, $hash); } + /** + * @expectedException \Magento\Framework\Exception\LocalizedException + */ + public function testCreateAccountWithPasswordHashWithNewCustomerAndLocalizedException() + { + $storeId = 1; + $storeName = 'store_name'; + $hash = '4nj54lkj5jfi03j49f8bgujfgsd'; + + $customerMock = $this->getMockBuilder('Magento\Customer\Api\Data\CustomerInterface') + ->getMockForAbstractClass(); + + $customerMock->expects($this->atLeastOnce()) + ->method('getId') + ->willReturn(null); + $customerMock->expects($this->atLeastOnce()) + ->method('getStoreId') + ->willReturn($storeId); + $customerMock->expects($this->once()) + ->method('setCreatedIn') + ->with($storeName) + ->willReturnSelf(); + $customerMock->expects($this->once()) + ->method('getAddresses') + ->willReturn([]); + $customerMock->expects($this->once()) + ->method('setAddresses') + ->with(null) + ->willReturnSelf(); + + $storeMock = $this->getMockBuilder('Magento\Store\Model\Store') + ->disableOriginalConstructor() + ->getMock(); + + $storeMock->expects($this->once()) + ->method('getName') + ->willReturn($storeName); + + $this->storeManager->expects($this->once()) + ->method('getStore') + ->with($storeId) + ->willReturn($storeMock); + + $exception = new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase('Exception message') + ); + $this->customerRepository + ->expects($this->once()) + ->method('save') + ->with($customerMock, $hash) + ->willThrowException($exception); + + $this->accountManagement->createAccountWithPasswordHash($customerMock, $hash); + } + /** * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ diff --git a/dev/tests/integration/testsuite/Magento/Customer/Model/AccountManagementTest.php b/dev/tests/integration/testsuite/Magento/Customer/Model/AccountManagementTest.php index 65c3aae162bf6ebbf6a8e1a66613c99bb5f8cfac..077f18fbe2cf355d3e95bf698df3e7234d101647 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Model/AccountManagementTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Model/AccountManagementTest.php @@ -587,7 +587,6 @@ class AccountManagementTest extends \PHPUnit_Framework_TestCase 'email' => $email, 'firstname' => $firstName, 'lastname' => $lastName, - 'created_in' => 'Admin', 'id' => null ] ); @@ -603,7 +602,6 @@ class AccountManagementTest extends \PHPUnit_Framework_TestCase $this->assertEquals($email, $customerAfter->getEmail()); $this->assertEquals($firstName, $customerAfter->getFirstname()); $this->assertEquals($lastName, $customerAfter->getLastname()); - $this->assertEquals('Admin', $customerAfter->getCreatedIn()); $this->accountManagement->authenticate( $customerAfter->getEmail(), 'aPassword' @@ -807,7 +805,6 @@ class AccountManagementTest extends \PHPUnit_Framework_TestCase $customerEntity->setEmail($email) ->setFirstname($firstName) ->setLastname($lastname) - ->setCreatedIn('Admin') ->setId(null); $customer = $this->accountManagement->createAccount($customerEntity, 'aPassword'); @@ -815,7 +812,6 @@ class AccountManagementTest extends \PHPUnit_Framework_TestCase $this->assertEquals($email, $customer->getEmail()); $this->assertEquals($firstName, $customer->getFirstname()); $this->assertEquals($lastname, $customer->getLastname()); - $this->assertEquals('Admin', $customer->getCreatedIn()); $this->accountManagement->authenticate( $customer->getEmail(), 'aPassword',