Skip to content

Commit e1e7da3

Browse files
authored
Magento Auto Sync Merge from: magento / magento2ce / develop
2 parents f6f7ffe + 30ceb4c commit e1e7da3

File tree

25 files changed

+1088
-68
lines changed

25 files changed

+1088
-68
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ public function createBatchBaseSelect($storeId, $attributeId)
177177
[
178178
$mainTableAlias . '.value_id = value.value_id',
179179
$this->getConnection()->quoteInto('value.store_id = ?', (int)$storeId),
180+
'value.' . $linkField . ' = entity.' . $linkField,
180181
]
181182
),
182183
['label', 'position', 'disabled']
@@ -187,6 +188,7 @@ public function createBatchBaseSelect($storeId, $attributeId)
187188
[
188189
$mainTableAlias . '.value_id = default_value.value_id',
189190
$this->getConnection()->quoteInto('default_value.store_id = ?', Store::DEFAULT_STORE_ID),
191+
'default_value.' . $linkField . ' = entity.' . $linkField,
190192
]
191193
),
192194
['label_default' => 'label', 'position_default' => 'position', 'disabled_default' => 'disabled']

app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/GalleryTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,12 @@ public function testLoadGallery()
317317
$attributeId = 6;
318318
$getTableReturnValue = 'table';
319319
$quoteInfoReturnValue =
320-
'main.value_id = value.value_id AND value.store_id = ' . $storeId;
320+
'main.value_id = value.value_id AND value.store_id = ' . $storeId
321+
. ' AND value.entity_id = entity.entity_id';
322+
$quoteDefaultInfoReturnValue =
323+
'main.value_id = default_value.value_id AND default_value.store_id = 0'
324+
. ' AND default_value.entity_id = entity.entity_id';
325+
321326
$positionCheckSql = 'testchecksql';
322327
$resultRow = [
323328
[
@@ -373,7 +378,7 @@ public function testLoadGallery()
373378
)->willReturnSelf();
374379
$this->select->expects($this->at(3))->method('joinLeft')->with(
375380
['default_value' => $getTableReturnValue],
376-
'main.value_id = default_value.value_id AND default_value.store_id = 0',
381+
$quoteDefaultInfoReturnValue,
377382
['label_default' => 'label', 'position_default' => 'position', 'disabled_default' => 'disabled']
378383
)->willReturnSelf();
379384
$this->select->expects($this->at(4))->method('where')->with(

dev/tests/integration/testsuite/Magento/Setup/Fixtures/FixtureModelTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ protected function setUp()
5555
$this->entityAsserts[] = $this->objectManager->get(FixturesAsserts\SimpleProductsAssert::class);
5656
$this->entityAsserts[] = $this->objectManager->get(FixturesAsserts\ConfigurableProductsAssert::class);
5757
$this->entityAsserts[] = $this->objectManager->get(FixturesAsserts\BundleProductsAssert::class);
58+
$this->entityAsserts[] = $this->objectManager->get(FixturesAsserts\ImagesAssert::class);
5859

5960
foreach ($this->objectManager->get(Config::class)->getIndexers() as $indexerId) {
6061
$indexer = $this->indexerRegistry->get($indexerId['indexer_id']);
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Setup\Fixtures\FixturesAsserts;
8+
9+
use Magento\Framework\App\Filesystem\DirectoryList;
10+
11+
/**
12+
* Class ImagesAssert
13+
*
14+
* Class performs assertions to check that generated images are valid
15+
* after running setup:performance:generate-fixtures command
16+
*/
17+
class ImagesAssert
18+
{
19+
/**
20+
* @var \Magento\Catalog\Api\ProductRepositoryInterface
21+
*/
22+
private $productRepository;
23+
24+
/**
25+
* @var \Magento\Framework\Api\SearchCriteriaBuilder
26+
*/
27+
private $searchCriteriaBuilder;
28+
29+
/**
30+
* @var \Magento\Catalog\Model\Product\Gallery\ReadHandler
31+
*/
32+
private $readHandler;
33+
34+
/**
35+
* @var \Magento\Framework\Filesystem
36+
*/
37+
private $filesystem;
38+
39+
/**
40+
* @var \Magento\Catalog\Model\Product\Media\Config
41+
*/
42+
private $mediaConfig;
43+
44+
/**
45+
* @var \Magento\Framework\Filesystem\Directory\ReadInterface
46+
*/
47+
private $mediaDirectory;
48+
49+
/**
50+
* @param \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder
51+
* @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
52+
* @param \Magento\Catalog\Model\Product\Gallery\ReadHandler $readHandler
53+
* @param \Magento\Framework\Filesystem $filesystem
54+
* @param \Magento\Catalog\Model\Product\Media\Config $mediaConfig
55+
*/
56+
public function __construct(
57+
\Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder,
58+
\Magento\Catalog\Api\ProductRepositoryInterface $productRepository,
59+
\Magento\Catalog\Model\Product\Gallery\ReadHandler $readHandler,
60+
\Magento\Framework\Filesystem $filesystem,
61+
\Magento\Catalog\Model\Product\Media\Config $mediaConfig
62+
) {
63+
$this->productRepository = $productRepository;
64+
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
65+
$this->readHandler = $readHandler;
66+
$this->filesystem = $filesystem;
67+
$this->mediaConfig = $mediaConfig;
68+
}
69+
70+
/**
71+
* Performs assertions over images
72+
*
73+
* @throws \AssertionError
74+
*/
75+
public function assert()
76+
{
77+
$searchCriteria = $this->searchCriteriaBuilder->create();
78+
$products = $this->productRepository->getList($searchCriteria)->getItems();
79+
80+
foreach ($products as $product) {
81+
$this->assertProductMediaGallery($product);
82+
$this->assertProductMediaAttributes($product);
83+
$this->assertProductImageExistsInFS($product);
84+
}
85+
}
86+
87+
/**
88+
* Performs assertions over media_gallery product attribute
89+
*
90+
* @param \Magento\Catalog\Model\Product $product
91+
* @throws \AssertionError
92+
*/
93+
private function assertProductMediaGallery(\Magento\Catalog\Model\Product $product)
94+
{
95+
$extendedProduct = $this->readHandler->execute($product);
96+
$mediaGalleryImages = $extendedProduct->getMediaGalleryEntries();
97+
98+
if (count($mediaGalleryImages) !== 1) {
99+
throw new \AssertionError('Product supposed to contain one image');
100+
}
101+
102+
$image = reset($mediaGalleryImages);
103+
104+
if ($image->getFile() === null) {
105+
throw new \AssertionError('Image path should not be null');
106+
}
107+
}
108+
109+
/**
110+
* Performs assertions over product media attributes
111+
* e.g. image|small_image|swatch_image|thumbnail
112+
*
113+
* @param \Magento\Catalog\Model\Product $product
114+
* @throws \AssertionError
115+
*/
116+
private function assertProductMediaAttributes(\Magento\Catalog\Model\Product $product)
117+
{
118+
foreach ($product->getMediaAttributeValues() as $attributeCode => $attributeValue) {
119+
if (empty($attributeValue)) {
120+
throw new \AssertionError(
121+
sprintf('Attribute: %s should not be empty', $attributeCode)
122+
);
123+
}
124+
}
125+
}
126+
127+
/**
128+
* Performs assertions over image files in FS
129+
*
130+
* @param \Magento\Catalog\Model\Product $product
131+
* @throws \AssertionError
132+
*/
133+
private function assertProductImageExistsInFS(\Magento\Catalog\Model\Product $product)
134+
{
135+
$mediaDirectory = $this->getMediaDirectory();
136+
$mediaAttributes = $product->getMediaAttributeValues();
137+
138+
if (!$mediaDirectory->isExist($this->mediaConfig->getBaseMediaPath() . $mediaAttributes['image'])) {
139+
throw new \AssertionError('Image file for product supposed to exist');
140+
}
141+
}
142+
143+
/**
144+
* Local cache for $mediaDirectory
145+
*
146+
* @return \Magento\Framework\Filesystem\Directory\ReadInterface
147+
*/
148+
private function getMediaDirectory()
149+
{
150+
if ($this->mediaDirectory === null) {
151+
$this->mediaDirectory = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA);
152+
}
153+
154+
return $this->mediaDirectory;
155+
}
156+
}

dev/tests/integration/testsuite/Magento/Setup/Fixtures/_files/small.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
<bundle_products>2</bundle_products>
1616
<bundle_products_options>2</bundle_products_options>
1717
<bundle_products_variation>2</bundle_products_variation>
18+
<product-images>
19+
<images-count>3</images-count>
20+
<images-per-product>1</images-per-product>
21+
</product-images>
1822
<configurable_products>
1923
<config>
2024
<attributeSet>Default</attributeSet>

setup/performance-toolkit/README.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,6 @@ Details http://jmeter.apache.org/usermanual/component_reference.html#View_Result
8585

8686
About other types read on
8787
http://jmeter.apache.org/usermanual/component_reference.html
88+
89+
About fixtures generation
90+
http://devdocs.magento.com/guides/v2.2/config-guide/cli/config-cli-subcommands-perf-data.html

setup/performance-toolkit/profiles/ce/extra_large.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
<products>16000</products>
2121
</config>
2222
</configurable_products>
23+
<product-images>
24+
<images-count>2000</images-count>
25+
<images-per-product>3</images-per-product>
26+
</product-images>
2327
<categories>6000</categories> <!-- Number of categories to generate -->
2428
<categories_nesting_level>5</categories_nesting_level> <!-- Nesting level for categories -->
2529
<customers>10000</customers> <!-- Number of customers to generate -->

setup/performance-toolkit/profiles/ce/large.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
<products>8000</products>
2121
</config>
2222
</configurable_products>
23+
<product-images>
24+
<images-count>2000</images-count>
25+
<images-per-product>3</images-per-product>
26+
</product-images>
2327
<categories>3000</categories> <!-- Number of categories to generate -->
2428
<categories_nesting_level>5</categories_nesting_level> <!-- Nesting level for categories -->
2529
<customers>5000</customers> <!-- Number of customers to generate -->

setup/performance-toolkit/profiles/ce/medium.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
<products>640</products>
2121
</config>
2222
</configurable_products>
23+
<product-images>
24+
<images-count>1000</images-count>
25+
<images-per-product>3</images-per-product>
26+
</product-images>
2327
<categories>300</categories> <!-- Number of categories to generate -->
2428
<categories_nesting_level>3</categories_nesting_level> <!-- Nesting level for categories -->
2529
<customers>2000</customers> <!-- Number of customers to generate -->

setup/performance-toolkit/profiles/ce/medium_msite.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
<products>79</products>
2727
</config>
2828
</configurable_products>
29+
<product-images>
30+
<images-count>1000</images-count>
31+
<images-per-product>3</images-per-product>
32+
</product-images>
2933
<categories>100</categories> <!-- Number of categories to generate -->
3034
<categories_nesting_level>3</categories_nesting_level> <!-- Nesting level for categories -->
3135
<customers>2000</customers> <!-- Number of customers to generate -->

0 commit comments

Comments
 (0)