CollectionTest.php 2.6 KB

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