|
1 | 1 | <?php |
2 | 2 | /** |
3 | | - * Copyright © Magento, Inc. All rights reserved. |
4 | | - * See COPYING.txt for license details. |
| 3 | + * Copyright 2014 Adobe |
| 4 | + * All Rights Reserved. |
5 | 5 | */ |
6 | 6 |
|
7 | 7 | namespace Magento\Customer\Model\ResourceModel\Grid; |
8 | 8 |
|
9 | 9 | use Magento\Customer\Api\CustomerRepositoryInterface; |
10 | | -use Magento\Customer\Api\Data\CustomerInterface; |
11 | 10 | use Magento\Customer\Model\Customer; |
12 | 11 | use Magento\Framework\Indexer\IndexerRegistry; |
13 | 12 | use Magento\Framework\Stdlib\DateTime\TimezoneInterface; |
|
19 | 18 | */ |
20 | 19 | class CollectionTest extends TestCase |
21 | 20 | { |
| 21 | + /** @var CustomerRepositoryInterface */ |
| 22 | + private $customerRepository; |
22 | 23 |
|
23 | | - public static function setUpBeforeClass(): void |
24 | | - { |
25 | | - $db = Bootstrap::getInstance() |
26 | | - ->getBootstrap() |
27 | | - ->getApplication() |
28 | | - ->getDbInstance(); |
29 | | - if (!$db->isDbDumpExists()) { |
30 | | - throw new \LogicException('DB dump does not exist.'); |
31 | | - } |
32 | | - $db->restoreFromDbDump(); |
| 24 | + /** @var \Magento\Framework\ObjectManagerInterface */ |
| 25 | + private $objectManager; |
33 | 26 |
|
34 | | - $indexerRegistry = Bootstrap::getObjectManager()->create(IndexerRegistry::class); |
35 | | - $indexer = $indexerRegistry->get(Customer::CUSTOMER_GRID_INDEXER_ID); |
36 | | - $indexer->reindexAll(); |
37 | | - parent::setUpBeforeClass(); |
| 27 | + /** @var IndexerRegistry */ |
| 28 | + private $indexerRegistry; |
| 29 | + |
| 30 | + /** @var \Magento\Customer\Model\ResourceModel\Grid\Collection */ |
| 31 | + private $targetObject; |
| 32 | + |
| 33 | + protected function setUp(): void |
| 34 | + { |
| 35 | + $this->objectManager = Bootstrap::getObjectManager(); |
| 36 | + $this->indexerRegistry = $this->objectManager->create(IndexerRegistry::class); |
| 37 | + $this->targetObject = $this->objectManager |
| 38 | + ->create(\Magento\Customer\Model\ResourceModel\Grid\Collection::class); |
| 39 | + $this->customerRepository = $this->objectManager->create(CustomerRepositoryInterface::class); |
38 | 40 | } |
39 | 41 |
|
40 | 42 | /** |
41 | | - * Test updated data for customer grid indexer during save/update customer data(including address data) |
| 43 | + * Test updated data for customer grid indexer |
42 | 44 | * in 'Update on Schedule' mode. |
43 | | - * |
44 | | - * Customer Grid Indexer can't work in 'Update on Schedule' mode. All data for indexer must be updated in realtime |
45 | | - * during save/update customer data(including address data). |
46 | | - * |
47 | | - * @magentoDataFixture Magento/Customer/_files/customer_grid_indexer_enabled_update_on_schedule.php |
48 | 45 | * @magentoDataFixture Magento/Customer/_files/customer_sample.php |
49 | 46 | * @magentoAppIsolation enabled |
50 | 47 | * @magentoDbIsolation disabled |
51 | 48 | */ |
52 | 49 | public function testGetItemByIdForUpdateOnSchedule() |
53 | 50 | { |
54 | | - $targetObject = Bootstrap::getObjectManager() |
55 | | - ->create(Collection::class); |
56 | | - $customerRepository = Bootstrap::getObjectManager() |
57 | | - ->create(CustomerRepositoryInterface::class); |
58 | | - /** Verify after first save */ |
59 | | - |
60 | | - /** @var CustomerInterface $newCustomer */ |
61 | | - $newCustomer = $customerRepository->get('customer@example.com'); |
62 | | - /** @var CustomerInterface $item */ |
63 | | - $item = $targetObject->getItemById($newCustomer->getId()); |
| 51 | + $indexer = $this->indexerRegistry->get(Customer::CUSTOMER_GRID_INDEXER_ID); |
| 52 | + $indexer->reindexAll(); |
| 53 | + $newCustomer = $this->customerRepository->get('customer@example.com'); |
| 54 | + $item = $this->targetObject->getItemById($newCustomer->getId()); |
64 | 55 | $this->assertNotEmpty($item); |
65 | 56 | $this->assertSame($newCustomer->getEmail(), $item->getEmail()); |
66 | 57 | $this->assertSame('test street test city Armed Forces Middle East 01001', $item->getBillingFull()); |
67 | 58 |
|
68 | | - /** Verify after update */ |
| 59 | + /** set customer grid indexer on schedule' mode */ |
| 60 | + $indexer->setScheduled(true); |
69 | 61 |
|
| 62 | + /** Verify after update */ |
70 | 63 | $newCustomer->setEmail('customer_updated@example.com'); |
71 | | - $customerRepository->save($newCustomer); |
72 | | - $targetObject->clear(); |
73 | | - $item = $targetObject->getItemById($newCustomer->getId()); |
74 | | - $this->assertSame($newCustomer->getEmail(), $item->getEmail()); |
| 64 | + $this->customerRepository->save($newCustomer); |
| 65 | + $this->targetObject->clear(); |
| 66 | + $item = $this->targetObject->getItemById($newCustomer->getId()); |
| 67 | + $this->assertNotEquals('customer_updated@example.com', $item->getEmail()); |
75 | 68 | } |
76 | 69 |
|
77 | 70 | /** |
|
0 commit comments