|
59 | 59 | use Magento\Framework\Session\SessionManagerInterface; |
60 | 60 | use Magento\Framework\Stdlib\StringUtils; |
61 | 61 | use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; |
| 62 | +use Magento\Framework\Validator\Factory as ValidatorFactory; |
62 | 63 | use Magento\Store\Model\ScopeInterface; |
63 | 64 | use Magento\Store\Model\Store; |
64 | 65 | use Magento\Store\Model\StoreManagerInterface; |
@@ -248,6 +249,11 @@ class AccountManagementTest extends TestCase |
248 | 249 | */ |
249 | 250 | private $addressFactory; |
250 | 251 |
|
| 252 | + /** |
| 253 | + * @var MockObject|ValidatorFactory |
| 254 | + */ |
| 255 | + private $validatorFactory; |
| 256 | + |
251 | 257 | /** |
252 | 258 | * @var MockObject|AddressRegistry |
253 | 259 | */ |
@@ -336,6 +342,7 @@ protected function setUp(): void |
336 | 342 | $this->sessionManager = $this->createMock(SessionManagerInterface::class); |
337 | 343 | $this->saveHandler = $this->createMock(SaveHandlerInterface::class); |
338 | 344 | $this->addressFactory = $this->createMock(AddressFactory::class); |
| 345 | + $this->validatorFactory = $this->createMock(ValidatorFactory::class); |
339 | 346 |
|
340 | 347 | $this->objectManagerHelper = new ObjectManagerHelper($this); |
341 | 348 | $objects = [ |
@@ -420,6 +427,7 @@ protected function setUp(): void |
420 | 427 | 'addressRegistry' => $this->addressRegistryMock, |
421 | 428 | 'allowedCountriesReader' => $this->allowedCountriesReader, |
422 | 429 | 'addressFactory' => $this->addressFactory, |
| 430 | + 'validatorFactory' => $this->validatorFactory, |
423 | 431 | ] |
424 | 432 | ); |
425 | 433 | $this->objectManagerHelper->setBackwardCompatibleProperty( |
@@ -547,7 +555,12 @@ public function testCreateAccountWithPasswordHashWithCustomerWithoutStoreId(): v |
547 | 555 | $addressModel = $this->createMock(Address::class); |
548 | 556 | $this->addressFactory->expects($this->once())->method('create')->willReturn($addressModel); |
549 | 557 | $addressModel->expects($this->once())->method('updateData')->with($address)->willReturnSelf(); |
550 | | - $addressModel->expects($this->once())->method('validate')->willReturn(true); |
| 558 | + $validator = $this->createMock(\Magento\Framework\Validator::class); |
| 559 | + $this->validatorFactory->expects($this->once()) |
| 560 | + ->method('createValidator') |
| 561 | + ->with('customer_address', 'save') |
| 562 | + ->willReturn($validator); |
| 563 | + $validator->expects($this->once())->method('isValid')->with($addressModel)->willReturn(true); |
551 | 564 |
|
552 | 565 | $this->customerRepository |
553 | 566 | ->expects($this->once()) |
@@ -629,7 +642,12 @@ public function testCreateAccountWithPasswordHashWithLocalizedException(): void |
629 | 642 | $addressModel = $this->createMock(Address::class); |
630 | 643 | $this->addressFactory->expects($this->once())->method('create')->willReturn($addressModel); |
631 | 644 | $addressModel->expects($this->once())->method('updateData')->with($address)->willReturnSelf(); |
632 | | - $addressModel->expects($this->once())->method('validate')->willReturn(true); |
| 645 | + $validator = $this->createMock(\Magento\Framework\Validator::class); |
| 646 | + $this->validatorFactory->expects($this->once()) |
| 647 | + ->method('createValidator') |
| 648 | + ->with('customer_address', 'save') |
| 649 | + ->willReturn($validator); |
| 650 | + $validator->expects($this->once())->method('isValid')->with($addressModel)->willReturn(true); |
633 | 651 |
|
634 | 652 | $this->customerRepository |
635 | 653 | ->expects($this->once()) |
@@ -711,7 +729,15 @@ public function testCreateAccountWithPasswordHashWithAddressException(): void |
711 | 729 | $addressModel = $this->createMock(Address::class); |
712 | 730 | $this->addressFactory->expects($this->once())->method('create')->willReturn($addressModel); |
713 | 731 | $addressModel->expects($this->once())->method('updateData')->with($address)->willReturnSelf(); |
714 | | - $addressModel->expects($this->once())->method('validate')->willReturn([new Phrase('Exception message')]); |
| 732 | + $validator = $this->createMock(\Magento\Framework\Validator::class); |
| 733 | + $this->validatorFactory->expects($this->once()) |
| 734 | + ->method('createValidator') |
| 735 | + ->with('customer_address', 'save') |
| 736 | + ->willReturn($validator); |
| 737 | + $validator->expects($this->once())->method('isValid')->willReturn(false); |
| 738 | + $validator->expects($this->atLeastOnce()) |
| 739 | + ->method('getMessages') |
| 740 | + ->willReturn([[new Phrase('Exception message')]]); |
715 | 741 |
|
716 | 742 | $this->customerRepository |
717 | 743 | ->expects($this->once()) |
@@ -885,7 +911,12 @@ public function testCreateAccountWithoutPassword(): void |
885 | 911 | $addressModel = $this->createMock(Address::class); |
886 | 912 | $this->addressFactory->expects($this->once())->method('create')->willReturn($addressModel); |
887 | 913 | $addressModel->expects($this->once())->method('updateData')->with($address)->willReturnSelf(); |
888 | | - $addressModel->expects($this->once())->method('validate')->willReturn(true); |
| 914 | + $validator = $this->createMock(\Magento\Framework\Validator::class); |
| 915 | + $this->validatorFactory->expects($this->once()) |
| 916 | + ->method('createValidator') |
| 917 | + ->with('customer_address', 'save') |
| 918 | + ->willReturn($validator); |
| 919 | + $validator->expects($this->once())->method('isValid')->with($addressModel)->willReturn(true); |
889 | 920 |
|
890 | 921 | $this->share->method('isWebsiteScope') |
891 | 922 | ->willReturn(true); |
@@ -1171,7 +1202,12 @@ public function testCreateAccountWithPassword(): void |
1171 | 1202 | $addressModel = $this->createMock(Address::class); |
1172 | 1203 | $this->addressFactory->expects($this->once())->method('create')->willReturn($addressModel); |
1173 | 1204 | $addressModel->expects($this->once())->method('updateData')->with($address)->willReturnSelf(); |
1174 | | - $addressModel->expects($this->once())->method('validate')->willReturn(true); |
| 1205 | + $validator = $this->createMock(\Magento\Framework\Validator::class); |
| 1206 | + $this->validatorFactory->expects($this->once()) |
| 1207 | + ->method('createValidator') |
| 1208 | + ->with('customer_address', 'save') |
| 1209 | + ->willReturn($validator); |
| 1210 | + $validator->expects($this->once())->method('isValid')->with($addressModel)->willReturn(true); |
1175 | 1211 |
|
1176 | 1212 | $this->share->method('isWebsiteScope') |
1177 | 1213 | ->willReturn(true); |
@@ -1345,7 +1381,12 @@ public function testCreateAccountWithGroupId(): void |
1345 | 1381 | $addressModel = $this->createMock(Address::class); |
1346 | 1382 | $this->addressFactory->expects($this->once())->method('create')->willReturn($addressModel); |
1347 | 1383 | $addressModel->expects($this->once())->method('updateData')->with($address)->willReturnSelf(); |
1348 | | - $addressModel->expects($this->once())->method('validate')->willReturn(true); |
| 1384 | + $validator = $this->createMock(\Magento\Framework\Validator::class); |
| 1385 | + $this->validatorFactory->expects($this->once()) |
| 1386 | + ->method('createValidator') |
| 1387 | + ->with('customer_address', 'save') |
| 1388 | + ->willReturn($validator); |
| 1389 | + $validator->expects($this->once())->method('isValid')->with($addressModel)->willReturn(true); |
1349 | 1390 |
|
1350 | 1391 | $this->share->method('isWebsiteScope') |
1351 | 1392 | ->willReturn(true); |
@@ -2294,13 +2335,20 @@ public function testCreateAccountWithPasswordHashWithCustomerAddresses(): void |
2294 | 2335 | $this->addressFactory->expects($this->exactly(2)) |
2295 | 2336 | ->method('create') |
2296 | 2337 | ->willReturnOnConsecutiveCalls($existingAddressModel, $nonExistingAddressModel); |
2297 | | - $existingAddressModel->expects($this->once())->method('updateData')->with($existingAddress)->willReturnSelf(); |
2298 | | - $existingAddressModel->expects($this->once())->method('validate')->willReturn(true); |
| 2338 | + $existingAddressModel->expects($this->once()) |
| 2339 | + ->method('updateData') |
| 2340 | + ->with($existingAddress) |
| 2341 | + ->willReturnSelf(); |
2299 | 2342 | $nonExistingAddressModel->expects($this->once()) |
2300 | 2343 | ->method('updateData') |
2301 | 2344 | ->with($nonExistingAddress) |
2302 | 2345 | ->willReturnSelf(); |
2303 | | - $nonExistingAddressModel->expects($this->once())->method('validate')->willReturn(true); |
| 2346 | + $validator = $this->createMock(\Magento\Framework\Validator::class); |
| 2347 | + $this->validatorFactory->expects($this->once()) |
| 2348 | + ->method('createValidator') |
| 2349 | + ->with('customer_address', 'save') |
| 2350 | + ->willReturn($validator); |
| 2351 | + $validator->expects($this->exactly(2))->method('isValid')->willReturn(true); |
2304 | 2352 |
|
2305 | 2353 | $this->storeManager |
2306 | 2354 | ->expects($this->atLeastOnce()) |
@@ -2422,7 +2470,12 @@ public function testCreateAccountUnexpectedValueException(): void |
2422 | 2470 | $addressModel = $this->createMock(Address::class); |
2423 | 2471 | $this->addressFactory->expects($this->once())->method('create')->willReturn($addressModel); |
2424 | 2472 | $addressModel->expects($this->once())->method('updateData')->with($address)->willReturnSelf(); |
2425 | | - $addressModel->expects($this->once())->method('validate')->willReturn(true); |
| 2473 | + $validator = $this->createMock(\Magento\Framework\Validator::class); |
| 2474 | + $this->validatorFactory->expects($this->once()) |
| 2475 | + ->method('createValidator') |
| 2476 | + ->with('customer_address', 'save') |
| 2477 | + ->willReturn($validator); |
| 2478 | + $validator->expects($this->once())->method('isValid')->with($addressModel)->willReturn(true); |
2426 | 2479 |
|
2427 | 2480 | $this->share->method('isWebsiteScope') |
2428 | 2481 | ->willReturn(true); |
|
0 commit comments