Skip to content

Commit

Permalink
Merge pull request #1374 from magento-troll/TrollTeam_PR
Browse files Browse the repository at this point in the history
MAGETWO-70683 New registered customer not showed in admin customer grid
MAGETWO-70869 Console errors after turning on CSS merging/minification
  • Loading branch information
rganin authored Aug 1, 2017
2 parents 88084c3 + b521256 commit 22b7543
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 8 deletions.
4 changes: 1 addition & 3 deletions app/code/Magento/Customer/Model/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,7 @@ public function reindex()
{
/** @var \Magento\Framework\Indexer\IndexerInterface $indexer */
$indexer = $this->indexerRegistry->get(Customer::CUSTOMER_GRID_INDEXER_ID);
if (!$indexer->isScheduled()) {
$indexer->reindexRow($this->getCustomerId());
}
$indexer->reindexRow($this->getCustomerId());
}

/**
Expand Down
4 changes: 1 addition & 3 deletions app/code/Magento/Customer/Model/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1077,9 +1077,7 @@ public function reindex()
{
/** @var \Magento\Framework\Indexer\IndexerInterface $indexer */
$indexer = $this->indexerRegistry->get(self::CUSTOMER_GRID_INDEXER_ID);
if (!$indexer->isScheduled()) {
$indexer->reindexRow($this->getId());
}
$indexer->reindexRow($this->getId());
}

/**
Expand Down
15 changes: 13 additions & 2 deletions app/code/Magento/Deploy/Model/Mode.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Magento\Framework\Config\File\ConfigFilePool;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Magento\Framework\Exception\LocalizedException;

/**
* A class to manage Magento modes
Expand Down Expand Up @@ -75,13 +76,23 @@ public function __construct(
/**
* Enable production mode
*
* @throws LocalizedException
* @return void
*/
public function enableProductionMode()
{
$this->enableMaintenanceMode($this->output);
$this->filesystem->regenerateStatic($this->output);
$this->setStoreMode(State::MODE_PRODUCTION);
$previousMode = $this->getMode();
try {
// We have to turn on production mode before generation.
// We need this to enable generation of the "min" files.
$this->setStoreMode(State::MODE_PRODUCTION);
$this->filesystem->regenerateStatic($this->output);
} catch (LocalizedException $e) {
// We have to return store mode to previous state in case of error.
$this->setStoreMode($previousMode);
throw $e;
}
$this->disableMaintenanceMode($this->output);
}

Expand Down
69 changes: 69 additions & 0 deletions app/code/Magento/Deploy/Test/Unit/Model/ModeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use PHPUnit_Framework_MockObject_MockObject as Mock;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Magento\Framework\Config\File\ConfigFilePool;
use Magento\Framework\Exception\LocalizedException;

/**
* @inheritdoc
Expand Down Expand Up @@ -96,4 +98,71 @@ public function testGetMode()
$this->assertSame(null, $this->model->getMode());
$this->assertSame(State::MODE_DEVELOPER, $this->model->getMode());
}

/**
* Test that production mode will be enabled before static generation call.
* We need this to be sure that "min" files will be generated.
*/
public function testEnableProductionMode()
{
$mode = State::MODE_DEVELOPER;
$modeModel = $this->model;
$dataStorage = [
ConfigFilePool::APP_ENV => [
State::PARAM_MODE => State::MODE_DEVELOPER,
],
];
$this->writerMock->expects($this->once())
->method("saveConfig")
->willReturnCallback(function ($data) use (&$dataStorage) {
$dataStorage = $data;
});
$this->readerMock->expects($this->any())
->method('load')
->willReturnCallback(function () use (&$dataStorage) {
return $dataStorage[ConfigFilePool::APP_ENV];
});
$this->filesystemMock->expects($this->once())
->method("regenerateStatic")
->willReturnCallback(function () use (&$modeModel, &$mode) {
$mode = $modeModel->getMode();
});
$this->model->enableProductionMode();
$this->assertEquals(State::MODE_PRODUCTION, $mode);
}

/**
* Test that previous mode will be enabled after error during static generation call.
* We need this to be sure that mode will be reverted to it previous tate.
*
* @expectedException \Magento\Framework\Exception\LocalizedException
*/
public function testEnableDeveloperModeOnFail()
{
$mode = State::MODE_DEVELOPER;
$dataStorage = [
ConfigFilePool::APP_ENV => [
State::PARAM_MODE => State::MODE_DEVELOPER,
],
];
$this->writerMock->expects($this->exactly(2))
->method("saveConfig")
->withConsecutive(
[$this->equalTo([ConfigFilePool::APP_ENV => [State::PARAM_MODE => State::MODE_PRODUCTION]])],
[$this->equalTo([ConfigFilePool::APP_ENV => [State::PARAM_MODE => State::MODE_DEVELOPER]])]
)
->willReturnCallback(function ($data) use (&$dataStorage) {
$dataStorage = $data;
});
$this->readerMock->expects($this->any())
->method('load')
->willReturnCallback(function () use (&$dataStorage) {
return $dataStorage[ConfigFilePool::APP_ENV];
});
$this->filesystemMock->expects($this->once())
->method("regenerateStatic")
->willThrowException(new LocalizedException(__('Exception')));
$this->model->enableProductionMode();
$this->assertEquals(State::MODE_PRODUCTION, $mode);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Customer\Model\ResourceModel\Grid;

use Magento\Customer\Api\CustomerRepositoryInterface;
use Magento\Customer\Api\Data\CustomerInterface;
use Magento\Framework\Indexer\IndexerRegistry;
use Magento\TestFramework\Helper\Bootstrap;

/**
* Customer grid collection tests.
*/
class CollectionTest extends \Magento\TestFramework\Indexer\TestCase
{
/** @var \Magento\Framework\ObjectManagerInterface */
private $objectManager;

/** @var IndexerRegistry */
private $indexerRegistry;

/** @var \Magento\Customer\Model\ResourceModel\Grid\Collection */
private $targetObject;

/** @var CustomerRepositoryInterface */
private $customerRepository;

protected function setUp()
{
$this->objectManager = Bootstrap::getObjectManager();
$this->indexerRegistry = $this->objectManager->create(IndexerRegistry::class);
$this->targetObject = $this->objectManager
->create(\Magento\Customer\Model\ResourceModel\Grid\Collection::class);
$this->customerRepository = $this->objectManager->create(CustomerRepositoryInterface::class);
}

/**
* Test updated data for customer grid indexer during save/update customer data(including address data)
* in 'Update on Schedule' mode.
*
* Customer Grid Indexer can't work in 'Update on Schedule' mode. All data for indexer must be updated in realtime
* during save/update customer data(including address data).
*
* @magentoDataFixture Magento/Customer/_files/customer_grid_indexer_enabled_update_on_schedule.php
* @magentoDataFixture Magento/Customer/_files/customer_sample.php
*/
public function testGetItemByIdForUpdateOnSchedule()
{
/** Verify after first save */
/** @var CustomerInterface $newCustomer */
$newCustomer = $this->customerRepository->get('customer@example.com');
/** @var CustomerInterface $item */
$item = $this->targetObject->getItemById($newCustomer->getId());
$this->assertNotEmpty($item);
$this->assertSame($newCustomer->getEmail(), $item->getEmail());
$this->assertSame('test street test city Armed Forces Middle East 01001', $item->getBillingFull());

/** Verify after update */
$newCustomer->setEmail('customer_updated@example.com');
$this->customerRepository->save($newCustomer);
$this->targetObject->clear();
$item = $this->targetObject->getItemById($newCustomer->getId());
$this->assertSame($newCustomer->getEmail(), $item->getEmail());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
/** @var Magento\Framework\Indexer\IndexerRegistry $indexerRegistry */
$indexerRegistry = $objectManager->create(\Magento\Framework\Indexer\IndexerRegistry::class);
$indexer = $indexerRegistry->get(\Magento\Customer\Model\Customer::CUSTOMER_GRID_INDEXER_ID);
$indexer->setScheduled(true);
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
/** @var Magento\Framework\Indexer\IndexerRegistry $indexerRegistry */
$indexerRegistry = $objectManager->create(\Magento\Framework\Indexer\IndexerRegistry::class);
$indexer = $indexerRegistry->get(\Magento\Customer\Model\Customer::CUSTOMER_GRID_INDEXER_ID);
$indexer->setScheduled(false);

0 comments on commit 22b7543

Please sign in to comment.