Skip to content

Commit d48cdc1

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

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 -->

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

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

setup/src/Magento/Setup/Fixtures/AdminUsersFixture.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
/**
1010
* Generate admin users
11+
*
12+
* Support the following format:
13+
* <!-- Number of admin users -->
14+
* <admin_users>{int}</admin_users>
1115
*/
1216
class AdminUsersFixture extends Fixture
1317
{

setup/src/Magento/Setup/Fixtures/AttributeSet/SwatchesGenerator.php

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -35,33 +35,30 @@ class SwatchesGenerator
3535
const GENERATED_SWATCH_TMP_NAME = 'tmp_swatch.jpg';
3636

3737
/**
38-
* @var \Magento\Framework\Filesystem
38+
* @var \Magento\Swatches\Helper\Media
3939
*/
40-
private $filesystem;
40+
private $swatchHelper;
4141

4242
/**
43-
* @var \Magento\Catalog\Model\Product\Media\Config
43+
* @var \Magento\Setup\Fixtures\ImagesGenerator\ImagesGeneratorFactory
4444
*/
45-
private $mediaConfig;
45+
private $imagesGeneratorFactory;
4646

4747
/**
48-
* @var \Magento\Swatches\Helper\Media
48+
* @var \Magento\Setup\Fixtures\ImagesGenerator\ImagesGenerator
4949
*/
50-
private $swatchHelper;
50+
private $imagesGenerator;
5151

5252
/**
53-
* @param \Magento\Framework\Filesystem $filesystem
54-
* @param \Magento\Catalog\Model\Product\Media\Config $config
5553
* @param \Magento\Swatches\Helper\Media $swatchHelper
54+
* @param \Magento\Setup\Fixtures\ImagesGenerator\ImagesGeneratorFactory $imagesGeneratorFactory
5655
*/
5756
public function __construct(
58-
\Magento\Framework\Filesystem $filesystem,
59-
\Magento\Catalog\Model\Product\Media\Config $config,
60-
\Magento\Swatches\Helper\Media $swatchHelper
57+
\Magento\Swatches\Helper\Media $swatchHelper,
58+
\Magento\Setup\Fixtures\ImagesGenerator\ImagesGeneratorFactory $imagesGeneratorFactory
6159
) {
62-
$this->filesystem = $filesystem;
63-
$this->mediaConfig = $config;
6460
$this->swatchHelper = $swatchHelper;
61+
$this->imagesGeneratorFactory = $imagesGeneratorFactory;
6562
}
6663

6764
/**
@@ -128,33 +125,18 @@ private function generateSwatchColor($index)
128125
*/
129126
private function generateSwatchImage($data)
130127
{
131-
$binaryData = '';
132-
$data = str_split(sha1($data), 2);
133-
foreach ($data as $item) {
134-
$binaryData .= base_convert($item, 16, 2);
135-
}
136-
$binaryData = str_split($binaryData, 1);
137-
138-
$image = imagecreate(self::GENERATED_SWATCH_WIDTH, self::GENERATED_SWATCH_HEIGHT);
139-
$bgColor = imagecolorallocate($image, 240, 240, 240);
140-
$fgColor = imagecolorallocate($image, mt_rand(0, 230), mt_rand(0, 230), mt_rand(0, 230));
141-
$colors = [$fgColor, $bgColor];
142-
imagefilledrectangle($image, 0, 0, self::GENERATED_SWATCH_WIDTH, self::GENERATED_SWATCH_HEIGHT, $bgColor);
143-
144-
for ($row = 10; $row < 100; $row += 18) {
145-
for ($col = 0; $col < 90; $col += 18) {
146-
next($binaryData);
147-
imagefilledrectangle($image, $row, $col, $row + 18, $col + 18, $colors[current($binaryData)]);
148-
}
128+
if ($this->imagesGenerator === null) {
129+
$this->imagesGenerator = $this->imagesGeneratorFactory->create();
149130
}
150131

151-
$mediaDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA);
152-
$absolutePathToMedia = $mediaDirectory->getAbsolutePath($this->mediaConfig->getBaseTmpMediaPath());
153-
$relativePathToMedia = $mediaDirectory->getRelativePath($this->mediaConfig->getBaseTmpMediaPath());
154-
$mediaDirectory->create($relativePathToMedia);
132+
$imageName = md5($data) . '.jpg';
133+
$this->imagesGenerator->generate([
134+
'image-width' => self::GENERATED_SWATCH_WIDTH,
135+
'image-height' => self::GENERATED_SWATCH_HEIGHT,
136+
'image-name' => $imageName
137+
]);
155138

156-
imagejpeg($image, $absolutePathToMedia . DIRECTORY_SEPARATOR . self::GENERATED_SWATCH_TMP_NAME, 100);
157-
$imagePath = substr($this->swatchHelper->moveImageFromTmp(self::GENERATED_SWATCH_TMP_NAME), 1);
139+
$imagePath = substr($this->swatchHelper->moveImageFromTmp($imageName), 1);
158140
$this->swatchHelper->generateSwatchVariations($imagePath);
159141

160142
return $imagePath;

setup/src/Magento/Setup/Fixtures/AttributeSetsFixture.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@
88

99
/**
1010
* Fixture for Attribute Sets and Attributes based on the configuration
11+
*
12+
* Support the following format:
13+
* <!-- Number of product attribute sets -->
14+
* <product_attribute_sets>{int}</product_attribute_sets>
15+
*
16+
* <!-- Number of attributes per set -->
17+
* <product_attribute_sets_attributes>{int}</product_attribute_sets_attributes>
18+
*
19+
* <!-- Number of values per attribute -->
20+
* <product_attribute_sets_attributes_values>{int}</product_attribute_sets_attributes_values>
21+
*
22+
* @see setup/performance-toolkit/profiles/ce/small.xml
1123
*/
1224
class AttributeSetsFixture extends Fixture
1325
{

0 commit comments

Comments
 (0)