Skip to content

Commit d818488

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-73989' into 2.2-develop-pr102
2 parents 4707b6e + 2799dae commit d818488

File tree

70 files changed

+1101
-738
lines changed

Some content is hidden

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

70 files changed

+1101
-738
lines changed

app/code/Magento/Catalog/Block/Adminhtml/Product/Helper/Form/Gallery/Content.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Magento\Framework\Exception\FileSystemException;
2020
use Magento\Framework\App\ObjectManager;
2121
use Magento\Backend\Block\DataProviders\UploadConfig as ImageUploadConfigDataProvider;
22+
use Magento\MediaStorage\Helper\File\Storage\Database;
2223

2324
class Content extends \Magento\Backend\Block\Widget
2425
{
@@ -47,25 +48,34 @@ class Content extends \Magento\Backend\Block\Widget
4748
*/
4849
private $imageHelper;
4950

51+
/**
52+
* @var Database
53+
*/
54+
private $fileStorageDatabase;
55+
5056
/**
5157
* @param \Magento\Backend\Block\Template\Context $context
5258
* @param \Magento\Framework\Json\EncoderInterface $jsonEncoder
5359
* @param \Magento\Catalog\Model\Product\Media\Config $mediaConfig
5460
* @param array $data
5561
* @param ImageUploadConfigDataProvider $imageUploadConfigDataProvider
62+
* @param Database $fileStorageDatabase
5663
*/
5764
public function __construct(
5865
\Magento\Backend\Block\Template\Context $context,
5966
\Magento\Framework\Json\EncoderInterface $jsonEncoder,
6067
\Magento\Catalog\Model\Product\Media\Config $mediaConfig,
6168
array $data = [],
62-
ImageUploadConfigDataProvider $imageUploadConfigDataProvider = null
69+
ImageUploadConfigDataProvider $imageUploadConfigDataProvider = null,
70+
Database $fileStorageDatabase = null
6371
) {
6472
$this->_jsonEncoder = $jsonEncoder;
6573
$this->_mediaConfig = $mediaConfig;
6674
parent::__construct($context, $data);
6775
$this->imageUploadConfigDataProvider = $imageUploadConfigDataProvider
6876
?: ObjectManager::getInstance()->get(ImageUploadConfigDataProvider::class);
77+
$this->fileStorageDatabase = $fileStorageDatabase
78+
?: ObjectManager::getInstance()->get(Database::class);
6979
}
7080

7181
/**
@@ -153,6 +163,13 @@ public function getImagesJson()
153163
$images = $this->sortImagesByPosition($value['images']);
154164
foreach ($images as &$image) {
155165
$image['url'] = $this->_mediaConfig->getMediaUrl($image['file']);
166+
if ($this->fileStorageDatabase->checkDbUsage() &&
167+
!$mediaDir->isFile($this->_mediaConfig->getMediaPath($image['file']))
168+
) {
169+
$this->fileStorageDatabase->saveFileToFilesystem(
170+
$this->_mediaConfig->getMediaPath($image['file'])
171+
);
172+
}
156173
try {
157174
$fileHandler = $mediaDir->stat($this->_mediaConfig->getMediaPath($image['file']));
158175
$image['size'] = $fileHandler['size'];

app/code/Magento/Catalog/Test/Mftf/Section/StorefrontCategoryProductSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<element name="productPriceOld" type="text" selector="//span[@data-price-type='oldPrice']//span[@class='price'][contains(., '{{var1}}')]" parameterized="true"/>
2525
<element name="productPriceLabel" type="text" selector="//span[@class='price-label'][contains(text(),'{{var1}}')]" parameterized="true"/>
2626
<element name="productPriceLinkAfterLabel" type="text" selector="//span[@class='price-label'][contains(text(),'{{var1}}')]/following::span[contains(text(), '{{var2}}')]" parameterized="true"/>
27+
<element name="productNameInGrid" type="text" selector="//div[contains(@class,'products-grid')]//strong[contains(@class,'product-item-name')]//a[normalize-space(text())='{{productName}}']" parameterized="true"/>
2728
<element name="productStockUnavailableByName" type="text" selector="//a[contains(@class, 'product-item-link') and normalize-space(text())='{{productName}}']/ancestor::div[contains(@class, 'product-item-details')]//span[contains(text(),'Out of stock')]" parameterized="true"/>
2829
</section>
2930
</sections>

app/code/Magento/Catalog/Test/Unit/Block/Adminhtml/Product/Helper/Form/Gallery/ContentTest.php

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Catalog\Model\Entity\Attribute;
1010
use Magento\Catalog\Model\Product;
1111
use Magento\Framework\Phrase;
12+
use Magento\MediaStorage\Helper\File\Storage\Database;
1213

1314
/**
1415
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -50,6 +51,11 @@ class ContentTest extends \PHPUnit\Framework\TestCase
5051
*/
5152
protected $imageHelper;
5253

54+
/**
55+
* @var \Magento\MediaStorage\Helper\File\Storage\Database|\PHPUnit_Framework_MockObject_MockObject
56+
*/
57+
protected $databaseMock;
58+
5359
/**
5460
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
5561
*/
@@ -71,13 +77,18 @@ public function setUp()
7177
->disableOriginalConstructor()
7278
->getMock();
7379

80+
$this->databaseMock = $this->getMockBuilder(Database::class)
81+
->disableOriginalConstructor()
82+
->getMock();
83+
7484
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
7585
$this->content = $this->objectManager->getObject(
7686
\Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Gallery\Content::class,
7787
[
7888
'mediaConfig' => $this->mediaConfigMock,
7989
'jsonEncoder' => $this->jsonEncoderMock,
80-
'filesystem' => $this->fileSystemMock
90+
'filesystem' => $this->fileSystemMock,
91+
'fileStorageDatabase' => $this->databaseMock
8192
]
8293
);
8394
}
@@ -143,6 +154,13 @@ public function testGetImagesJson()
143154
$this->readMock->expects($this->any())->method('stat')->willReturnMap($sizeMap);
144155
$this->jsonEncoderMock->expects($this->once())->method('encode')->willReturnCallback('json_encode');
145156

157+
$this->readMock->expects($this->any())
158+
->method('isFile')
159+
->will($this->returnValue(true));
160+
$this->databaseMock->expects($this->any())
161+
->method('checkDbUsage')
162+
->will($this->returnValue(false));
163+
146164
$this->assertSame(json_encode($imagesResult), $this->content->getImagesJson());
147165
}
148166

@@ -221,6 +239,13 @@ public function testGetImagesJsonWithException()
221239
$this->imageHelper->expects($this->any())->method('getDefaultPlaceholderUrl')->willReturn($placeholderUrl);
222240
$this->jsonEncoderMock->expects($this->once())->method('encode')->willReturnCallback('json_encode');
223241

242+
$this->readMock->expects($this->any())
243+
->method('isFile')
244+
->will($this->returnValue(true));
245+
$this->databaseMock->expects($this->any())
246+
->method('checkDbUsage')
247+
->will($this->returnValue(false));
248+
224249
$this->assertSame(json_encode($imagesResult), $this->content->getImagesJson());
225250
}
226251

@@ -365,4 +390,52 @@ private function getMediaAttribute(string $label, string $attributeCode)
365390

366391
return $mediaAttribute;
367392
}
393+
394+
/**
395+
* Test GetImagesJson() calls MediaStorage functions to obtain image from DB prior to stat call
396+
*
397+
* @return void
398+
*/
399+
public function testGetImagesJsonMediaStorageMode()
400+
{
401+
$images = [
402+
'images' => [
403+
[
404+
'value_id' => '0',
405+
'file' => 'file_1.jpg',
406+
'media_type' => 'image',
407+
'position' => '0'
408+
]
409+
]
410+
];
411+
412+
$mediaPath = [
413+
['file_1.jpg', 'catalog/product/image_1.jpg']
414+
];
415+
416+
$this->content->setElement($this->galleryMock);
417+
418+
$this->galleryMock->expects($this->once())
419+
->method('getImages')
420+
->willReturn($images);
421+
$this->fileSystemMock->expects($this->once())
422+
->method('getDirectoryRead')
423+
->willReturn($this->readMock);
424+
$this->mediaConfigMock->expects($this->any())
425+
->method('getMediaPath')
426+
->willReturnMap($mediaPath);
427+
428+
$this->readMock->expects($this->any())
429+
->method('isFile')
430+
->will($this->returnValue(false));
431+
$this->databaseMock->expects($this->any())
432+
->method('checkDbUsage')
433+
->will($this->returnValue(true));
434+
435+
$this->databaseMock->expects($this->once())
436+
->method('saveFileToFilesystem')
437+
->with('catalog/product/image_1.jpg');
438+
439+
$this->content->getImagesJson();
440+
}
368441
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="AdminAssertQueryLengthHintsActionGroup">
12+
<amOnPage url="{{AdminCatalogSearchConfigurationPage.url('#catalog_search-link')}}" stepKey="navigateToConfigurationPage"/>
13+
<see userInput="{{MinMaxQueryLength.hint}}" selector="{{AdminCatalogSearchConfigurationSection.minQueryLengthHint}}" stepKey="seeMinQueryLengthHint"/>
14+
<see userInput="{{MinMaxQueryLength.hint}}" selector="{{AdminCatalogSearchConfigurationSection.maxQueryLengthHint}}" stepKey="seeMaxQueryLengthHint"/>
15+
</actionGroup>
16+
</actionGroups>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="StorefrontSearchProductActionGroup" extends="StorefrontQuickSearchActionGroup">
12+
<arguments>
13+
<argument name="product"/>
14+
</arguments>
15+
<waitForElementVisible selector="{{StorefrontCategoryProductSection.productNameInGrid(product.name)}}" after="clickSearchButton" stepKey="waitForProductNameElement"/>
16+
<seeElement selector="{{StorefrontCategoryProductSection.productNameInGrid(product.name)}}" stepKey="seeProductNameInCatalogSearchPage"/>
17+
</actionGroup>
18+
</actionGroups>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:DataGenerator/etc/dataProfileSchema.xsd">
11+
<entity name="MinMaxQueryLength" type="constant">
12+
<data key="hint">This value must be compatible with the corresponding setting in the configured search engine</data>
13+
</entity>
14+
</entities>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:DataGenerator/etc/dataProfileSchema.xsd">
11+
<entity name="SetMinQueryLengthToDefault" type="catalog_search_config">
12+
<requiredEntity type="length_config">CheckUseSystemValueCheckbox</requiredEntity>
13+
</entity>
14+
<entity name="SetMinQueryLengthToOne" type="catalog_search_config">
15+
<requiredEntity type="length_config">MinQueryLengthValue1</requiredEntity>
16+
</entity>
17+
<entity name="SetMinQueryLengthToTwo" type="catalog_search_config">
18+
<requiredEntity type="length_config">MinQueryLengthValue2</requiredEntity>
19+
</entity>
20+
21+
<entity name="MinQueryLengthValue1" type="length_config">
22+
<data key="value">1</data>
23+
<requiredEntity type="length_config_inherit">UncheckUseSystemValueCheckbox</requiredEntity>
24+
</entity>
25+
<entity name="MinQueryLengthValue2" type="length_config">
26+
<data key="value">2</data>
27+
<requiredEntity type="length_config_inherit">UncheckUseSystemValueCheckbox</requiredEntity>
28+
</entity>
29+
30+
<entity name="UncheckUseSystemValueCheckbox" type="length_config_inherit">
31+
<data key="value">false</data>
32+
</entity>
33+
<entity name="CheckUseSystemValueCheckbox" type="length_config_inherit">
34+
<data key="inherit">true</data>
35+
</entity>
36+
</entities>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<operations xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:DataGenerator/etc/dataOperation.xsd">
10+
<operation name="CatalogSearchConfig" dataType="catalog_search_config" type="create" auth="adminFormKey" url="/admin/system_config/save/section/catalog/" method="POST" successRegex="/messages-message-success/">
11+
<object key="groups" dataType="catalog_search_config">
12+
<object key="search" dataType="catalog_search_config">
13+
<object key="fields" dataType="catalog_search_config">
14+
<object key="min_query_length" dataType="length_config">
15+
<object key="inherit" dataType="length_config_inherit">
16+
<field key="value">boolean</field>
17+
</object>
18+
<field key="value">integer</field>
19+
</object>
20+
</object>
21+
</object>
22+
</object>
23+
</operation>
24+
</operations>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<pages xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/PageObject.xsd">
9+
<page name="AdminCatalogSearchConfigurationPage" url="admin/system_config/edit/section/catalog/{{tab_anchor}}" area="admin" module="Magento_CatalogSearch" parameterized="true">
10+
<section name="AdminCatalogSearchConfigurationSection"/>
11+
</page>
12+
</pages>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
11+
<section name="AdminCatalogSearchConfigurationSection">
12+
<element name="minQueryLength" type="input" selector="#catalog_search_min_query_length"/>
13+
<element name="minQueryLengthInherit" type="checkbox" selector="#catalog_search_min_query_length_inherit"/>
14+
<element name="minQueryLengthHint" type="text" selector="#row_catalog_search_min_query_length .value span"/>
15+
<element name="maxQueryLengthHint" type="text" selector="#row_catalog_search_max_query_length .value span"/>
16+
</section>
17+
</sections>

0 commit comments

Comments
 (0)