File tree Expand file tree Collapse file tree 12 files changed +256
-5
lines changed
Test/Unit/Ui/DataProvider/Product/Form/Modifier
Ui/DataProvider/Product/Form/Modifier
Sales/view/adminhtml/layout
dev/tests/functional/tests/app/Magento/Catalog/Test Expand file tree Collapse file tree 12 files changed +256
-5
lines changed Original file line number Diff line number Diff line change @@ -24,7 +24,9 @@ protected function createModel()
24
24
25
25
public function testModifyData ()
26
26
{
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 ' ]);
28
30
}
29
31
30
32
public function testModifyMeta ()
@@ -40,4 +42,24 @@ public function testModifyMeta()
40
42
41
43
$ this ->assertSame ([], $ this ->getModel ()->modifyMeta ($ meta ));
42
44
}
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
+ }
43
65
}
Original file line number Diff line number Diff line change @@ -51,6 +51,21 @@ public function modifyMeta(array $meta)
51
51
*/
52
52
public function modifyData (array $ data )
53
53
{
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
+
54
69
return $ data ;
55
70
}
56
71
}
Original file line number Diff line number Diff line change 16
16
17
17
<referenceBlock name =" page.title" >
18
18
<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 >
20
20
</action >
21
21
</referenceBlock >
22
22
<referenceContainer name =" after.body.start" >
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 143
143
</fields >
144
144
</attributes >
145
145
<gallery >
146
- <class >\Magento\Ui \Test\Block\Adminhtml\Section</class >
146
+ <class >\Magento\Catalog \Test\Block\Adminhtml\Product\Edit\ Section\BlockGallery </class >
147
147
<selector >[data-index='block_gallery']</selector >
148
148
<strategy >css selector</strategy >
149
149
</gallery >
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 36
36
<field name =" gallery" is_required =" 0" />
37
37
<field name =" gift_message_available" is_required =" 0" />
38
38
<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" />
41
41
<field name =" manufacturer" is_required =" 0" />
42
42
<field name =" media_gallery" is_required =" 0" />
43
43
<field name =" meta_description" is_required =" 0" group =" search-engine-optimization" />
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 509
509
<constraint name =" Magento\Catalog\Test\Constraint\AssertProductPage" />
510
510
<constraint name =" Magento\Catalog\Test\Constraint\AssertProductInCart" />
511
511
</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 >
512
526
</testCase >
513
527
</config >
You can’t perform that action at this time.
0 commit comments