Skip to content

Commit 21b3976

Browse files
MAGETWO-59114: [PR] Bug fixes for Import/Export, Travis
4 parents 6af7f78 + 64d1e69 + a25e326 + d029543 commit 21b3976

File tree

6 files changed

+145
-8
lines changed

6 files changed

+145
-8
lines changed

app/code/Magento/ImportExport/Model/Import.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,10 @@ public function invalidateIndex()
605605
foreach (array_keys($relatedIndexers) as $indexerId) {
606606
try {
607607
$indexer = $this->indexerRegistry->get($indexerId);
608-
$indexer->invalidate();
608+
609+
if (!$indexer->isScheduled()) {
610+
$indexer->invalidate();
611+
}
609612
} catch (\InvalidArgumentException $e) {
610613
}
611614
}

app/code/Magento/ImportExport/Test/Unit/Model/ImportTest.php

Lines changed: 86 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
*/
66
namespace Magento\ImportExport\Test\Unit\Model;
77

8+
use Magento\Framework\Indexer\IndexerInterface;
9+
use Magento\ImportExport\Model\Import;
10+
811
/**
912
* Class ImportTest
1013
* @package Magento\ImportExport\Test\Unit\Model
@@ -126,7 +129,7 @@ protected function setUp()
126129
->getMock();
127130
$this->_importConfig = $this->getMockBuilder(\Magento\ImportExport\Model\Import\Config::class)
128131
->disableOriginalConstructor()
129-
->setMethods(['getEntityTypeCode', 'getBehavior', 'getEntities'])
132+
->setMethods(['getEntityTypeCode', 'getBehavior', 'getEntities', 'getRelatedIndexers'])
130133
->getMockForAbstractClass();
131134
$this->_entityFactory = $this->getMockBuilder(\Magento\ImportExport\Model\Import\Entity\Factory::class)
132135
->disableOriginalConstructor()
@@ -419,12 +422,90 @@ public function testValidateSource()
419422
$this->markTestIncomplete('This test has not been implemented yet.');
420423
}
421424

422-
/**
423-
* @todo to implement it.
424-
*/
425425
public function testInvalidateIndex()
426426
{
427-
$this->markTestIncomplete('This test has not been implemented yet.');
427+
$indexers = [
428+
'indexer_1' => 'indexer_1',
429+
'indexer_2' => 'indexer_2'
430+
];
431+
$indexer1 = $this->getMockBuilder(IndexerInterface::class)
432+
->getMockForAbstractClass();
433+
$indexer2 = clone $indexer1;
434+
$logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)
435+
->disableOriginalConstructor()
436+
->getMock();
437+
438+
$indexer1->expects($this->once())
439+
->method('isScheduled')
440+
->willReturn(true);
441+
$indexer1->expects($this->never())
442+
->method('invalidate');
443+
$indexer2->expects($this->once())
444+
->method('isScheduled')
445+
->willReturn(false);
446+
$indexer2->expects($this->once())
447+
->method('invalidate');
448+
449+
$this->_importConfig->expects($this->atLeastOnce())
450+
->method('getRelatedIndexers')
451+
->willReturn($indexers);
452+
$this->indexerRegistry->expects($this->any())
453+
->method('get')
454+
->willReturnMap([
455+
['indexer_1', $indexer1],
456+
['indexer_2', $indexer2],
457+
]);
458+
459+
$import = new Import(
460+
$logger,
461+
$this->_filesystem,
462+
$this->_importExportData,
463+
$this->_coreConfig,
464+
$this->_importConfig,
465+
$this->_entityFactory,
466+
$this->_importData,
467+
$this->_csvFactory,
468+
$this->_httpFactory,
469+
$this->_uploaderFactory,
470+
$this->_behaviorFactory,
471+
$this->indexerRegistry,
472+
$this->historyModel,
473+
$this->dateTime
474+
);
475+
476+
$import->setEntity('test');
477+
$import->invalidateIndex();
478+
}
479+
480+
public function testInvalidateIndexWithoutIndexers()
481+
{
482+
$this->_importConfig->expects($this->once())
483+
->method('getRelatedIndexers')
484+
->willReturn([]);
485+
486+
$logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)
487+
->disableOriginalConstructor()
488+
->getMock();
489+
490+
$import = new Import(
491+
$logger,
492+
$this->_filesystem,
493+
$this->_importExportData,
494+
$this->_coreConfig,
495+
$this->_importConfig,
496+
$this->_entityFactory,
497+
$this->_importData,
498+
$this->_csvFactory,
499+
$this->_httpFactory,
500+
$this->_uploaderFactory,
501+
$this->_behaviorFactory,
502+
$this->indexerRegistry,
503+
$this->historyModel,
504+
$this->dateTime
505+
);
506+
507+
$import->setEntity('test');
508+
$this->assertSame($import, $import->invalidateIndex());
428509
}
429510

430511
/**
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Framework\Backup;
7+
8+
use \Magento\TestFramework\Helper\Bootstrap;
9+
use \Magento\Framework\App\Filesystem\DirectoryList;
10+
11+
class FilesystemTest extends \PHPUnit_Framework_TestCase
12+
{
13+
/**
14+
* @var \Magento\Framework\ObjectManagerInterface
15+
*/
16+
private $objectManager;
17+
18+
/**
19+
* @var \Magento\Framework\Backup\Filesystem
20+
*/
21+
private $filesystem;
22+
23+
protected function setUp()
24+
{
25+
$this->objectManager = Bootstrap::getObjectManager();
26+
$this->filesystem = $this->objectManager->create(\Magento\Framework\Backup\Filesystem::class);
27+
}
28+
29+
/**
30+
* @magentoAppIsolation enabled
31+
*/
32+
public function testRollback()
33+
{
34+
$rootDir = Bootstrap::getInstance()->getAppTempDir()
35+
. '/rollback_test_' . time();
36+
$backupsDir = __DIR__ . '/_files/var/backups';
37+
$fileName = 'test.txt';
38+
39+
mkdir($rootDir);
40+
41+
$this->filesystem->setRootDir($rootDir)
42+
->setBackupsDir($backupsDir)
43+
->setTime(1474538269)
44+
->setName('code')
45+
->setBackupExtension('tgz');
46+
47+
$this->assertTrue($this->filesystem->rollback());
48+
$this->assertTrue(file_exists($rootDir . '/' . $fileName));
49+
}
50+
}

dev/tests/integration/testsuite/Magento/Framework/Image/Adapter/InterfaceTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,9 @@ public function cropDataProvider()
547547
*/
548548
public function testCreatePngFromString($pixel1, $expectedColor1, $pixel2, $expectedColor2, $adapterType)
549549
{
550+
if (!function_exists('imagettfbbox')) {
551+
$this->markTestSkipped('Workaround for problem with imagettfbbox() function on Travis');
552+
}
550553
$adapter = $this->_getAdapter($adapterType);
551554

552555
/** @var \Magento\Framework\Filesystem\Directory\ReadFactory readFactory */

lib/internal/Magento/Framework/Backup/Filesystem.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ protected function getRollBackFtp()
316316
if (!$this->rollBackFtp) {
317317
$this->rollBackFtp = ObjectManager::getInstance()->create(
318318
\Magento\Framework\Backup\Filesystem\Rollback\Ftp::class,
319-
[$this]
319+
['snapshotObject' => $this]
320320
);
321321
}
322322

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

0 commit comments

Comments
 (0)