@@ -45,36 +45,71 @@ class ContextTest extends TestCase
45
45
*/
46
46
private $ authorization ;
47
47
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
+
48
83
protected function setUp (): void
49
84
{
50
- $ pageLayout = $ this ->getMockBuilder (LayoutInterface::class)
85
+ $ this -> pageLayout = $ this ->getMockBuilder (LayoutInterface::class)
51
86
->getMock ();
52
87
$ request = $ this ->getMockBuilder (Http::class)
53
88
->disableOriginalConstructor ()
54
89
->onlyMethods (['getHeader ' ])
55
90
->getMock ();
56
91
$ request ->method ('getHeader ' )->willReturn ('' );
57
- $ buttonProviderFactory =
92
+ $ this -> buttonProviderFactory =
58
93
$ this ->getMockBuilder (ButtonProviderFactory::class)
59
94
->disableOriginalConstructor ()
60
95
->getMock ();
61
- $ actionPoolFactory =
96
+ $ this -> actionPoolFactory =
62
97
$ this ->getMockBuilder (ActionPoolFactory::class)
63
98
->disableOriginalConstructor ()
64
99
->getMock ();
65
100
$ this ->actionPool = $ this ->getMockBuilder (ActionPoolInterface::class)
66
101
->disableOriginalConstructor ()
67
102
->getMockForAbstractClass ();
68
- $ actionPoolFactory ->method ('create ' )->willReturn ($ this ->actionPool );
69
- $ contentTypeFactory =
103
+ $ this -> actionPoolFactory ->method ('create ' )->willReturn ($ this ->actionPool );
104
+ $ this -> contentTypeFactory =
70
105
$ this ->getMockBuilder (ContentTypeFactory::class)
71
106
->disableOriginalConstructor ()
72
107
->getMock ();
73
- $ urlBuilder = $ this ->getMockBuilder (UrlInterface::class)
108
+ $ this -> urlBuilder = $ this ->getMockBuilder (UrlInterface::class)
74
109
->getMock ();
75
- $ processor = $ this ->getMockBuilder (Processor::class)
110
+ $ this -> processor = $ this ->getMockBuilder (Processor::class)
76
111
->getMock ();
77
- $ uiComponentFactory =
112
+ $ this -> uiComponentFactory =
78
113
$ this ->getMockBuilder (UiComponentFactory::class)
79
114
->disableOriginalConstructor ()
80
115
->getMock ();
@@ -86,14 +121,14 @@ protected function setUp(): void
86
121
$ this ->context = $ objectManagerHelper ->getObject (
87
122
Context::class,
88
123
[
89
- 'pageLayout ' => $ pageLayout ,
124
+ 'pageLayout ' => $ this -> pageLayout ,
90
125
'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 ,
97
132
'authorization ' => $ this ->authorization ,
98
133
]
99
134
);
@@ -162,6 +197,60 @@ public function testAddComponentDefinition($components, $expected)
162
197
$ this ->assertEquals ($ expected , $ this ->context ->getComponentsDefinitions ());
163
198
}
164
199
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
+ ['text/html, application/json ' , 'json ' ]
251
+ ];
252
+ }
253
+
165
254
/**
166
255
* @return array
167
256
*/
0 commit comments