1111
1212use Magento \Framework \View \Element \UiComponent \Context ;
1313use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
14+ use Magento \Framework \View \Element \UiComponent \Control \ActionPoolInterface ;
1415
16+ /**
17+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
18+ */
1519class ContextTest extends \PHPUnit \Framework \TestCase
1620{
1721 /**
1822 * @var Context
1923 */
2024 protected $ context ;
2125
26+ /**
27+ * @var ActionPoolInterface
28+ */
29+ private $ actionPool ;
30+
31+ /**
32+ * @var \Magento\Framework\AuthorizationInterface
33+ */
34+ private $ authorization ;
35+
2236 protected function setUp ()
2337 {
2438 $ pageLayout = $ this ->getMockBuilder (\Magento \Framework \View \LayoutInterface::class)->getMock ();
@@ -33,6 +47,10 @@ protected function setUp()
3347 $ this ->getMockBuilder (\Magento \Framework \View \Element \UiComponent \Control \ActionPoolFactory::class)
3448 ->disableOriginalConstructor ()
3549 ->getMock ();
50+ $ this ->actionPool = $ this ->getMockBuilder (ActionPoolInterface::class)
51+ ->disableOriginalConstructor ()
52+ ->getMock ();
53+ $ actionPoolFactory ->method ('create ' )->willReturn ($ this ->actionPool );
3654 $ contentTypeFactory =
3755 $ this ->getMockBuilder (\Magento \Framework \View \Element \UiComponent \ContentType \ContentTypeFactory::class)
3856 ->disableOriginalConstructor ()
@@ -43,6 +61,9 @@ protected function setUp()
4361 $ this ->getMockBuilder (\Magento \Framework \View \Element \UiComponentFactory::class)
4462 ->disableOriginalConstructor ()
4563 ->getMock ();
64+ $ this ->authorization = $ this ->getMockBuilder (\Magento \Framework \AuthorizationInterface::class)
65+ ->disableOriginalConstructor ()
66+ ->getMock ();
4667
4768 $ objectManagerHelper = new ObjectManagerHelper ($ this );
4869 $ this ->context = $ objectManagerHelper ->getObject (
@@ -55,11 +76,62 @@ protected function setUp()
5576 'contentTypeFactory ' => $ contentTypeFactory ,
5677 'urlBuilder ' => $ urlBuilder ,
5778 'processor ' => $ processor ,
58- 'uiComponentFactory ' => $ uiComponentFactory
79+ 'uiComponentFactory ' => $ uiComponentFactory ,
80+ 'authorization ' => $ this ->authorization ,
5981 ]
6082 );
6183 }
6284
85+ public function testAddButtonWithoutAclResource ()
86+ {
87+ $ component = $ this ->getMockBuilder (\Magento \Framework \View \Element \UiComponentInterface::class)
88+ ->disableOriginalConstructor ()
89+ ->getMock ();
90+
91+ $ this ->actionPool ->expects ($ this ->once ())->method ('add ' );
92+ $ this ->authorization ->expects ($ this ->never ())->method ('isAllowed ' );
93+
94+ $ this ->context ->addButtons ([
95+ 'button_1 ' => [
96+ 'name ' => 'button_1 ' ,
97+ ],
98+ ], $ component );
99+ }
100+
101+ public function testAddButtonWithAclResourceAllowed ()
102+ {
103+ $ component = $ this ->getMockBuilder (\Magento \Framework \View \Element \UiComponentInterface::class)
104+ ->disableOriginalConstructor ()
105+ ->getMock ();
106+
107+ $ this ->actionPool ->expects ($ this ->once ())->method ('add ' );
108+ $ this ->authorization ->expects ($ this ->once ())->method ('isAllowed ' )->willReturn (true );
109+
110+ $ this ->context ->addButtons ([
111+ 'button_1 ' => [
112+ 'name ' => 'button_1 ' ,
113+ 'aclResource ' => 'Magento_Framwork::acl ' ,
114+ ],
115+ ], $ component );
116+ }
117+
118+ public function testAddButtonWithAclResourceDenied ()
119+ {
120+ $ component = $ this ->getMockBuilder (\Magento \Framework \View \Element \UiComponentInterface::class)
121+ ->disableOriginalConstructor ()
122+ ->getMock ();
123+
124+ $ this ->actionPool ->expects ($ this ->never ())->method ('add ' );
125+ $ this ->authorization ->expects ($ this ->once ())->method ('isAllowed ' )->willReturn (false );
126+
127+ $ this ->context ->addButtons ([
128+ 'button_1 ' => [
129+ 'name ' => 'button_1 ' ,
130+ 'aclResource ' => 'Magento_Framwork::acl ' ,
131+ ],
132+ ], $ component );
133+ }
134+
63135 /**
64136 * @dataProvider addComponentDefinitionDataProvider
65137 * @param array $components
0 commit comments