12
12
use Magento \Catalog \Model \Category ;
13
13
use Magento \Cms \Api \GetBlockByIdentifierInterface ;
14
14
use Magento \Framework \Exception \NoSuchEntityException ;
15
+ use Magento \Store \Model \StoreManagerInterface ;
15
16
16
17
/**
17
18
* Test cases for save category controller.
18
19
*
19
20
* @magentoAppArea adminhtml
20
- * @magentoDbIsolation disabled
21
+ * @magentoDbIsolation enabled
21
22
*/
22
23
class SaveCategoryTest extends AbstractSaveCategoryTest
23
24
{
@@ -30,6 +31,9 @@ class SaveCategoryTest extends AbstractSaveCategoryTest
30
31
/** @var string */
31
32
private $ createdCategoryId ;
32
33
34
+ /** @var StoreManagerInterface */
35
+ private $ storeManager ;
36
+
33
37
/**
34
38
* @inheritdoc
35
39
*/
@@ -39,19 +43,22 @@ protected function setUp(): void
39
43
40
44
$ this ->categoryRepository = $ this ->_objectManager ->get (CategoryRepositoryInterface::class);
41
45
$ this ->getBlockByIdentifier = $ this ->_objectManager ->get (GetBlockByIdentifierInterface::class);
46
+ $ this ->storeManager = $ this ->_objectManager ->get (StoreManagerInterface::class);
42
47
}
43
48
44
49
/**
45
50
* @inheritdoc
46
51
*/
47
52
protected function tearDown (): void
48
53
{
49
- try {
50
- $ this ->categoryRepository ->deleteByIdentifier ($ this ->createdCategoryId );
51
- } catch (NoSuchEntityException $ e ) {
52
- //Category already deleted.
54
+ if (!empty ($ this ->createdCategoryId )) {
55
+ try {
56
+ $ this ->categoryRepository ->deleteByIdentifier ($ this ->createdCategoryId );
57
+ } catch (NoSuchEntityException $ e ) {
58
+ //Category already deleted.
59
+ }
60
+ $ this ->createdCategoryId = null ;
53
61
}
54
- $ this ->createdCategoryId = null ;
55
62
56
63
parent ::tearDown ();
57
64
}
@@ -63,15 +70,16 @@ protected function tearDown(): void
63
70
*/
64
71
public function testCreateCategoryWithCmsBlock (): void
65
72
{
66
- $ blockId = $ this ->getBlockByIdentifier ->execute ('fixture_block ' , 1 )->getId ();
73
+ $ storeId = (int )$ this ->storeManager ->getStore ('default ' )->getId ();
74
+ $ blockId = $ this ->getBlockByIdentifier ->execute ('fixture_block ' , $ storeId )->getId ();
67
75
$ postData = [
68
76
CategoryInterface::KEY_NAME => 'Category with cms block ' ,
69
77
CategoryInterface::KEY_IS_ACTIVE => 1 ,
70
78
CategoryInterface::KEY_INCLUDE_IN_MENU => 1 ,
71
79
'display_mode ' => Category::DM_MIXED ,
72
80
'landing_page ' => $ blockId ,
73
- ' available_sort_by ' => 1 ,
74
- 'default_sort_by ' => 1 ,
81
+ CategoryInterface:: KEY_AVAILABLE_SORT_BY => [ ' position ' ] ,
82
+ 'default_sort_by ' => ' position ' ,
75
83
];
76
84
$ responseData = $ this ->performSaveCategoryRequest ($ postData );
77
85
$ this ->assertRequestIsSuccessfullyPerformed ($ responseData );
0 commit comments