12
12
use Magento \Catalog \Model \Category as Category ;
13
13
use Magento \Catalog \Model \ResourceModel \Product as ProductResource ;
14
14
use Magento \Framework \App \Request \Http as HttpRequest ;
15
- use Magento \Framework \Exception \AuthenticationException ;
16
15
use Magento \Framework \Message \MessageInterface ;
17
16
use Magento \Framework \Serialize \Serializer \Json ;
18
17
use Magento \Store \Api \StoreRepositoryInterface ;
@@ -37,19 +36,20 @@ class CategoryTest extends AbstractBackendController
37
36
/** @var StoreRepositoryInterface */
38
37
private $ storeRepository ;
39
38
39
+ /** @var Json */
40
+ private $ json ;
41
+
40
42
/**
41
43
* @inheritdoc
42
- *
43
- * @throws AuthenticationException
44
44
*/
45
45
protected function setUp ()
46
46
{
47
47
parent ::setUp ();
48
-
49
48
/** @var ProductResource $productResource */
50
49
$ this ->productResource = $ this ->_objectManager ->get (ProductResource::class);
51
50
$ this ->categoryRepository = $ this ->_objectManager ->get (CategoryRepositoryInterface::class);
52
51
$ this ->storeRepository = $ this ->_objectManager ->get (StoreRepositoryInterface::class);
52
+ $ this ->json = $ this ->_objectManager ->get (Json::class);
53
53
}
54
54
55
55
/**
@@ -134,6 +134,10 @@ public function testDefaultValueForCategoryUrlPath(): void
134
134
$ this ->dispatch ('backend/catalog/category/save ' );
135
135
$ category = $ this ->categoryRepository ->get ($ categoryId );
136
136
$ this ->assertEquals ($ defaultUrlPath , $ category ->getData ('url_path ' ));
137
+ $ this ->assertSessionMessages (
138
+ $ this ->equalTo ([(string )__ ('You saved the category. ' )]),
139
+ MessageInterface::TYPE_SUCCESS
140
+ );
137
141
}
138
142
139
143
/**
@@ -157,7 +161,7 @@ public function testSaveActionFromProductCreationPage($postData): void
157
161
$ this ->stringContains ('http://localhost/index.php/backend/catalog/category/edit/ ' )
158
162
);
159
163
} else {
160
- $ result = $ this ->_objectManager -> get (Json::class) ->unserialize ($ body );
164
+ $ result = $ this ->json ->unserialize ($ body );
161
165
$ this ->assertArrayHasKey ('messages ' , $ result );
162
166
$ this ->assertFalse ($ result ['error ' ]);
163
167
$ category = $ result ['category ' ];
@@ -445,9 +449,9 @@ public function testMoveAction(
445
449
->setPostValue ('pid ' , $ parentId )
446
450
->setMethod (HttpRequest::METHOD_POST );
447
451
$ this ->dispatch ('backend/catalog/category/move ' );
448
- $ jsonResponse = json_decode ($ this ->getResponse ()->getBody ());
452
+ $ jsonResponse = $ this -> json -> unserialize ($ this ->getResponse ()->getBody ());
449
453
$ this ->assertNotNull ($ jsonResponse );
450
- $ this ->assertEquals ($ error , $ jsonResponse-> error );
454
+ $ this ->assertEquals ($ error , $ jsonResponse[ ' error ' ] );
451
455
}
452
456
453
457
/**
@@ -485,6 +489,10 @@ public function testSaveCategoryWithProductPosition(array $postData): void
485
489
$ this ->getRequest ()->setPostValue ($ postData );
486
490
$ this ->dispatch ('backend/catalog/category/save ' );
487
491
$ newCategoryProductsCount = $ this ->getCategoryProductsCount ();
492
+ $ this ->assertSessionMessages (
493
+ $ this ->equalTo ([(string )__ ('You saved the category. ' )]),
494
+ MessageInterface::TYPE_SUCCESS
495
+ );
488
496
$ this ->assertEquals (
489
497
$ oldCategoryProductsCount ,
490
498
$ newCategoryProductsCount ,
0 commit comments