Skip to content

Commit bdc4f78

Browse files
author
Sergey Semenov
committed
Merge remote-tracking branch 'origin/MAGETWO-42285' into BUGS
2 parents f5e7b1f + c8bd7a9 commit bdc4f78

File tree

3 files changed

+64
-6
lines changed

3 files changed

+64
-6
lines changed

app/code/Magento/Customer/Model/AccountManagement.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,13 @@ public function createAccountWithPasswordHash(CustomerInterface $customer, $hash
513513
$customer->setStoreId($storeId);
514514
}
515515

516+
// Update 'created_in' value with actual store name
517+
if ($customer->getId() === null) {
518+
$storeName = $this->storeManager->getStore($customer->getStoreId())
519+
->getName();
520+
$customer->setCreatedIn($storeName);
521+
}
522+
516523
$customerAddresses = $customer->getAddresses() ?: [];
517524
$customer->setAddresses(null);
518525
try {

app/code/Magento/Customer/Test/Unit/Model/AccountManagementTest.php

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ public function testCreateAccountWithPasswordHashWithCustomerWithoutStoreId()
265265
->method('getDefaultStore')
266266
->willReturn($store);
267267
$customer = $this->getMockBuilder('Magento\Customer\Api\Data\CustomerInterface')->getMock();
268-
$customer->expects($this->once())
268+
$customer->expects($this->atLeastOnce())
269269
->method('getId')
270270
->willReturn($customerId);
271271
$customer->expects($this->once())
@@ -341,7 +341,7 @@ public function testCreateAccountWithPasswordHashWithLocalizedException()
341341
->method('getDefaultStore')
342342
->willReturn($store);
343343
$customer = $this->getMockBuilder('Magento\Customer\Api\Data\CustomerInterface')->getMock();
344-
$customer->expects($this->once())
344+
$customer->expects($this->atLeastOnce())
345345
->method('getId')
346346
->willReturn($customerId);
347347
$customer->expects($this->once())
@@ -478,6 +478,61 @@ public function testCreateAccountWithPasswordHashWithAddressException()
478478
$this->accountManagement->createAccountWithPasswordHash($customer, $hash);
479479
}
480480

481+
/**
482+
* @expectedException \Magento\Framework\Exception\LocalizedException
483+
*/
484+
public function testCreateAccountWithPasswordHashWithNewCustomerAndLocalizedException()
485+
{
486+
$storeId = 1;
487+
$storeName = 'store_name';
488+
$hash = '4nj54lkj5jfi03j49f8bgujfgsd';
489+
490+
$customerMock = $this->getMockBuilder('Magento\Customer\Api\Data\CustomerInterface')
491+
->getMockForAbstractClass();
492+
493+
$customerMock->expects($this->atLeastOnce())
494+
->method('getId')
495+
->willReturn(null);
496+
$customerMock->expects($this->atLeastOnce())
497+
->method('getStoreId')
498+
->willReturn($storeId);
499+
$customerMock->expects($this->once())
500+
->method('setCreatedIn')
501+
->with($storeName)
502+
->willReturnSelf();
503+
$customerMock->expects($this->once())
504+
->method('getAddresses')
505+
->willReturn([]);
506+
$customerMock->expects($this->once())
507+
->method('setAddresses')
508+
->with(null)
509+
->willReturnSelf();
510+
511+
$storeMock = $this->getMockBuilder('Magento\Store\Model\Store')
512+
->disableOriginalConstructor()
513+
->getMock();
514+
515+
$storeMock->expects($this->once())
516+
->method('getName')
517+
->willReturn($storeName);
518+
519+
$this->storeManager->expects($this->once())
520+
->method('getStore')
521+
->with($storeId)
522+
->willReturn($storeMock);
523+
524+
$exception = new \Magento\Framework\Exception\LocalizedException(
525+
new \Magento\Framework\Phrase('Exception message')
526+
);
527+
$this->customerRepository
528+
->expects($this->once())
529+
->method('save')
530+
->with($customerMock, $hash)
531+
->willThrowException($exception);
532+
533+
$this->accountManagement->createAccountWithPasswordHash($customerMock, $hash);
534+
}
535+
481536
/**
482537
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
483538
*/

dev/tests/integration/testsuite/Magento/Customer/Model/AccountManagementTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,6 @@ public function testCreateNonexistingCustomer()
587587
'email' => $email,
588588
'firstname' => $firstName,
589589
'lastname' => $lastName,
590-
'created_in' => 'Admin',
591590
'id' => null
592591
]
593592
);
@@ -603,7 +602,6 @@ public function testCreateNonexistingCustomer()
603602
$this->assertEquals($email, $customerAfter->getEmail());
604603
$this->assertEquals($firstName, $customerAfter->getFirstname());
605604
$this->assertEquals($lastName, $customerAfter->getLastname());
606-
$this->assertEquals('Admin', $customerAfter->getCreatedIn());
607605
$this->accountManagement->authenticate(
608606
$customerAfter->getEmail(),
609607
'aPassword'
@@ -807,15 +805,13 @@ public function testCreateNewCustomerFromClone()
807805
$customerEntity->setEmail($email)
808806
->setFirstname($firstName)
809807
->setLastname($lastname)
810-
->setCreatedIn('Admin')
811808
->setId(null);
812809

813810
$customer = $this->accountManagement->createAccount($customerEntity, 'aPassword');
814811
$this->assertNotEmpty($customer->getId());
815812
$this->assertEquals($email, $customer->getEmail());
816813
$this->assertEquals($firstName, $customer->getFirstname());
817814
$this->assertEquals($lastname, $customer->getLastname());
818-
$this->assertEquals('Admin', $customer->getCreatedIn());
819815
$this->accountManagement->authenticate(
820816
$customer->getEmail(),
821817
'aPassword',

0 commit comments

Comments
 (0)