@@ -19,6 +19,16 @@ class ContextTest extends \PHPUnit\Framework\TestCase
1919 */
2020 protected $ context ;
2121
22+ /**
23+ * @var \Magento\Framework\View\Element\UiComponent\Control\ActionPoolInterface
24+ */
25+ private $ actionPool ;
26+
27+ /**
28+ * @var \Magento\Framework\AuthorizationInterface
29+ */
30+ private $ authorization ;
31+
2232 protected function setUp ()
2333 {
2434 $ pageLayout = $ this ->getMockBuilder (\Magento \Framework \View \LayoutInterface::class)->getMock ();
@@ -33,6 +43,10 @@ protected function setUp()
3343 $ this ->getMockBuilder (\Magento \Framework \View \Element \UiComponent \Control \ActionPoolFactory::class)
3444 ->disableOriginalConstructor ()
3545 ->getMock ();
46+ $ this ->actionPool = $ this ->getMockBuilder (\Magento \Framework \View \Element \UiComponent \Control \ActionPoolInterface::class)
47+ ->disableOriginalConstructor ()
48+ ->getMock ();
49+ $ actionPoolFactory ->method ('create ' )->willReturn ($ this ->actionPool );
3650 $ contentTypeFactory =
3751 $ this ->getMockBuilder (\Magento \Framework \View \Element \UiComponent \ContentType \ContentTypeFactory::class)
3852 ->disableOriginalConstructor ()
@@ -43,6 +57,9 @@ protected function setUp()
4357 $ this ->getMockBuilder (\Magento \Framework \View \Element \UiComponentFactory::class)
4458 ->disableOriginalConstructor ()
4559 ->getMock ();
60+ $ this ->authorization = $ this ->getMockBuilder (\Magento \Framework \AuthorizationInterface::class)
61+ ->disableOriginalConstructor ()
62+ ->getMock ();
4663
4764 $ objectManagerHelper = new ObjectManagerHelper ($ this );
4865 $ this ->context = $ objectManagerHelper ->getObject (
@@ -55,11 +72,62 @@ protected function setUp()
5572 'contentTypeFactory ' => $ contentTypeFactory ,
5673 'urlBuilder ' => $ urlBuilder ,
5774 'processor ' => $ processor ,
58- 'uiComponentFactory ' => $ uiComponentFactory
75+ 'uiComponentFactory ' => $ uiComponentFactory ,
76+ 'authorization ' => $ this ->authorization ,
5977 ]
6078 );
6179 }
6280
81+ public function testAddButtonWithoutAclResource ()
82+ {
83+ $ component = $ this ->getMockBuilder (\Magento \Framework \View \Element \UiComponentInterface::class)
84+ ->disableOriginalConstructor ()
85+ ->getMock ();
86+
87+ $ this ->actionPool ->expects ($ this ->once ())->method ('add ' );
88+ $ this ->authorization ->expects ($ this ->never ())->method ('isAllowed ' );
89+
90+ $ this ->context ->addButtons ([
91+ 'button_1 ' => [
92+ 'name ' => 'button_1 ' ,
93+ ],
94+ ], $ component );
95+ }
96+
97+ public function testAddButtonWithAclResourceAllowed ()
98+ {
99+ $ component = $ this ->getMockBuilder (\Magento \Framework \View \Element \UiComponentInterface::class)
100+ ->disableOriginalConstructor ()
101+ ->getMock ();
102+
103+ $ this ->actionPool ->expects ($ this ->once ())->method ('add ' );
104+ $ this ->authorization ->expects ($ this ->once ())->method ('isAllowed ' )->willReturn (true );
105+
106+ $ this ->context ->addButtons ([
107+ 'button_1 ' => [
108+ 'name ' => 'button_1 ' ,
109+ 'aclResource ' => 'Magento_Framwork::acl ' ,
110+ ],
111+ ], $ component );
112+ }
113+
114+ public function testAddButtonWithAclResourceDenied ()
115+ {
116+ $ component = $ this ->getMockBuilder (\Magento \Framework \View \Element \UiComponentInterface::class)
117+ ->disableOriginalConstructor ()
118+ ->getMock ();
119+
120+ $ this ->actionPool ->expects ($ this ->never ())->method ('add ' );
121+ $ this ->authorization ->expects ($ this ->once ())->method ('isAllowed ' )->willReturn (false );
122+
123+ $ this ->context ->addButtons ([
124+ 'button_1 ' => [
125+ 'name ' => 'button_1 ' ,
126+ 'aclResource ' => 'Magento_Framwork::acl ' ,
127+ ],
128+ ], $ component );
129+ }
130+
63131 /**
64132 * @dataProvider addComponentDefinitionDataProvider
65133 * @param array $components
0 commit comments