|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +namespace Magento\Customer\Model\ResourceModel\Grid; |
| 8 | + |
| 9 | +use Magento\Customer\Api\CustomerRepositoryInterface; |
| 10 | +use Magento\Customer\Api\Data\CustomerInterface; |
| 11 | +use Magento\Framework\Indexer\IndexerRegistry; |
| 12 | +use Magento\TestFramework\Helper\Bootstrap; |
| 13 | + |
| 14 | +/** |
| 15 | + * Customer grid collection tests. |
| 16 | + */ |
| 17 | +class CollectionTest extends \Magento\TestFramework\Indexer\TestCase |
| 18 | +{ |
| 19 | + /** @var \Magento\Framework\ObjectManagerInterface */ |
| 20 | + private $objectManager; |
| 21 | + |
| 22 | + /** @var IndexerRegistry */ |
| 23 | + private $indexerRegistry; |
| 24 | + |
| 25 | + /** @var \Magento\Customer\Model\ResourceModel\Grid\Collection */ |
| 26 | + private $targetObject; |
| 27 | + |
| 28 | + /** @var CustomerRepositoryInterface */ |
| 29 | + private $customerRepository; |
| 30 | + |
| 31 | + protected function setUp() |
| 32 | + { |
| 33 | + $this->objectManager = Bootstrap::getObjectManager(); |
| 34 | + $this->indexerRegistry = $this->objectManager->create(IndexerRegistry::class); |
| 35 | + $this->targetObject = $this->objectManager |
| 36 | + ->create(\Magento\Customer\Model\ResourceModel\Grid\Collection::class); |
| 37 | + $this->customerRepository = $this->objectManager->create(CustomerRepositoryInterface::class); |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * Test updated data for customer grid indexer during save/update customer data(including address data) |
| 42 | + * 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 | + * @magentoDataFixture Magento/Customer/_files/customer_sample.php |
| 49 | + */ |
| 50 | + public function testGetItemByIdForUpdateOnSchedule() |
| 51 | + { |
| 52 | + /** Verify after first save */ |
| 53 | + /** @var CustomerInterface $newCustomer */ |
| 54 | + $newCustomer = $this->customerRepository->get('customer@example.com'); |
| 55 | + /** @var CustomerInterface $item */ |
| 56 | + $item = $this->targetObject->getItemById($newCustomer->getId()); |
| 57 | + $this->assertNotEmpty($item); |
| 58 | + $this->assertSame($newCustomer->getEmail(), $item->getEmail()); |
| 59 | + $this->assertSame('test street test city Armed Forces Middle East 01001', $item->getBillingFull()); |
| 60 | + |
| 61 | + /** Verify after update */ |
| 62 | + $newCustomer->setEmail('customer_updated@example.com'); |
| 63 | + $this->customerRepository->save($newCustomer); |
| 64 | + $this->targetObject->clear(); |
| 65 | + $item = $this->targetObject->getItemById($newCustomer->getId()); |
| 66 | + $this->assertSame($newCustomer->getEmail(), $item->getEmail()); |
| 67 | + } |
| 68 | +} |
0 commit comments