Skip to content

Commit 7a3c79f

Browse files
committed
Added Unit Test for UIComponent Context file
1 parent f9143f0 commit 7a3c79f

File tree

1 file changed

+103
-15
lines changed
  • lib/internal/Magento/Framework/View/Test/Unit/Element/UiComponent

1 file changed

+103
-15
lines changed

lib/internal/Magento/Framework/View/Test/Unit/Element/UiComponent/ContextTest.php

Lines changed: 103 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,36 +45,71 @@ class ContextTest extends TestCase
4545
*/
4646
private $authorization;
4747

48+
/**
49+
* @var LayoutInterface
50+
*/
51+
private $pageLayout;
52+
53+
/**
54+
* @var ButtonProviderFactory
55+
*/
56+
private $buttonProviderFactory;
57+
58+
/**
59+
* @var ActionPoolFactory
60+
*/
61+
private $actionPoolFactory;
62+
63+
/**
64+
* @var ContentTypeFactory
65+
*/
66+
private $contentTypeFactory;
67+
68+
/**
69+
* @var UrlInterface
70+
*/
71+
private $urlBuilder;
72+
73+
/**
74+
* @var Processor
75+
*/
76+
private $processor;
77+
78+
/**
79+
* @var UiComponentFactory
80+
*/
81+
private $uiComponentFactory;
82+
4883
protected function setUp(): void
4984
{
50-
$pageLayout = $this->getMockBuilder(LayoutInterface::class)
85+
$this->pageLayout = $this->getMockBuilder(LayoutInterface::class)
5186
->getMock();
5287
$request = $this->getMockBuilder(Http::class)
5388
->disableOriginalConstructor()
5489
->onlyMethods(['getHeader'])
5590
->getMock();
5691
$request->method('getHeader')->willReturn('');
57-
$buttonProviderFactory =
92+
$this->buttonProviderFactory =
5893
$this->getMockBuilder(ButtonProviderFactory::class)
5994
->disableOriginalConstructor()
6095
->getMock();
61-
$actionPoolFactory =
96+
$this->actionPoolFactory =
6297
$this->getMockBuilder(ActionPoolFactory::class)
6398
->disableOriginalConstructor()
6499
->getMock();
65100
$this->actionPool = $this->getMockBuilder(ActionPoolInterface::class)
66101
->disableOriginalConstructor()
67102
->getMockForAbstractClass();
68-
$actionPoolFactory->method('create')->willReturn($this->actionPool);
69-
$contentTypeFactory =
103+
$this->actionPoolFactory->method('create')->willReturn($this->actionPool);
104+
$this->contentTypeFactory =
70105
$this->getMockBuilder(ContentTypeFactory::class)
71106
->disableOriginalConstructor()
72107
->getMock();
73-
$urlBuilder = $this->getMockBuilder(UrlInterface::class)
108+
$this->urlBuilder = $this->getMockBuilder(UrlInterface::class)
74109
->getMock();
75-
$processor = $this->getMockBuilder(Processor::class)
110+
$this->processor = $this->getMockBuilder(Processor::class)
76111
->getMock();
77-
$uiComponentFactory =
112+
$this->uiComponentFactory =
78113
$this->getMockBuilder(UiComponentFactory::class)
79114
->disableOriginalConstructor()
80115
->getMock();
@@ -86,14 +121,14 @@ protected function setUp(): void
86121
$this->context = $objectManagerHelper->getObject(
87122
Context::class,
88123
[
89-
'pageLayout' => $pageLayout,
124+
'pageLayout' => $this->pageLayout,
90125
'request' => $request,
91-
'buttonProviderFactory' => $buttonProviderFactory,
92-
'actionPoolFactory' => $actionPoolFactory,
93-
'contentTypeFactory' => $contentTypeFactory,
94-
'urlBuilder' => $urlBuilder,
95-
'processor' => $processor,
96-
'uiComponentFactory' => $uiComponentFactory,
126+
'buttonProviderFactory' => $this->buttonProviderFactory,
127+
'actionPoolFactory' => $this->actionPoolFactory,
128+
'contentTypeFactory' => $this->contentTypeFactory,
129+
'urlBuilder' => $this->urlBuilder,
130+
'processor' => $this->processor,
131+
'uiComponentFactory' => $this->uiComponentFactory,
97132
'authorization' => $this->authorization,
98133
]
99134
);
@@ -162,6 +197,59 @@ public function testAddComponentDefinition($components, $expected)
162197
$this->assertEquals($expected, $this->context->getComponentsDefinitions());
163198
}
164199

200+
/**
201+
* @param string $headerAccept
202+
* @param string $acceptType
203+
*
204+
* @dataProvider getAcceptTypeDataProvider
205+
*/
206+
public function testGetAcceptType($headerAccept, $acceptType)
207+
{
208+
$request = $this->getMockBuilder(Http::class)
209+
->disableOriginalConstructor()
210+
->onlyMethods(['getHeader'])
211+
->getMock();
212+
$request->method('getHeader')
213+
->with('Accept')
214+
->willReturn($headerAccept);
215+
216+
$objectManagerHelper = new ObjectManagerHelper($this);
217+
$context = $objectManagerHelper->getObject(
218+
Context::class,
219+
[
220+
'pageLayout' => $this->pageLayout,
221+
'request' => $request,
222+
'buttonProviderFactory' => $this->buttonProviderFactory,
223+
'actionPoolFactory' => $this->actionPoolFactory,
224+
'contentTypeFactory' => $this->contentTypeFactory,
225+
'urlBuilder' => $this->urlBuilder,
226+
'processor' => $this->processor,
227+
'uiComponentFactory' => $this->uiComponentFactory,
228+
'authorization' => $this->authorization,
229+
]
230+
);
231+
232+
$this->assertEquals($acceptType, $context->getAcceptType());
233+
}
234+
235+
/**
236+
* @return array
237+
*/
238+
public function getAcceptTypeDataProvider()
239+
{
240+
return [
241+
['json', 'json'],
242+
['text/html,application/xhtml+xml,application/json;q=0.9,
243+
application/javascript;q=0.9,text/javascript;q=0.9,application/xml;q=0.9,
244+
text/plain;q=0.8,*/*;q=0.7', 'html'],
245+
['application/json, text/javascript, */*;q=0.01', 'json'],
246+
['text/html, application/xhtml+xml, application/xml;q=0.9,
247+
image/avif, image/webp, image/apng, */*;q=0.8,
248+
application/signed-exchange;v=b3;q=0.9', 'html'],
249+
['xml', 'xml']
250+
];
251+
}
252+
165253
/**
166254
* @return array
167255
*/

0 commit comments

Comments
 (0)