diff --git a/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/ImagesTest.php b/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/ImagesTest.php index 2172e184a9a2ed400d80eb89314855c69fb2c7c1..7a55bd31e3deef64ddeaf5b452cc1b7eb389517c 100644 --- a/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/ImagesTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/ImagesTest.php @@ -24,7 +24,9 @@ class ImagesTest extends AbstractModifierTest public function testModifyData() { - $this->assertSame($this->getSampleData(), $this->getModel()->modifyData($this->getSampleData())); + $this->productMock->expects($this->once())->method('getId')->willReturn(2051); + $actualResult = $this->getModel()->modifyData($this->getSampleData()); + $this->assertSame("", $actualResult[2051]['product']['media_gallery']['images'][0]['label']); } public function testModifyMeta() @@ -40,4 +42,24 @@ class ImagesTest extends AbstractModifierTest $this->assertSame([], $this->getModel()->modifyMeta($meta)); } + + /** + * {@inheritdoc} + */ + protected function getSampleData() + { + return [ + 2051 => [ + 'product' => [ + 'media_gallery' => [ + 'images' => [ + [ + 'label' => null + ] + ] + ] + ] + ] + ]; + } } diff --git a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Images.php b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Images.php index 810a06df4a42f76392ee54525eb5bf6ffc5f489f..a8536cacc79668797ac961e1082c7b8c0f020e76 100644 --- a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Images.php +++ b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Images.php @@ -51,6 +51,21 @@ class Images extends AbstractModifier */ public function modifyData(array $data) { + /** @var \Magento\Catalog\Api\Data\ProductInterface $product */ + $product = $this->locator->getProduct(); + $modelId = $product->getId(); + if ( + isset($data[$modelId][self::DATA_SOURCE_DEFAULT]['media_gallery']) + && !empty($data[$modelId][self::DATA_SOURCE_DEFAULT]['media_gallery']) + && !empty($data[$modelId][self::DATA_SOURCE_DEFAULT]['media_gallery']['images']) + ) { + foreach ($data[$modelId][self::DATA_SOURCE_DEFAULT]['media_gallery']['images'] as $index => $image) { + if (!isset($image['label'])) { + $data[$modelId][self::DATA_SOURCE_DEFAULT]['media_gallery']['images'][$index]['label'] = ""; + } + } + }; + return $data; } } diff --git a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_index.xml b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_index.xml index b2e779e330fe0582f855f17ee57e6f648f61a001..6acb23ab0910ea3e8dc1e8bd5e87c28900e19da5 100644 --- a/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_index.xml +++ b/app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_index.xml @@ -16,7 +16,7 @@ <referenceBlock name="page.title"> <action method="setTitleId"> - <argument translate="true" name="id" xsi:type="string">order-header</argument> + <argument translate="false" name="id" xsi:type="string">order-header</argument> </action> </referenceBlock> <referenceContainer name="after.body.start"> diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Edit/Section/BlockGallery.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Edit/Section/BlockGallery.php new file mode 100644 index 0000000000000000000000000000000000000000..bc0d0b87f24bba19d2e249fa37be7e59e16cca92 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Edit/Section/BlockGallery.php @@ -0,0 +1,49 @@ +<?php +/** + * Copyright © 2016 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Catalog\Test\Block\Adminhtml\Product\Edit\Section; + +use Magento\Mtf\Client\Element\SimpleElement; +use Magento\Mtf\Client\Locator; +use Magento\Ui\Test\Block\Adminhtml\Section; + +/** + * Class for product gallery block. + */ +class BlockGallery extends Section +{ + /** + * Selector for image loader container. + * + * @var string + */ + private $imageLoader = '.image.image-placeholder .file-row'; + + /** + * Selector for image upload input. + * + * @var string + */ + private $imageUploadInput = '[name="image"]'; + + /** + * Upload product images. + * + * @param array $data + * @param SimpleElement|null $element + * @return $this + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function setFieldsData(array $data, SimpleElement $element = null) + { + foreach ($data['image']['value'] as $imageData) { + $uploadElement = $element->find($this->imageUploadInput, Locator::SELECTOR_CSS, 'upload'); + $uploadElement->setValue($imageData['file']); + $this->waitForElementNotVisible($this->imageLoader); + } + return $this; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/ProductForm.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/ProductForm.xml index 407b5c9cb20a3b2097ea87e9d1f5a8240e5566b2..3b66164ebe658097e05fdba2e8b53c6cb3d643d2 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/ProductForm.xml +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/ProductForm.xml @@ -143,7 +143,7 @@ </fields> </attributes> <gallery> - <class>\Magento\Ui\Test\Block\Adminhtml\Section</class> + <class>\Magento\Catalog\Test\Block\Adminhtml\Product\Edit\Section\BlockGallery</class> <selector>[data-index='block_gallery']</selector> <strategy>css selector</strategy> </gallery> diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCanSaveProduct.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCanSaveProduct.php new file mode 100644 index 0000000000000000000000000000000000000000..04e1c034b3db77a49a583ee819f9b8d97cb440ba --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCanSaveProduct.php @@ -0,0 +1,46 @@ +<?php +/** + * Copyright © 2016 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Catalog\Test\Constraint; + +/** + * Assert that can save already exist product. + */ +class AssertCanSaveProduct extends \Magento\Mtf\Constraint\AbstractConstraint +{ + /** + * Assert that can save already existing product. + * + * @param \Magento\Mtf\Fixture\FixtureInterface $product + * @param \Magento\Catalog\Test\Page\Adminhtml\CatalogProductEdit $catalogProductEdit + * @param \Magento\Catalog\Test\Page\Adminhtml\CatalogProductIndex $catalogProductIndex + * @return void + */ + public function processAssert( + \Magento\Mtf\Fixture\FixtureInterface $product, + \Magento\Catalog\Test\Page\Adminhtml\CatalogProductEdit $catalogProductEdit, + \Magento\Catalog\Test\Page\Adminhtml\CatalogProductIndex $catalogProductIndex + ) { + $filter = ['sku' => $product->getSku()]; + $catalogProductIndex->open()->getProductGrid()->searchAndOpen($filter); + $catalogProductEdit->getFormPageActions()->save(); + + \PHPUnit_Framework_Assert::assertNotEmpty( + $catalogProductEdit->getMessagesBlock()->getSuccessMessage(), + 'Can\'t save existing product.' + ); + } + + /** + * Returns a string representation of the object. + * + * @return string + */ + public function toString() + { + return 'Product was saved without errors.'; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductHasImageInGrid.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductHasImageInGrid.php new file mode 100644 index 0000000000000000000000000000000000000000..fed3b36c08d661bbc0297b6f87d08aa692d3c04e --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductHasImageInGrid.php @@ -0,0 +1,45 @@ +<?php +/** + * Copyright © 2016 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Catalog\Test\Constraint; + +use Magento\Mtf\Fixture\InjectableFixture; +use Magento\Mtf\Constraint\AbstractConstraint; +use Magento\Catalog\Test\Page\Adminhtml\CatalogProductIndex; + +class AssertProductHasImageInGrid extends AbstractConstraint +{ + /** + * Assert that product image is present in grid. + * + * @param CatalogProductIndex $productGrid + * @param InjectableFixture $product + * @return void + */ + public function processAssert( + CatalogProductIndex $productGrid, + InjectableFixture $product + ) { + $filter = ['sku' => $product->getSku()]; + $productGrid->open(); + $productGrid->getProductGrid()->search($filter); + $src = $productGrid->getProductGrid()->getBaseImageSource(); + \PHPUnit_Framework_Assert::assertTrue( + strpos($src, '/placeholder/') === false, + 'Product image is not present in product grid when it should be' + ); + } + + /** + * Returns a string representation of the object. + * + * @return string + */ + public function toString() + { + return 'Product image is displayed in product grid.'; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/CatalogProductSimple.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/CatalogProductSimple.xml index b4514208a509358a6828a7b77d33ca0c2678072a..e8ceb1d0889247805746a401f6c60bb5a0556010 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/CatalogProductSimple.xml +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/CatalogProductSimple.xml @@ -36,8 +36,8 @@ <field name="gallery" is_required="0" /> <field name="gift_message_available" is_required="0" /> <field name="has_options" is_required="0" /> - <field name="image" is_required="0" /> - <field name="image_label" is_required="0" /> + <field name="image" is_required="0" group="gallery" source="Magento\Catalog\Test\Fixture\Product\Image" /> + <field name="image_label" group="gallery" is_required="0" /> <field name="manufacturer" is_required="0" /> <field name="media_gallery" is_required="0" /> <field name="meta_description" is_required="0" group="search-engine-optimization" /> diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Product/Image.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Product/Image.php new file mode 100644 index 0000000000000000000000000000000000000000..ad72a6db4f4cef615f4abb7edddc497886a73981 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Product/Image.php @@ -0,0 +1,60 @@ +<?php +/** + * Copyright © 2016 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Catalog\Test\Fixture\Product; + +use Magento\Mtf\Fixture\DataSource; +use Magento\Mtf\Fixture\FixtureFactory; + +/** + * Image entity data source. + */ +class Image extends DataSource +{ + /** + * Fixture Factory instance. + * + * @var FixtureFactory + */ + private $fixtureFactory; + + /** + * Fixture data. + * + * @var array + */ + private $fixtureData; + + /** + * @param FixtureFactory $fixtureFactory + * @param array $params + * @param array $data + */ + public function __construct(FixtureFactory $fixtureFactory, array $params, $data = []) + { + $this->fixtureFactory = $fixtureFactory; + $this->params = $params; + $this->fixtureData = $data; + } + + /** + * {@inheritdoc} + * @throws \Exception + */ + public function getData($key = null) + { + foreach ($this->fixtureData as &$imageData) { + if (isset($imageData['file']) && file_exists(MTF_TESTS_PATH . $imageData['file'])) { + $imageData['file'] = MTF_TESTS_PATH . $imageData['file']; + } else { + throw new \Exception("Image '{$imageData['file']}'' not found on the server."); + } + } + $this->data = $this->fixtureData; + + return parent::getData($key); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/CreateSimpleProductEntityTest.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/CreateSimpleProductEntityTest.xml index d9ef9f0b0420d6545718bae78b006417f7684b33..9f4a5e4bb71fea9293612125157757f7e3d965da 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/CreateSimpleProductEntityTest.xml +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/CreateSimpleProductEntityTest.xml @@ -509,5 +509,19 @@ <constraint name="Magento\Catalog\Test\Constraint\AssertProductPage" /> <constraint name="Magento\Catalog\Test\Constraint\AssertProductInCart" /> </variation> + <variation name="CreateSimpleProductEntityWithImageTestVariation1" summary="Create product with image and try to save it again"> + <data name="product/data/image/0/file" xsi:type="string">Magento/Catalog/Test/_files/test1.png</data> + <data name="product/data/image/1/file" xsi:type="string">Magento/Catalog/Test/_files/test2.png</data> + <data name="product/data/url_key" xsi:type="string">simple-product-%isolation%</data> + <data name="product/data/name" xsi:type="string">Simple Product %isolation%</data> + <data name="product/data/sku" xsi:type="string">simple_sku_%isolation%</data> + <data name="product/data/price/value" xsi:type="string">10</data> + <data name="product/data/weight" xsi:type="string">50</data> + <data name="tag" xsi:type="string">severity:S1</data> + <data name="product/data/quantity_and_stock_status/qty" xsi:type="string">100</data> + <constraint name="Magento\Catalog\Test\Constraint\AssertProductSaveMessage" /> + <constraint name="Magento\Catalog\Test\Constraint\AssertProductHasImageInGrid" /> + <constraint name="Magento\Catalog\Test\Constraint\AssertCanSaveProduct" /> + </variation> </testCase> </config> diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/_files/test1.png b/dev/tests/functional/tests/app/Magento/Catalog/Test/_files/test1.png new file mode 100644 index 0000000000000000000000000000000000000000..3077df38da2ffab3378a630914803dfad59e7961 Binary files /dev/null and b/dev/tests/functional/tests/app/Magento/Catalog/Test/_files/test1.png differ diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/_files/test2.png b/dev/tests/functional/tests/app/Magento/Catalog/Test/_files/test2.png new file mode 100644 index 0000000000000000000000000000000000000000..3d219e6ee734b983a39e041a2386117a10d762be Binary files /dev/null and b/dev/tests/functional/tests/app/Magento/Catalog/Test/_files/test2.png differ