Skip to content

Commit d600ac8

Browse files
author
Bohdan Korablov
committed
MAGETWO-57743: Fix Catalog integration tests on Travis CI
2 parents de8cb2f + d0e44f9 commit d600ac8

File tree

58 files changed

+1841
-397
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1841
-397
lines changed

app/code/Magento/Catalog/Console/Command/ImagesResizeCommand.php

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,15 @@
55
*/
66
namespace Magento\Catalog\Console\Command;
77

8-
use Magento\Catalog\Model\Product;
9-
use Magento\Catalog\Model\Product\Image\Cache as ImageCache;
10-
use Magento\Catalog\Model\Product\Image\CacheFactory as ImageCacheFactory;
11-
use Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection;
12-
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory;
13-
use Magento\Framework\App\State as AppState;
14-
use Magento\Framework\Exception\NoSuchEntityException;
15-
use Symfony\Component\Console\Command\Command;
16-
use Symfony\Component\Console\Input\InputInterface;
17-
use Symfony\Component\Console\Output\OutputInterface;
18-
19-
class ImagesResizeCommand extends Command
8+
class ImagesResizeCommand extends \Symfony\Component\Console\Command\Command
209
{
2110
/**
22-
* @var AppState
11+
* @var \Magento\Framework\App\State
2312
*/
2413
protected $appState;
2514

2615
/**
27-
* @var ProductCollectionFactory
16+
* @var \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory
2817
*/
2918
protected $productCollectionFactory;
3019

@@ -34,21 +23,21 @@ class ImagesResizeCommand extends Command
3423
protected $productRepository;
3524

3625
/**
37-
* @var ImageCacheFactory
26+
* @var \Magento\Catalog\Model\Product\Image\CacheFactory
3827
*/
3928
protected $imageCacheFactory;
4029

4130
/**
42-
* @param AppState $appState
43-
* @param ProductCollectionFactory $productCollectionFactory
31+
* @param \Magento\Framework\App\State $appState
32+
* @param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory
4433
* @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
45-
* @param ImageCacheFactory $imageCacheFactory
34+
* @param \Magento\Catalog\Model\Product\Image\CacheFactory $imageCacheFactory
4635
*/
4736
public function __construct(
48-
AppState $appState,
49-
ProductCollectionFactory $productCollectionFactory,
37+
\Magento\Framework\App\State $appState,
38+
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
5039
\Magento\Catalog\Api\ProductRepositoryInterface $productRepository,
51-
ImageCacheFactory $imageCacheFactory
40+
\Magento\Catalog\Model\Product\Image\CacheFactory $imageCacheFactory
5241
) {
5342
$this->appState = $appState;
5443
$this->productCollectionFactory = $productCollectionFactory;
@@ -69,11 +58,13 @@ protected function configure()
6958
/**
7059
* {@inheritdoc}
7160
*/
72-
protected function execute(InputInterface $input, OutputInterface $output)
73-
{
74-
$this->appState->setAreaCode('catalog');
61+
protected function execute(
62+
\Symfony\Component\Console\Input\InputInterface $input,
63+
\Symfony\Component\Console\Output\OutputInterface $output
64+
) {
65+
$this->appState->setAreaCode(\Magento\Framework\App\Area::AREA_GLOBAL);
7566

76-
/** @var ProductCollection $productCollection */
67+
/** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection */
7768
$productCollection = $this->productCollectionFactory->create();
7869
$productIds = $productCollection->getAllIds();
7970
if (!count($productIds)) {
@@ -85,13 +76,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
8576
try {
8677
foreach ($productIds as $productId) {
8778
try {
88-
/** @var Product $product */
79+
/** @var \Magento\Catalog\Model\Product $product */
8980
$product = $this->productRepository->getById($productId);
90-
} catch (NoSuchEntityException $e) {
81+
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
9182
continue;
9283
}
9384

94-
/** @var ImageCache $imageCache */
85+
/** @var \Magento\Catalog\Model\Product\Image\Cache $imageCache */
9586
$imageCache = $this->imageCacheFactory->create();
9687
$imageCache->generate($product);
9788

app/code/Magento/Catalog/Console/Command/ProductAttributesCleanUp.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ protected function configure()
7878
protected function execute(InputInterface $input, OutputInterface $output)
7979
{
8080
$output->setDecorated(true);
81-
$this->appState->setAreaCode('catalog');
81+
$this->appState->setAreaCode(\Magento\Framework\App\Area::AREA_GLOBAL);
8282
$connection = $this->attributeResource->getConnection();
8383
$attributeTables = $this->getAttributeTables();
8484

app/code/Magento/Catalog/Model/Product/Gallery/ReadHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function addMediaDataToProduct(Product $product, array $mediaEntries)
7878

7979
foreach ($mediaEntries as $mediaEntry) {
8080
$mediaEntry = $this->substituteNullsWithDefaultValues($mediaEntry);
81-
$value['images'][] = $mediaEntry;
81+
$value['images'][$mediaEntry['value_id']] = $mediaEntry;
8282
}
8383
$product->setData($attrCode, $value);
8484
}

app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Eav/AbstractEav.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ protected function _getIndexableAttributesCondition()
263263
'ca.is_filterable_in_search > 0',
264264
'ca.is_visible_in_advanced_search > 0',
265265
'ca.is_filterable > 0',
266+
// Visibility is attribute that isn't used by search, but required to determine is product should be shown
267+
"ea.attribute_code = 'visibility'"
266268
];
267269

268270
return implode(' OR ', $conditions);

app/code/Magento/Catalog/Test/Unit/Console/Command/ImagesResizeCommandTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\Framework\App\State as AppState;
1515
use Magento\Framework\Exception\NoSuchEntityException;
1616
use Symfony\Component\Console\Tester\CommandTester;
17+
use \Magento\Framework\App\Area;
1718

1819
/**
1920
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -79,7 +80,7 @@ public function testExecuteNoProducts()
7980
{
8081
$this->appState->expects($this->once())
8182
->method('setAreaCode')
82-
->with('catalog')
83+
->with(Area::AREA_GLOBAL)
8384
->willReturnSelf();
8485

8586
$this->productCollection->expects($this->once())
@@ -101,7 +102,7 @@ public function testExecute()
101102

102103
$this->appState->expects($this->once())
103104
->method('setAreaCode')
104-
->with('catalog')
105+
->with(Area::AREA_GLOBAL)
105106
->willReturnSelf();
106107

107108
$this->productCollection->expects($this->once())
@@ -142,7 +143,7 @@ public function testExecuteWithException()
142143

143144
$this->appState->expects($this->once())
144145
->method('setAreaCode')
145-
->with('catalog')
146+
->with(Area::AREA_GLOBAL)
146147
->willReturnSelf();
147148

148149
$this->productCollection->expects($this->once())

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/General.php

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
use Magento\Catalog\Model\Locator\LocatorInterface;
1010
use Magento\Ui\Component\Form;
1111
use Magento\Framework\Stdlib\ArrayManager;
12-
use Magento\Store\Model\StoreManagerInterface;
13-
use Magento\Framework\Locale\CurrencyInterface;
1412

1513
/**
1614
* Data provider for main panel of product page
@@ -26,14 +24,9 @@ class General extends AbstractModifier
2624
* @var ArrayManager
2725
*/
2826
protected $arrayManager;
29-
30-
/**
31-
* @var StoreManagerInterface
32-
*/
33-
private $storeManager;
3427

3528
/**
36-
* @var CurrencyInterface
29+
* @var \Magento\Framework\Locale\CurrencyInterface
3730
*/
3831
private $localeCurrency;
3932

@@ -82,7 +75,7 @@ protected function customizeWeightFormat(array $data)
8275
$data = $this->arrayManager->replace(
8376
$path,
8477
$data,
85-
$this->formatNumber($this->arrayManager->get($path, $data))
78+
$this->formatWeight($this->arrayManager->get($path, $data))
8679
);
8780
}
8881

@@ -105,7 +98,7 @@ protected function customizeAdvancedPriceFormat(array $data)
10598
$value[ProductAttributeInterface::CODE_TIER_PRICE_FIELD_PRICE] =
10699
$this->formatPrice($value[ProductAttributeInterface::CODE_TIER_PRICE_FIELD_PRICE]);
107100
$value[ProductAttributeInterface::CODE_TIER_PRICE_FIELD_PRICE_QTY] =
108-
$this->formatNumber((int)$value[ProductAttributeInterface::CODE_TIER_PRICE_FIELD_PRICE_QTY]);
101+
(int)$value[ProductAttributeInterface::CODE_TIER_PRICE_FIELD_PRICE_QTY];
109102
}
110103
}
111104

@@ -373,28 +366,12 @@ protected function customizeNameListeners(array $meta)
373366
private function getLocaleCurrency()
374367
{
375368
if ($this->localeCurrency === null) {
376-
$this->localeCurrency = \Magento\Framework\App\ObjectManager::getInstance()->get(CurrencyInterface::class);
369+
$this->localeCurrency = \Magento\Framework\App\ObjectManager::getInstance()
370+
->get(\Magento\Framework\Locale\CurrencyInterface::class);
377371
}
378372
return $this->localeCurrency;
379373
}
380374

381-
/**
382-
* The getter function to get the store manager for real application code
383-
*
384-
* @return \Magento\Store\Model\StoreManagerInterface
385-
*
386-
* @deprecated
387-
*/
388-
private function getStoreManager()
389-
{
390-
if ($this->storeManager === null) {
391-
$this->storeManager =
392-
\Magento\Framework\App\ObjectManager::getInstance()->get(StoreManagerInterface::class);
393-
}
394-
return $this->storeManager;
395-
}
396-
397-
398375
/**
399376
* Format price according to the locale of the currency
400377
*
@@ -407,7 +384,7 @@ protected function formatPrice($value)
407384
return null;
408385
}
409386

410-
$store = $this->getStoreManager()->getStore();
387+
$store = $this->locator->getStore();
411388
$currency = $this->getLocaleCurrency()->getCurrency($store->getBaseCurrencyCode());
412389
$value = $currency->toCurrency($value, ['display' => \Magento\Framework\Currency::NO_SYMBOL]);
413390

@@ -428,7 +405,7 @@ protected function formatNumber($value)
428405

429406
$value = (float)$value;
430407
$precision = strlen(substr(strrchr($value, "."), 1));
431-
$store = $this->getStoreManager()->getStore();
408+
$store = $this->locator->getStore();
432409
$currency = $this->getLocaleCurrency()->getCurrency($store->getBaseCurrencyCode());
433410
$value = $currency->toCurrency($value, ['display' => \Magento\Framework\Currency::NO_SYMBOL,
434411
'precision' => $precision]);

app/code/Magento/CatalogImportExport/Model/Import/Uploader.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ public function move($fileName, $renameFileOff = false)
155155

156156
$filePath = $this->_directory->getRelativePath($this->getTmpDir() . '/' . $fileName);
157157
$this->_setUploadFile($filePath);
158-
$result = $this->save($this->getDestDir());
158+
$destDir = $this->_directory->getAbsolutePath($this->getDestDir());
159+
$result = $this->save($destDir);
159160
$result['name'] = self::getCorrectFileName($result['name']);
160161
return $result;
161162
}
@@ -305,11 +306,10 @@ protected function _moveFile($tmpPath, $destPath)
305306
$tmpRealPath = $this->_directory->getDriver()->getRealPath(
306307
$this->_directory->getAbsolutePath($tmpPath)
307308
);
308-
$destinationRealPath = $this->_directory->getDriver()->getRealPath(
309-
$this->_directory->getAbsolutePath($destPath)
310-
);
309+
$destinationRealPath = $this->_directory->getDriver()->getRealPath($destPath);
310+
$relativeDestPath = $this->_directory->getRelativePath($destPath);
311311
$isSameFile = $tmpRealPath === $destinationRealPath;
312-
return $isSameFile ?: $this->_directory->copyFile($tmpPath, $destPath);
312+
return $isSameFile ?: $this->_directory->copyFile($tmpPath, $relativeDestPath);
313313
} else {
314314
return false;
315315
}

app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/UploaderTest.php

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,11 @@ protected function setUp()
6868

6969
$this->readFactory = $this->getMockBuilder(\Magento\Framework\Filesystem\File\ReadFactory::class)
7070
->disableOriginalConstructor()
71+
->setMethods(['create'])
7172
->getMock();
7273

7374
$this->directoryMock = $this->getMockBuilder(\Magento\Framework\Filesystem\Directory\Writer::class)
74-
->setMethods(['writeFile', 'getRelativePath'])
75+
->setMethods(['writeFile', 'getRelativePath', 'isWritable', 'getAbsolutePath'])
7576
->disableOriginalConstructor()
7677
->getMock();
7778

@@ -92,6 +93,7 @@ protected function setUp()
9293
$this->filesystem,
9394
$this->readFactory,
9495
])
96+
->setMethods(['_setUploadFile', 'save', 'getTmpDir'])
9597
->getMock();
9698
}
9799

@@ -100,10 +102,14 @@ protected function setUp()
100102
*/
101103
public function testMoveFileUrl($fileUrl, $expectedHost, $expectedFileName)
102104
{
105+
$destDir = 'var/dest/dir';
103106
$expectedRelativeFilePath = $this->uploader->getTmpDir() . '/' . $expectedFileName;
107+
$this->directoryMock->expects($this->once())->method('isWritable')->with($destDir)->willReturn(true);
104108
$this->directoryMock->expects($this->any())->method('getRelativePath')->with($expectedRelativeFilePath);
109+
$this->directoryMock->expects($this->once())->method('getAbsolutePath')->with($destDir)
110+
->willReturn($destDir . '/' . $expectedFileName);
105111
// Check writeFile() method invoking.
106-
$this->directoryMock->expects($this->any())->method('writeFile')->will($this->returnValue(null));
112+
$this->directoryMock->expects($this->any())->method('writeFile')->will($this->returnValue($expectedFileName));
107113

108114
// Create adjusted reader which does not validate path.
109115
$readMock = $this->getMockBuilder(\Magento\Framework\Filesystem\File\Read::class)
@@ -113,59 +119,37 @@ public function testMoveFileUrl($fileUrl, $expectedHost, $expectedFileName)
113119
// Check readAll() method invoking.
114120
$readMock->expects($this->once())->method('readAll')->will($this->returnValue(null));
115121

116-
$this->readFactory = $this->getMockBuilder(\Magento\Framework\Filesystem\File\ReadFactory::class)
117-
->disableOriginalConstructor()
118-
->setMethods(['create'])
119-
->getMock();
120122
// Check create() method invoking with expected argument.
121123
$this->readFactory->expects($this->once())
122124
->method('create')
123125
->will($this->returnValue($readMock))->with($expectedHost);
124-
125-
$uploaderMock = $this->getMockBuilder(\Magento\CatalogImportExport\Model\Import\Uploader::class)
126-
->setConstructorArgs([
127-
$this->coreFileStorageDb,
128-
$this->coreFileStorage,
129-
$this->imageFactory,
130-
$this->validator,
131-
$this->filesystem,
132-
$this->readFactory,
133-
])
134-
->setMethods(['_setUploadFile', 'save', 'getTmpDir'])
135-
->getMock();
136-
137126
//Check invoking of getTmpDir(), _setUploadFile(), save() methods.
138-
$uploaderMock->expects($this->any())->method('getTmpDir')->will($this->returnValue(''));
139-
$uploaderMock->expects($this->once())->method('_setUploadFile')->will($this->returnSelf());
140-
$uploaderMock->expects($this->once())->method('save')->will($this->returnValue(['name' => null]));
127+
$this->uploader->expects($this->any())->method('getTmpDir')->will($this->returnValue(''));
128+
$this->uploader->expects($this->once())->method('_setUploadFile')->will($this->returnSelf());
129+
$this->uploader->expects($this->once())->method('save')->with($destDir . '/' . $expectedFileName)
130+
->willReturn(['name' => $expectedFileName]);
141131

142-
$uploaderMock->move($fileUrl);
132+
$this->uploader->setDestDir($destDir);
133+
$this->assertEquals(['name' => $expectedFileName], $this->uploader->move($fileUrl));
143134
}
144135

145136
public function testMoveFileName()
146137
{
138+
$destDir = 'var/dest/dir';
147139
$fileName = 'test_uploader_file';
148140
$expectedRelativeFilePath = $this->uploader->getTmpDir() . '/' . $fileName;
141+
$this->directoryMock->expects($this->once())->method('isWritable')->with($destDir)->willReturn(true);
149142
$this->directoryMock->expects($this->any())->method('getRelativePath')->with($expectedRelativeFilePath);
150-
151-
$uploaderMock = $this->getMockBuilder(\Magento\CatalogImportExport\Model\Import\Uploader::class)
152-
->setConstructorArgs([
153-
$this->coreFileStorageDb,
154-
$this->coreFileStorage,
155-
$this->imageFactory,
156-
$this->validator,
157-
$this->filesystem,
158-
$this->readFactory,
159-
])
160-
->setMethods(['_setUploadFile', 'save', 'getTmpDir'])
161-
->getMock();
162-
143+
$this->directoryMock->expects($this->once())->method('getAbsolutePath')->with($destDir)
144+
->willReturn($destDir . '/' . $fileName);
163145
//Check invoking of getTmpDir(), _setUploadFile(), save() methods.
164-
$uploaderMock->expects($this->once())->method('getTmpDir')->will($this->returnValue(''));
165-
$uploaderMock->expects($this->once())->method('_setUploadFile')->will($this->returnSelf());
166-
$uploaderMock->expects($this->once())->method('save')->will($this->returnValue(['name' => null]));
146+
$this->uploader->expects($this->once())->method('getTmpDir')->will($this->returnValue(''));
147+
$this->uploader->expects($this->once())->method('_setUploadFile')->will($this->returnSelf());
148+
$this->uploader->expects($this->once())->method('save')->with($destDir . '/' . $fileName)
149+
->willReturn(['name' => $fileName]);
167150

168-
$uploaderMock->move($fileName);
151+
$this->uploader->setDestDir($destDir);
152+
$this->assertEquals(['name' => $fileName], $this->uploader->move($fileName));
169153
}
170154

171155
public function moveFileUrlDataProvider()

0 commit comments

Comments
 (0)