Skip to content

Commit 1ef9ca2

Browse files
[Magento Community Engineering] Community Contributions - 2.4-develop-expedited-prs
- merged with '2.4-develop-fast-lane-prs' branch
2 parents 4602b16 + f41e489 commit 1ef9ca2

File tree

4 files changed

+79
-14
lines changed

4 files changed

+79
-14
lines changed

app/code/Magento/Customer/Model/ResourceModel/CustomerRepository.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Magento\Customer\Model\Data\CustomerSecureFactory;
1818
use Magento\Customer\Model\Delegation\Data\NewOperation;
1919
use Magento\Customer\Model\Delegation\Storage as DelegatedStorage;
20+
use Magento\Customer\Model\ResourceModel\Customer\Collection;
2021
use Magento\Framework\Api\DataObjectHelper;
2122
use Magento\Framework\Api\ExtensibleDataObjectConverter;
2223
use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface;
@@ -31,6 +32,8 @@
3132
/**
3233
* Customer repository.
3334
*
35+
* CRUD operations for customer entity
36+
*
3437
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3538
* @SuppressWarnings(PHPMD.TooManyFields)
3639
*/
@@ -187,8 +190,7 @@ public function save(CustomerInterface $customer, $passwordHash = null)
187190
{
188191
/** @var NewOperation|null $delegatedNewOperation */
189192
$delegatedNewOperation = !$customer->getId() ? $this->delegatedStorage->consumeNewOperation() : null;
190-
$prevCustomerData = null;
191-
$prevCustomerDataArr = null;
193+
$prevCustomerData = $prevCustomerDataArr = null;
192194
if ($customer->getId()) {
193195
$prevCustomerData = $this->getById($customer->getId());
194196
$prevCustomerDataArr = $prevCustomerData->__toArray();
@@ -214,6 +216,7 @@ public function save(CustomerInterface $customer, $passwordHash = null)
214216
$prevCustomerData ? $prevCustomerData->getStoreId() : $this->storeManager->getStore()->getId()
215217
);
216218
}
219+
$this->setCustomerGroupId($customerModel, $customerArr, $prevCustomerDataArr);
217220
// Need to use attribute set or future updates can cause data loss
218221
if (!$customerModel->getAttributeSetId()) {
219222
$customerModel->setAttributeSetId(CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER);
@@ -452,4 +455,18 @@ private function setValidationFlag($customerArray, $customerModel)
452455
$customerModel->setData('ignore_validation_flag', true);
453456
}
454457
}
458+
459+
/**
460+
* Set customer group id
461+
*
462+
* @param Customer $customerModel
463+
* @param array $customerArr
464+
* @param array $prevCustomerDataArr
465+
*/
466+
private function setCustomerGroupId($customerModel, $customerArr, $prevCustomerDataArr)
467+
{
468+
if (!isset($customerArr['group_id']) && $prevCustomerDataArr && isset($prevCustomerDataArr['group_id'])) {
469+
$customerModel->setGroupId($prevCustomerDataArr['group_id']);
470+
}
471+
}
455472
}

app/code/Magento/Customer/Test/Unit/Model/ResourceModel/CustomerRepositoryTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ public function testSave()
211211
'setFirstFailure',
212212
'setLockExpires',
213213
'save',
214+
'setGroupId'
214215
]
215216
);
216217

@@ -245,9 +246,15 @@ public function testSave()
245246
$this->customer->expects($this->atLeastOnce())
246247
->method('getId')
247248
->willReturn($customerId);
248-
$this->customer->expects($this->atLeastOnce())
249+
$this->customer->expects($this->at(4))
249250
->method('__toArray')
250251
->willReturn([]);
252+
$this->customer->expects($this->at(3))
253+
->method('__toArray')
254+
->willReturn(['group_id' => 1]);
255+
$customerModel->expects($this->once())
256+
->method('setGroupId')
257+
->with(1);
251258
$this->customerRegistry->expects($this->atLeastOnce())
252259
->method('retrieve')
253260
->with($customerId)

app/code/Magento/Wishlist/Controller/Index/Send.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@
2525
use Magento\Customer\Model\Customer;
2626

2727
/**
28-
* Class Send
28+
* Class Send Email Wishlist Controller
2929
*
30-
* @package Magento\Wishlist\Controller\Index
3130
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3231
*/
3332
class Send extends \Magento\Wishlist\Controller\AbstractIndex implements Action\HttpPostActionInterface
@@ -204,7 +203,7 @@ public function execute()
204203
$error = __('Please enter an email address.');
205204
} else {
206205
if (count($emails) > $emailsLeft) {
207-
$error = __('This wish list can be shared %1 more times.', $emailsLeft);
206+
$error = __('Maximum of %1 emails can be sent.', $emailsLeft);
208207
} else {
209208
foreach ($emails as $index => $email) {
210209
$email = trim($email);
@@ -319,7 +318,6 @@ protected function addLayoutHandles(ResultLayout $resultLayout)
319318
*
320319
* @param int $wishlistId
321320
* @param \Magento\Framework\View\Result\Layout $resultLayout
322-
* @return mixed
323321
*/
324322
protected function getRssLink($wishlistId, ResultLayout $resultLayout)
325323
{

app/code/Magento/Wishlist/Test/Unit/Controller/Index/SendTest.php

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
*/
66
namespace Magento\Wishlist\Test\Unit\Controller\Index;
77

8+
use Magento\Captcha\Helper\Data as CaptchaHelper;
9+
use Magento\Captcha\Model\DefaultModel as CaptchaModel;
810
use Magento\Customer\Model\Data\Customer as CustomerData;
11+
use Magento\Customer\Model\Session;
912
use Magento\Framework\App\Action\Context as ActionContext;
1013
use Magento\Framework\App\RequestInterface;
1114
use Magento\Framework\Controller\Result\Redirect as ResultRedirect;
@@ -14,15 +17,13 @@
1417
use Magento\Framework\Event\ManagerInterface as EventManagerInterface;
1518
use Magento\Framework\Mail\TransportInterface;
1619
use Magento\Framework\Message\ManagerInterface;
20+
use Magento\Framework\Phrase;
21+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1722
use Magento\Framework\UrlInterface;
1823
use Magento\Framework\View\Result\Layout as ResultLayout;
1924
use Magento\Store\Model\Store;
2025
use Magento\Wishlist\Controller\Index\Send;
2126
use Magento\Wishlist\Controller\WishlistProviderInterface;
22-
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
23-
use Magento\Captcha\Helper\Data as CaptchaHelper;
24-
use Magento\Captcha\Model\DefaultModel as CaptchaModel;
25-
use Magento\Customer\Model\Session;
2627

2728
/**
2829
* @SuppressWarnings(PHPMD.TooManyFields)
@@ -212,7 +213,12 @@ protected function setUp()
212213
);
213214
}
214215

215-
public function testExecuteNoFormKeyValidated()
216+
/**
217+
* Verify execute method without Form Key validated
218+
*
219+
* @return void
220+
*/
221+
public function testExecuteNoFormKeyValidated(): void
216222
{
217223
$this->formKeyValidator->expects($this->once())
218224
->method('validate')
@@ -228,8 +234,43 @@ public function testExecuteNoFormKeyValidated()
228234
}
229235

230236
/**
231-
* @expectedException \Magento\Framework\Exception\NotFoundException
232-
* @expectedExceptionMessage Page not found.
237+
* Verify execute with no emails left
238+
*
239+
* @return void
240+
*/
241+
public function testExecuteWithNoEmailLeft(): void
242+
{
243+
$expectedMessage = new Phrase('Maximum of %1 emails can be sent.', [0]);
244+
245+
$this->formKeyValidator->expects($this->once())
246+
->method('validate')
247+
->with($this->request)
248+
->willReturn(true);
249+
250+
$this->request->expects($this->at(0))
251+
->method('getPost')
252+
->with('emails')
253+
->willReturn('some.Email@gmail.com', 'some.email2@gmail.com');
254+
$this->request->expects($this->at(1))
255+
->method('getPost')
256+
->with('message');
257+
$wishlist = $this->createMock(\Magento\Wishlist\Model\Wishlist::class);
258+
$this->wishlistProvider->expects($this->once())
259+
->method('getWishlist')
260+
->willReturn($wishlist);
261+
$this->resultRedirect->expects($this->once())
262+
->method('setPath')
263+
->with('*/*/share')
264+
->willReturnSelf();
265+
$this->messageManager->expects($this->once())
266+
->method('addErrorMessage')
267+
->with($expectedMessage);
268+
269+
$this->assertEquals($this->resultRedirect, $this->model->execute());
270+
}
271+
272+
/**
273+
* Execute method with no wishlist available
233274
*/
234275
public function testExecuteNoWishlistAvailable()
235276
{
@@ -241,6 +282,8 @@ public function testExecuteNoWishlistAvailable()
241282
$this->wishlistProvider->expects($this->once())
242283
->method('getWishlist')
243284
->willReturn(null);
285+
$this->expectException(\Magento\Framework\Exception\NotFoundException::class);
286+
$this->expectExceptionMessage('Page not found');
244287

245288
$this->model->execute();
246289
}

0 commit comments

Comments
 (0)