Skip to content

Commit

Permalink
Merge pull request #454 from magento-falcons/MAGETWO-59114
Browse files Browse the repository at this point in the history
[Falcons] Bug fixes for Import/Export, Travis
  • Loading branch information
Yaroslav Onischenko authored Oct 3, 2016
2 parents 6614360 + dcbb6fc commit 152309b
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 8 deletions.
5 changes: 4 additions & 1 deletion app/code/Magento/ImportExport/Model/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,10 @@ public function invalidateIndex()
foreach (array_keys($relatedIndexers) as $indexerId) {
try {
$indexer = $this->indexerRegistry->get($indexerId);
$indexer->invalidate();

if (!$indexer->isScheduled()) {
$indexer->invalidate();
}
} catch (\InvalidArgumentException $e) {
}
}
Expand Down
91 changes: 86 additions & 5 deletions app/code/Magento/ImportExport/Test/Unit/Model/ImportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
*/
namespace Magento\ImportExport\Test\Unit\Model;

use Magento\Framework\Indexer\IndexerInterface;
use Magento\ImportExport\Model\Import;

/**
* Class ImportTest
* @package Magento\ImportExport\Test\Unit\Model
Expand Down Expand Up @@ -126,7 +129,7 @@ protected function setUp()
->getMock();
$this->_importConfig = $this->getMockBuilder(\Magento\ImportExport\Model\Import\Config::class)
->disableOriginalConstructor()
->setMethods(['getEntityTypeCode', 'getBehavior', 'getEntities'])
->setMethods(['getEntityTypeCode', 'getBehavior', 'getEntities', 'getRelatedIndexers'])
->getMockForAbstractClass();
$this->_entityFactory = $this->getMockBuilder(\Magento\ImportExport\Model\Import\Entity\Factory::class)
->disableOriginalConstructor()
Expand Down Expand Up @@ -419,12 +422,90 @@ public function testValidateSource()
$this->markTestIncomplete('This test has not been implemented yet.');
}

/**
* @todo to implement it.
*/
public function testInvalidateIndex()
{
$this->markTestIncomplete('This test has not been implemented yet.');
$indexers = [
'indexer_1' => 'indexer_1',
'indexer_2' => 'indexer_2'
];
$indexer1 = $this->getMockBuilder(IndexerInterface::class)
->getMockForAbstractClass();
$indexer2 = clone $indexer1;
$logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)
->disableOriginalConstructor()
->getMock();

$indexer1->expects($this->once())
->method('isScheduled')
->willReturn(true);
$indexer1->expects($this->never())
->method('invalidate');
$indexer2->expects($this->once())
->method('isScheduled')
->willReturn(false);
$indexer2->expects($this->once())
->method('invalidate');

$this->_importConfig->expects($this->atLeastOnce())
->method('getRelatedIndexers')
->willReturn($indexers);
$this->indexerRegistry->expects($this->any())
->method('get')
->willReturnMap([
['indexer_1', $indexer1],
['indexer_2', $indexer2],
]);

$import = new Import(
$logger,
$this->_filesystem,
$this->_importExportData,
$this->_coreConfig,
$this->_importConfig,
$this->_entityFactory,
$this->_importData,
$this->_csvFactory,
$this->_httpFactory,
$this->_uploaderFactory,
$this->_behaviorFactory,
$this->indexerRegistry,
$this->historyModel,
$this->dateTime
);

$import->setEntity('test');
$import->invalidateIndex();
}

public function testInvalidateIndexWithoutIndexers()
{
$this->_importConfig->expects($this->once())
->method('getRelatedIndexers')
->willReturn([]);

$logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)
->disableOriginalConstructor()
->getMock();

$import = new Import(
$logger,
$this->_filesystem,
$this->_importExportData,
$this->_coreConfig,
$this->_importConfig,
$this->_entityFactory,
$this->_importData,
$this->_csvFactory,
$this->_httpFactory,
$this->_uploaderFactory,
$this->_behaviorFactory,
$this->indexerRegistry,
$this->historyModel,
$this->dateTime
);

$import->setEntity('test');
$this->assertSame($import, $import->invalidateIndex());
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\Backup;

use \Magento\TestFramework\Helper\Bootstrap;
use \Magento\Framework\App\Filesystem\DirectoryList;

class FilesystemTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Magento\Framework\ObjectManagerInterface
*/
private $objectManager;

/**
* @var \Magento\Framework\Backup\Filesystem
*/
private $filesystem;

protected function setUp()
{
$this->objectManager = Bootstrap::getObjectManager();
$this->filesystem = $this->objectManager->create(\Magento\Framework\Backup\Filesystem::class);
}

/**
* @magentoAppIsolation enabled
*/
public function testRollback()
{
$rootDir = Bootstrap::getInstance()->getAppTempDir()
. '/rollback_test_' . time();
$backupsDir = __DIR__ . '/_files/var/backups';
$fileName = 'test.txt';

mkdir($rootDir);

$this->filesystem->setRootDir($rootDir)
->setBackupsDir($backupsDir)
->setTime(1474538269)
->setName('code')
->setBackupExtension('tgz');

$this->assertTrue($this->filesystem->rollback());
$this->assertTrue(file_exists($rootDir . '/' . $fileName));
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,9 @@ public function cropDataProvider()
*/
public function testCreatePngFromString($pixel1, $expectedColor1, $pixel2, $expectedColor2, $adapterType)
{
if (!function_exists('imagettfbbox')) {
$this->markTestSkipped('Workaround for problem with imagettfbbox() function on Travis');
}
$adapter = $this->_getAdapter($adapterType);

/** @var \Magento\Framework\Filesystem\Directory\ReadFactory readFactory */
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/Magento/Framework/Backup/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ protected function getRollBackFtp()
if (!$this->rollBackFtp) {
$this->rollBackFtp = ObjectManager::getInstance()->create(
\Magento\Framework\Backup\Filesystem\Rollback\Ftp::class,
[$this]
['snapshotObject' => $this]
);
}

Expand All @@ -332,7 +332,7 @@ protected function getRollBackFs()
if (!$this->rollBackFs) {
$this->rollBackFs = ObjectManager::getInstance()->create(
\Magento\Framework\Backup\Filesystem\Rollback\Fs::class,
[$this]
['snapshotObject' => $this]
);
}

Expand Down

0 comments on commit 152309b

Please sign in to comment.