18 import(
'lib.pkp.tests.PKPTestCase');
19 import(
'lib.pkp.classes.core.PKPRouter');
20 import(
'lib.pkp.classes.core.PKPRequest');
21 import(
'lib.pkp.classes.plugins.HookRegistry');
22 import(
'classes.core.Application');
23 import(
'lib.pkp.classes.db.DAORegistry');
37 protected function setUp() : void {
54 self::assertSame(
$application, $this->router->getApplication());
64 self::assertSame($dispatcher, $this->router->getDispatcher());
72 self::assertTrue($this->router->supports($this->request));
79 $this->markTestSkipped();
81 self::assertFalse($this->router->isCacheable($this->request));
92 $this->router->getRequestedContextPath($this->request, 2);
100 $_SERVER[
'PATH_INFO'] =
null;
101 self::assertEquals(array(
'index',
'index'),
102 $this->router->getRequestedContextPaths($this->request));
112 $_SERVER[
'PATH_INFO'] =
'/context1/context2/other/path/vars';
113 self::assertEquals(array(
'context1',
'context2'),
114 $this->router->getRequestedContextPaths($this->request));
115 self::assertEquals(
'context1',
116 $this->router->getRequestedContextPath($this->request, 1));
117 self::assertEquals(
'context2',
118 $this->router->getRequestedContextPath($this->request, 2));
120 array(array(
'Router::getRequestedContextPaths', array(array(
'context1',
'context2')))),
130 $_SERVER[
'PATH_INFO'] =
'/context';
131 self::assertEquals(array(
'context',
'index'),
132 $this->router->getRequestedContextPaths($this->request));
140 $_SERVER[
'PATH_INFO'] =
'/context:?#/';
141 self::assertEquals(array(
'context',
'index'),
142 $this->router->getRequestedContextPaths($this->request));
150 $_GET[
'firstContext'] =
null;
151 $_GET[
'secondContext'] =
null;
152 self::assertEquals(array(
'index',
'index'),
153 $this->router->getRequestedContextPaths($this->request));
161 $this->markTestSkipped(
'Plugins (or something) appear to interfere with the expectations of the called hook list test in Travis environment');
164 $_GET[
'firstContext'] =
'context1';
165 $_GET[
'secondContext'] =
'context2';
166 self::assertEquals(array(
'context1',
'context2'),
167 $this->router->getRequestedContextPaths($this->request));
168 self::assertEquals(
'context1',
169 $this->router->getRequestedContextPath($this->request, 1));
170 self::assertEquals(
'context2',
171 $this->router->getRequestedContextPath($this->request, 2));
173 array(array(
'Router::getRequestedContextPaths', array(array(
'context1',
'context2')))),
185 $_GET[
'firstContext'] =
'context';
186 self::assertEquals(array(
'context',
'index'),
187 $this->router->getRequestedContextPaths($this->request));
199 $_SERVER[
'PATH_INFO'] =
'/contextPath';
204 $mockDao = $this->getMockBuilder(get_class($contextDao))
205 ->setMethods(array(
'getByPath'))
212 $expectedResult = $this->getMockBuilder(get_class($contextDao->newDataObject()))->getMock();
213 $mockDao->expects($this->once())
214 ->method(
'getByPath')
215 ->with(
'contextPath')
216 ->will($this->returnValue($expectedResult));
217 $result = $this->router->getContext($this->request, 1);
218 self::assertInstanceOf(
'Context', $result);
219 self::assertEquals($expectedResult, $result);
221 $resultByName = $this->router->getContextByName($this->request,
'someContext');
222 self::assertInstanceOf(
'Context', $resultByName);
223 self::assertEquals($expectedResult, $resultByName);
233 $_SERVER[
'PATH_INFO'] =
'/';
235 $result = $this->router->getContext($this->request, 1);
236 self::assertNull($result);
238 $resultByName = $this->router->getContextByName($this->request,
'someContext');
239 self::assertNull($resultByName);
249 'SERVER_NAME' =>
'mydomain.org',
250 'SCRIPT_NAME' =>
'/base/index.php'
254 self::assertEquals(
'http://mydomain.org/base/index.php', $this->router->getIndexUrl($this->request));
259 array(
'Request::getServerHost', array(
'mydomain.org',
false,
true)),
260 array(
'Request::getProtocol', array(
'http')),
261 array(
'Request::getBasePath', array(
'/base')),
262 array(
'Request::getBaseUrl', array(
'http://mydomain.org/base')),
263 array(
'Router::getIndexUrl' , array(
'http://mydomain.org/base/index.php'))
271 self::assertEquals(
'http://mydomain.org/base/index.php', $this->router->getIndexUrl($this->request));
285 'SERVER_NAME' =>
'mydomain.org',
286 'SCRIPT_NAME' =>
'/base/index.php'
289 self::assertEquals(
'http://mydomain.org/base', $this->router->getIndexUrl($this->request));
301 $contextDepth = 2, $contextList = array(
'firstContext',
'secondContext')) {
303 $mockApplication = $this->getMockBuilder(Application::class)
304 ->setMethods(array(
'getContextDepth',
'getContextList'))
308 $mockApplication->expects($this->any())
309 ->method(
'getContextDepth')
310 ->will($this->returnValue($contextDepth));
313 $mockApplication->expects($this->any())
314 ->method(
'getContextList')
315 ->will($this->returnValue($contextList));
317 $this->router->setApplication($mockApplication);
321 $dispatcher = $mockApplication->getDispatcher();
322 $this->router->setDispatcher($dispatcher);
325 $this->request = $this->getMockBuilder(PKPRequest::class)
326 ->setMethods(array(
'isPathInfoEnabled'))
328 $this->request->setRouter($this->router);
329 $this->request->expects($this->any())
330 ->method(
'isPathInfoEnabled')
331 ->will($this->returnValue($pathInfoEnabled));
333 return $mockApplication;
346 protected function _setUpMockDAOs($firstContextPath =
'current-context1', $secondContextPath =
'current-context2', $firstContextIsNull =
false, $secondContextIsNull =
false) {
349 $contextClassName = get_class($contextDao->newDataObject());
350 $mockFirstContextDao = $this->getMockBuilder(get_class($contextDao))
351 ->setMethods(array(
'getByPath'))
353 if (!$firstContextIsNull) {
354 $firstContextInstance = $this->getMockBuilder($contextClassName)
355 ->setMethods(array(
'getPath',
'getSetting'))
357 $firstContextInstance->expects($this->any())
359 ->will($this->returnValue($firstContextPath));
360 $firstContextInstance->expects($this->any())
361 ->method(
'getSetting')
362 ->will($this->returnValue(
null));
363 $mockFirstContextDao->expects($this->any())
364 ->method(
'getByPath')
365 ->with($firstContextPath)
366 ->will($this->returnValue($firstContextInstance));
370 $mockSecondContextDao = $this->getMockBuilder($contextClassName)
371 ->setMethods(array(
'getByPath'))
373 if (!$secondContextIsNull) {
374 $secondContextInstance = $this->getMockBuilder($contextClassName)
375 ->setMethods(array(
'getPath'))
377 $secondContextInstance->expects($this->any())
379 ->will($this->returnValue($secondContextPath));
380 $mockSecondContextDao->expects($this->any())
381 ->method(
'getByPath')
382 ->with($secondContextPath)
383 ->will($this->returnValue($secondContextInstance));