From 3b6a8968441197574f29a3875cadaf8869b38994 Mon Sep 17 00:00:00 2001 From: Stanislav Idolov <sidolov@magento.com> Date: Mon, 7 Nov 2016 08:39:45 +0200 Subject: [PATCH] MAGETWO-59626: Error saving configurable product after disabling child products --- .../Product/Edit/Section/BlockGallery.php | 18 ++++++---- .../Block/Adminhtml/Product/ProductForm.xml | 7 +--- ...CanUpdate.php => AssertCanSaveProduct.php} | 11 +++--- .../Test/Fixture/CatalogProductSimple.xml | 4 +-- .../Catalog/Test/Fixture/Product/Image.php | 35 ++++++++++++++++--- .../Product/CreateSimpleProductEntityTest.xml | 5 ++- 6 files changed, 53 insertions(+), 27 deletions(-) rename dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/{AssertProductCanUpdate.php => AssertCanSaveProduct.php} (80%) 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 index bc1a0ebc4ce..5a7ee7970ea 100644 --- 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 @@ -10,8 +10,16 @@ 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 { + /** + * @var string + */ + private $imageLoader = '.image.image-placeholder .file-row'; + /** * Upload product images * @@ -22,12 +30,10 @@ class BlockGallery extends Section */ public function setFieldsData(array $data, SimpleElement $element = null) { - if (isset($data['image'])) { - foreach ($data['image']['value'] as $imageData) { - $uploadElement = $this->_rootElement->find('[name="image"]', Locator::SELECTOR_CSS, 'upload'); - $uploadElement->setValue($imageData['file']); - $this->waitForElementNotVisible('.image.image-placeholder .file-row'); - } + foreach ($data['image']['value'] as $imageData) { + $uploadElement = $element->find('[name="image"]', 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 b4f2d99385c..3b66164ebe6 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> @@ -223,9 +223,4 @@ <selector>[data-index="related"]</selector> <strategy>css selector</strategy> </related> - <block_gallery> - <class>\Magento\Catalog\Test\Block\Adminhtml\Product\Edit\Section\BlockGallery</class> - <selector>[data-index="block_gallery"]</selector> - <strategy>css selector</strategy> - </block_gallery> </sections> diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductCanUpdate.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCanSaveProduct.php similarity index 80% rename from dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductCanUpdate.php rename to dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCanSaveProduct.php index 24f1f9d7714..6f0dcd09520 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductCanUpdate.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCanSaveProduct.php @@ -7,12 +7,12 @@ namespace Magento\Catalog\Test\Constraint; /** - * Class AssertProductCanUpdate + * Assert that can save already exist product */ -class AssertProductCanUpdate extends \Magento\Mtf\Constraint\AbstractConstraint +class AssertCanSaveProduct extends \Magento\Mtf\Constraint\AbstractConstraint { /** - * Assert that product with image can update without errors. + * Assert that can save already exist product * * @param \Magento\Mtf\Fixture\FixtureInterface $product * @param \Magento\Catalog\Test\Page\Adminhtml\CatalogProductEdit $catalogProductEdit @@ -29,7 +29,8 @@ class AssertProductCanUpdate extends \Magento\Mtf\Constraint\AbstractConstraint $catalogProductEdit->getFormPageActions()->save(); \PHPUnit_Framework_Assert::assertNotEmpty( - $catalogProductEdit->getMessagesBlock()->getSuccessMessage() + $catalogProductEdit->getMessagesBlock()->getSuccessMessage(), + 'Cant save existing product.' ); } @@ -40,6 +41,6 @@ class AssertProductCanUpdate extends \Magento\Mtf\Constraint\AbstractConstraint */ public function toString() { - return 'Product with image was updated without errors.'; + return 'Product was saved without errors.'; } } 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 a4ca27a0c9e..e8ceb1d0889 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" group="block_gallery" source="Magento\Catalog\Test\Fixture\Product\Image" /> - <field name="image_label" group="block_gallery" 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 index 0136c3431fe..ad72a6db4f4 100644 --- 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 @@ -15,21 +15,46 @@ use Magento\Mtf\Fixture\FixtureFactory; class Image extends DataSource { /** - * Image constructor. + * Fixture Factory instance. + * + * @var FixtureFactory + */ + private $fixtureFactory; + + /** + * Fixture data. + * + * @var array + */ + private $fixtureData; + + /** * @param FixtureFactory $fixtureFactory * @param array $params * @param array $data - * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function __construct(FixtureFactory $fixtureFactory, array $params, $data = []) { - foreach ($data as $key => &$imageData) { + $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 { - unset($data[$key]); + throw new \Exception("Image '{$imageData['file']}'' not found on the server."); } } - $this->data = $data; + $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 5e0a61a9c04..9690f409011 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 @@ -500,8 +500,7 @@ <constraint name="Magento\Catalog\Test\Constraint\AssertProductPage" /> <constraint name="Magento\Catalog\Test\Constraint\AssertProductInCart" /> </variation> - <variation name="CreateSimpleProductEntityWithImageTestVariation1"> - <data name="description" xsi:type="string">Create product with image and try to save it again</data> + <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> @@ -512,7 +511,7 @@ <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\AssertProductCanUpdate" /> + <constraint name="Magento\Catalog\Test\Constraint\AssertCanSaveProduct" /> </variation> </testCase> </config> -- GitLab