11
11
use Magento \Catalog \Model \Product ;
12
12
use Magento \Catalog \Api \Data \ProductInterface ;
13
13
use Magento \Framework \App \Request \Http as HttpRequest ;
14
+ use Magento \Framework \Message \MessageInterface ;
14
15
use Magento \TestFramework \TestCase \AbstractBackendController ;
15
16
16
17
/**
@@ -42,17 +43,21 @@ protected function setUp()
42
43
/**
43
44
* Test add simple related, up-sells, cross-sells product
44
45
*
45
- * @dataProvider addRelatedUpSellCrossSellProductsProvider
46
46
* @magentoDataFixture Magento/Catalog/_files/multiple_products.php
47
47
* @magentoDbIsolation enabled
48
48
* @param array $postData
49
49
* @return void
50
50
*/
51
- public function testAddRelatedUpSellCrossSellProducts (array $ postData ): void
51
+ public function testAddRelatedUpSellCrossSellProducts (): void
52
52
{
53
+ $ postData = $ this ->getPostData ();
53
54
$ this ->getRequest ()->setMethod (HttpRequest::METHOD_POST );
54
55
$ this ->getRequest ()->setPostValue ($ postData );
55
56
$ this ->dispatch ('backend/catalog/product/save ' );
57
+ $ this ->assertSessionMessages (
58
+ $ this ->equalTo (['You saved the product. ' ]),
59
+ MessageInterface::TYPE_SUCCESS
60
+ );
56
61
$ product = $ this ->productRepository ->get ('simple ' );
57
62
$ this ->assertEquals (
58
63
$ this ->getExpectedLinks ($ postData ['links ' ]),
@@ -62,34 +67,30 @@ public function testAddRelatedUpSellCrossSellProducts(array $postData): void
62
67
}
63
68
64
69
/**
65
- * Provide test data for testAddRelatedUpSellCrossSellProducts().
70
+ * Get post data for the request
66
71
*
67
72
* @return array
68
73
*/
69
- public function addRelatedUpSellCrossSellProductsProvider (): array
74
+ public function getPostData (): array
70
75
{
71
76
return [
72
- [
73
- 'post_data ' => [
74
- 'product ' => [
75
- 'attribute_set_id ' => '4 ' ,
76
- 'status ' => '1 ' ,
77
- 'name ' => 'Simple Product ' ,
78
- 'sku ' => 'simple ' ,
79
- 'url_key ' => 'simple-product ' ,
80
- ],
81
- 'links ' => [
82
- 'upsell ' => [
83
- ['id ' => '10 ' ],
84
- ],
85
- 'crosssell ' => [
86
- ['id ' => '11 ' ],
87
- ],
88
- 'related ' => [
89
- ['id ' => '12 ' ],
90
- ],
91
- ]
92
- ]
77
+ 'product ' => [
78
+ 'attribute_set_id ' => '4 ' ,
79
+ 'status ' => '1 ' ,
80
+ 'name ' => 'Simple Product ' ,
81
+ 'sku ' => 'simple ' ,
82
+ 'url_key ' => 'simple-product ' ,
83
+ ],
84
+ 'links ' => [
85
+ 'upsell ' => [
86
+ ['id ' => '10 ' ],
87
+ ],
88
+ 'crosssell ' => [
89
+ ['id ' => '11 ' ],
90
+ ],
91
+ 'related ' => [
92
+ ['id ' => '12 ' ],
93
+ ],
93
94
]
94
95
];
95
96
}
@@ -123,23 +124,19 @@ private function getActualLinks(ProductInterface $product): array
123
124
{
124
125
$ actualLinks = [];
125
126
foreach ($ this ->linkTypes as $ linkType ) {
126
- $ products = [];
127
- $ actualLinks [$ linkType ] = [];
127
+ $ ids = [];
128
128
switch ($ linkType ) {
129
129
case 'upsell ' :
130
- $ products = $ product ->getUpSellProducts ();
130
+ $ ids = $ product ->getUpSellProductIds ();
131
131
break ;
132
132
case 'crosssell ' :
133
- $ products = $ product ->getCrossSellProducts ();
133
+ $ ids = $ product ->getCrossSellProductIds ();
134
134
break ;
135
135
case 'related ' :
136
- $ products = $ product ->getRelatedProducts ();
136
+ $ ids = $ product ->getRelatedProductIds ();
137
137
break ;
138
138
}
139
- /** @var ProductInterface|Product $productItem */
140
- foreach ($ products as $ productItem ) {
141
- $ actualLinks [$ linkType ][] = $ productItem ->getId ();
142
- }
139
+ $ actualLinks [$ linkType ] = $ ids ;
143
140
}
144
141
145
142
return $ actualLinks ;
0 commit comments