8
8
9
9
use Magento \Backend \Model \Auth ;
10
10
use Magento \Catalog \Api \CategoryRepositoryInterface ;
11
+ use Magento \Catalog \Api \Data \CategoryInterface ;
12
+ use Magento \Catalog \Api \Data \CategoryInterfaceFactory ;
11
13
use Magento \Framework \Acl \Builder ;
12
14
use Magento \Framework \Acl \CacheInterface ;
13
15
use Magento \TestFramework \Helper \Bootstrap ;
@@ -40,6 +42,11 @@ class CategoryRepositoryTest extends \PHPUnit_Framework_TestCase
40
42
*/
41
43
private $ aclCache ;
42
44
45
+ /**
46
+ * @var CategoryInterfaceFactory
47
+ */
48
+ private $ categoryFactory ;
49
+
43
50
/**
44
51
* Sets up common objects.
45
52
*
@@ -51,6 +58,8 @@ protected function setUp()
51
58
$ this ->authorization = Bootstrap::getObjectManager ()->get (Auth::class);
52
59
$ this ->aclBuilder = Bootstrap::getObjectManager ()->get (Builder::class);
53
60
$ this ->aclCache = Bootstrap::getObjectManager ()->get (CacheInterface::class);
61
+ $ this ->categoryFactory = Bootstrap::getObjectManager ()->get (CategoryInterfaceFactory::class);
62
+ $ this ->authorization ->login (TestBootstrap::ADMIN_NAME , TestBootstrap::ADMIN_PASSWORD );
54
63
}
55
64
56
65
/**
@@ -67,6 +76,7 @@ protected function tearDown()
67
76
/**
68
77
* Test authorization when saving category's design settings.
69
78
*
79
+ * @return CategoryInterface
70
80
* @magentoDataFixture Magento/Catalog/_files/category.php
71
81
* @magentoAppArea adminhtml
72
82
* @magentoDbIsolation enabled
@@ -75,14 +85,14 @@ protected function tearDown()
75
85
public function testSaveDesign ()
76
86
{
77
87
$ category = $ this ->repository ->get (333 );
78
- $ this ->authorization ->login (TestBootstrap::ADMIN_NAME , TestBootstrap::ADMIN_PASSWORD );
79
88
80
89
//Admin doesn't have access to category's design.
81
90
$ this ->aclBuilder ->getAcl ()->deny (null , 'Magento_Catalog::edit_category_design ' );
82
91
83
92
$ category ->setCustomAttribute ('custom_design ' , 2 );
84
93
$ category = $ this ->repository ->save ($ category );
85
- $ this ->assertEmpty ($ category ->getCustomAttribute ('custom_design ' ));
94
+ $ customDesignAttribute = $ category ->getCustomAttribute ('custom_design ' );
95
+ $ this ->assertTrue (!$ customDesignAttribute || !$ customDesignAttribute ->getValue ());
86
96
87
97
//Admin has access to category' design.
88
98
$ this ->aclBuilder ->getAcl ()
@@ -92,5 +102,32 @@ public function testSaveDesign()
92
102
$ category = $ this ->repository ->save ($ category );
93
103
$ this ->assertNotEmpty ($ category ->getCustomAttribute ('custom_design ' ));
94
104
$ this ->assertEquals (2 , $ category ->getCustomAttribute ('custom_design ' )->getValue ());
105
+
106
+ return $ category ;
107
+ }
108
+
109
+ /**
110
+ * Test authorization when saving category's design settings with restricted permission.
111
+ *
112
+ * @param CategoryInterface $category
113
+ * @return void
114
+ * @magentoAppArea adminhtml
115
+ * @magentoDbIsolation enabled
116
+ * @magentoAppIsolation enabled
117
+ * @depends testSaveDesign
118
+ */
119
+ public function testSaveDesignWithRestrictedPermission (CategoryInterface $ category )
120
+ {
121
+ /** @var CategoryInterface $newCategory */
122
+ $ newCategory = $ this ->categoryFactory ->create ();
123
+ $ newCategory ->setName ('new category without design ' );
124
+ $ newCategory ->setParentId ($ category ->getParentId ());
125
+ $ newCategory ->setIsActive (true );
126
+ $ this ->aclBuilder ->getAcl ()->deny (null , 'Magento_Catalog::edit_category_design ' );
127
+ $ newCategory ->setCustomAttribute ('custom_design ' , 2 );
128
+ $ newCategory = $ this ->repository ->save ($ newCategory );
129
+ $ customDesignAttribute = $ newCategory ->getCustomAttribute ('custom_design ' );
130
+
131
+ $ this ->assertTrue (!$ customDesignAttribute || !$ customDesignAttribute ->getValue ());
95
132
}
96
133
}
0 commit comments