Skip to content

Commit 2a56d98

Browse files
author
Olexandr Lysenko
committed
Merge remote-tracking branch 'origin/develop' into bugfixes
2 parents 1fee018 + fa0ed96 commit 2a56d98

File tree

12 files changed

+256
-5
lines changed

12 files changed

+256
-5
lines changed

app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/ImagesTest.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ protected function createModel()
2424

2525
public function testModifyData()
2626
{
27-
$this->assertSame($this->getSampleData(), $this->getModel()->modifyData($this->getSampleData()));
27+
$this->productMock->expects($this->once())->method('getId')->willReturn(2051);
28+
$actualResult = $this->getModel()->modifyData($this->getSampleData());
29+
$this->assertSame("", $actualResult[2051]['product']['media_gallery']['images'][0]['label']);
2830
}
2931

3032
public function testModifyMeta()
@@ -40,4 +42,24 @@ public function testModifyMeta()
4042

4143
$this->assertSame([], $this->getModel()->modifyMeta($meta));
4244
}
45+
46+
/**
47+
* {@inheritdoc}
48+
*/
49+
protected function getSampleData()
50+
{
51+
return [
52+
2051 => [
53+
'product' => [
54+
'media_gallery' => [
55+
'images' => [
56+
[
57+
'label' => null
58+
]
59+
]
60+
]
61+
]
62+
]
63+
];
64+
}
4365
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,21 @@ public function modifyMeta(array $meta)
5151
*/
5252
public function modifyData(array $data)
5353
{
54+
/** @var \Magento\Catalog\Api\Data\ProductInterface $product */
55+
$product = $this->locator->getProduct();
56+
$modelId = $product->getId();
57+
if (
58+
isset($data[$modelId][self::DATA_SOURCE_DEFAULT]['media_gallery'])
59+
&& !empty($data[$modelId][self::DATA_SOURCE_DEFAULT]['media_gallery'])
60+
&& !empty($data[$modelId][self::DATA_SOURCE_DEFAULT]['media_gallery']['images'])
61+
) {
62+
foreach ($data[$modelId][self::DATA_SOURCE_DEFAULT]['media_gallery']['images'] as $index => $image) {
63+
if (!isset($image['label'])) {
64+
$data[$modelId][self::DATA_SOURCE_DEFAULT]['media_gallery']['images'][$index]['label'] = "";
65+
}
66+
}
67+
};
68+
5469
return $data;
5570
}
5671
}

app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_index.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
<referenceBlock name="page.title">
1818
<action method="setTitleId">
19-
<argument translate="true" name="id" xsi:type="string">order-header</argument>
19+
<argument translate="false" name="id" xsi:type="string">order-header</argument>
2020
</action>
2121
</referenceBlock>
2222
<referenceContainer name="after.body.start">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Test\Block\Adminhtml\Product\Edit\Section;
8+
9+
use Magento\Mtf\Client\Element\SimpleElement;
10+
use Magento\Mtf\Client\Locator;
11+
use Magento\Ui\Test\Block\Adminhtml\Section;
12+
13+
/**
14+
* Class for product gallery block.
15+
*/
16+
class BlockGallery extends Section
17+
{
18+
/**
19+
* Selector for image loader container.
20+
*
21+
* @var string
22+
*/
23+
private $imageLoader = '.image.image-placeholder .file-row';
24+
25+
/**
26+
* Selector for image upload input.
27+
*
28+
* @var string
29+
*/
30+
private $imageUploadInput = '[name="image"]';
31+
32+
/**
33+
* Upload product images.
34+
*
35+
* @param array $data
36+
* @param SimpleElement|null $element
37+
* @return $this
38+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
39+
*/
40+
public function setFieldsData(array $data, SimpleElement $element = null)
41+
{
42+
foreach ($data['image']['value'] as $imageData) {
43+
$uploadElement = $element->find($this->imageUploadInput, Locator::SELECTOR_CSS, 'upload');
44+
$uploadElement->setValue($imageData['file']);
45+
$this->waitForElementNotVisible($this->imageLoader);
46+
}
47+
return $this;
48+
}
49+
}

dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/ProductForm.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
</fields>
144144
</attributes>
145145
<gallery>
146-
<class>\Magento\Ui\Test\Block\Adminhtml\Section</class>
146+
<class>\Magento\Catalog\Test\Block\Adminhtml\Product\Edit\Section\BlockGallery</class>
147147
<selector>[data-index='block_gallery']</selector>
148148
<strategy>css selector</strategy>
149149
</gallery>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Test\Constraint;
8+
9+
/**
10+
* Assert that can save already exist product.
11+
*/
12+
class AssertCanSaveProduct extends \Magento\Mtf\Constraint\AbstractConstraint
13+
{
14+
/**
15+
* Assert that can save already existing product.
16+
*
17+
* @param \Magento\Mtf\Fixture\FixtureInterface $product
18+
* @param \Magento\Catalog\Test\Page\Adminhtml\CatalogProductEdit $catalogProductEdit
19+
* @param \Magento\Catalog\Test\Page\Adminhtml\CatalogProductIndex $catalogProductIndex
20+
* @return void
21+
*/
22+
public function processAssert(
23+
\Magento\Mtf\Fixture\FixtureInterface $product,
24+
\Magento\Catalog\Test\Page\Adminhtml\CatalogProductEdit $catalogProductEdit,
25+
\Magento\Catalog\Test\Page\Adminhtml\CatalogProductIndex $catalogProductIndex
26+
) {
27+
$filter = ['sku' => $product->getSku()];
28+
$catalogProductIndex->open()->getProductGrid()->searchAndOpen($filter);
29+
$catalogProductEdit->getFormPageActions()->save();
30+
31+
\PHPUnit_Framework_Assert::assertNotEmpty(
32+
$catalogProductEdit->getMessagesBlock()->getSuccessMessage(),
33+
'Can\'t save existing product.'
34+
);
35+
}
36+
37+
/**
38+
* Returns a string representation of the object.
39+
*
40+
* @return string
41+
*/
42+
public function toString()
43+
{
44+
return 'Product was saved without errors.';
45+
}
46+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Test\Constraint;
8+
9+
use Magento\Mtf\Fixture\InjectableFixture;
10+
use Magento\Mtf\Constraint\AbstractConstraint;
11+
use Magento\Catalog\Test\Page\Adminhtml\CatalogProductIndex;
12+
13+
class AssertProductHasImageInGrid extends AbstractConstraint
14+
{
15+
/**
16+
* Assert that product image is present in grid.
17+
*
18+
* @param CatalogProductIndex $productGrid
19+
* @param InjectableFixture $product
20+
* @return void
21+
*/
22+
public function processAssert(
23+
CatalogProductIndex $productGrid,
24+
InjectableFixture $product
25+
) {
26+
$filter = ['sku' => $product->getSku()];
27+
$productGrid->open();
28+
$productGrid->getProductGrid()->search($filter);
29+
$src = $productGrid->getProductGrid()->getBaseImageSource();
30+
\PHPUnit_Framework_Assert::assertTrue(
31+
strpos($src, '/placeholder/') === false,
32+
'Product image is not present in product grid when it should be'
33+
);
34+
}
35+
36+
/**
37+
* Returns a string representation of the object.
38+
*
39+
* @return string
40+
*/
41+
public function toString()
42+
{
43+
return 'Product image is displayed in product grid.';
44+
}
45+
}

dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/CatalogProductSimple.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
<field name="gallery" is_required="0" />
3737
<field name="gift_message_available" is_required="0" />
3838
<field name="has_options" is_required="0" />
39-
<field name="image" is_required="0" />
40-
<field name="image_label" is_required="0" />
39+
<field name="image" is_required="0" group="gallery" source="Magento\Catalog\Test\Fixture\Product\Image" />
40+
<field name="image_label" group="gallery" is_required="0" />
4141
<field name="manufacturer" is_required="0" />
4242
<field name="media_gallery" is_required="0" />
4343
<field name="meta_description" is_required="0" group="search-engine-optimization" />
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Test\Fixture\Product;
8+
9+
use Magento\Mtf\Fixture\DataSource;
10+
use Magento\Mtf\Fixture\FixtureFactory;
11+
12+
/**
13+
* Image entity data source.
14+
*/
15+
class Image extends DataSource
16+
{
17+
/**
18+
* Fixture Factory instance.
19+
*
20+
* @var FixtureFactory
21+
*/
22+
private $fixtureFactory;
23+
24+
/**
25+
* Fixture data.
26+
*
27+
* @var array
28+
*/
29+
private $fixtureData;
30+
31+
/**
32+
* @param FixtureFactory $fixtureFactory
33+
* @param array $params
34+
* @param array $data
35+
*/
36+
public function __construct(FixtureFactory $fixtureFactory, array $params, $data = [])
37+
{
38+
$this->fixtureFactory = $fixtureFactory;
39+
$this->params = $params;
40+
$this->fixtureData = $data;
41+
}
42+
43+
/**
44+
* {@inheritdoc}
45+
* @throws \Exception
46+
*/
47+
public function getData($key = null)
48+
{
49+
foreach ($this->fixtureData as &$imageData) {
50+
if (isset($imageData['file']) && file_exists(MTF_TESTS_PATH . $imageData['file'])) {
51+
$imageData['file'] = MTF_TESTS_PATH . $imageData['file'];
52+
} else {
53+
throw new \Exception("Image '{$imageData['file']}'' not found on the server.");
54+
}
55+
}
56+
$this->data = $this->fixtureData;
57+
58+
return parent::getData($key);
59+
}
60+
}

dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/CreateSimpleProductEntityTest.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,5 +509,19 @@
509509
<constraint name="Magento\Catalog\Test\Constraint\AssertProductPage" />
510510
<constraint name="Magento\Catalog\Test\Constraint\AssertProductInCart" />
511511
</variation>
512+
<variation name="CreateSimpleProductEntityWithImageTestVariation1" summary="Create product with image and try to save it again">
513+
<data name="product/data/image/0/file" xsi:type="string">Magento/Catalog/Test/_files/test1.png</data>
514+
<data name="product/data/image/1/file" xsi:type="string">Magento/Catalog/Test/_files/test2.png</data>
515+
<data name="product/data/url_key" xsi:type="string">simple-product-%isolation%</data>
516+
<data name="product/data/name" xsi:type="string">Simple Product %isolation%</data>
517+
<data name="product/data/sku" xsi:type="string">simple_sku_%isolation%</data>
518+
<data name="product/data/price/value" xsi:type="string">10</data>
519+
<data name="product/data/weight" xsi:type="string">50</data>
520+
<data name="tag" xsi:type="string">severity:S1</data>
521+
<data name="product/data/quantity_and_stock_status/qty" xsi:type="string">100</data>
522+
<constraint name="Magento\Catalog\Test\Constraint\AssertProductSaveMessage" />
523+
<constraint name="Magento\Catalog\Test\Constraint\AssertProductHasImageInGrid" />
524+
<constraint name="Magento\Catalog\Test\Constraint\AssertCanSaveProduct" />
525+
</variation>
512526
</testCase>
513527
</config>

0 commit comments

Comments
 (0)