18 require_mock_env(
'env1');
20 import(
'lib.pkp.classes.core.PKPPageRouter');
21 import(
'lib.pkp.tests.classes.core.PKPRouterTestCase');
22 import(
'classes.security.Validation');
23 import(
'classes.i18n.AppLocale');
29 protected function setUp() : void {
31 $this->router = $this->getMockBuilder(PKPPageRouter::class)
32 ->setMethods(array(
'getCacheablePages'))
34 $this->router->expects($this->any())
35 ->method(
'getCacheablePages')
36 ->will($this->returnValue(array(
'cacheable')));
45 self::assertFalse($this->router->isCacheable($this->request));
54 $_POST = array(
'somevar' =>
'someval');
55 self::assertFalse($this->router->isCacheable($this->request));
64 $_GET = array(
'somevar' =>
'someval');
66 'PATH_INFO' =>
'/context1/context2/somepage',
67 'SCRIPT_NAME' =>
'/index.php',
69 self::assertFalse($this->router->isCacheable($this->request));
72 self::assertFalse($this->router->isCacheable($this->request));
86 'PATH_INFO' =>
'/context1/context2/cacheable',
87 'SCRIPT_NAME' =>
'/index.php',
90 self::assertTrue($this->router->isCacheable($this->request,
true));
93 self::assertFalse($this->router->isCacheable($this->request,
true));
103 $_GET = array(
'somevar' =>
'someval');
104 self::assertFalse($this->router->isCacheable($this->request,
true));
107 'firstContext' =>
'something',
108 'secondContext' =>
'something',
109 'page' =>
'something',
111 'path' =>
'something'
113 self::assertFalse($this->router->isCacheable($this->request,
true));
126 'page' =>
'cacheable'
128 self::assertTrue($this->router->isCacheable($this->request,
true));
136 $this->markTestSkipped();
145 'PATH_INFO' =>
'/context1/context2/index',
146 'SCRIPT_NAME' =>
'/index.php',
148 $expectedId =
'/context1/context2/index-en_US';
149 self::assertEquals(
Core::getBaseDir().
'/cache/wc-'.md5($expectedId).
'.html', $this->router->getCacheFilename($this->request));
158 'firstContext' =>
'something',
159 'secondContext' =>
'something',
162 $expectedId =
'something-something-index---en_US';
163 self::assertEquals(
Core::getBaseDir().
'/cache/wc-'.md5($expectedId).
'.html', $this->router->getCacheFilename($this->request));
173 'PATH_INFO' =>
'/context1/context2/some#page',
174 'SCRIPT_NAME' =>
'/index.php',
176 self::assertEquals(
'somepage', $this->router->getRequestedPage($this->request));
185 $_GET[
'page'] =
'some#page';
186 self::assertEquals(
'somepage', $this->router->getRequestedPage($this->request));
196 'PATH_INFO' =>
'/context1/context2',
197 'SCRIPT_NAME' =>
'/index.php',
199 self::assertEquals(
'', $this->router->getRequestedPage($this->request));
208 unset($_GET[
'page']);
209 self::assertEquals(
'', $this->router->getRequestedPage($this->request));
219 'PATH_INFO' =>
'/context1/context2/somepage/some#op',
220 'SCRIPT_NAME' =>
'/index.php',
222 self::assertEquals(
'someop', $this->router->getRequestedOp($this->request));
231 $_GET[
'op'] =
'some#op';
232 self::assertEquals(
'someop', $this->router->getRequestedOp($this->request));
242 'PATH_INFO' =>
'/context1/context2/somepage',
243 'SCRIPT_NAME' =>
'/index.php',
245 self::assertEquals(
'index', $this->router->getRequestedOp($this->request));
255 self::assertEquals(
'index', $this->router->getRequestedOp($this->request));
265 'SERVER_NAME' =>
'mydomain.org',
266 'SCRIPT_NAME' =>
'/index.php',
267 'PATH_INFO' =>
'/current-context1/current-context2/current-page/current-op'
273 $result = $this->router->url($this->request);
274 self::assertEquals(
'http://mydomain.org/index.php/current-context1/current-context2/current-page/current-op', $result);
276 $result = $this->router->url($this->request,
'new-context1');
277 self::assertEquals(
'http://mydomain.org/index.php/new-context1/current-context2', $result);
279 $result = $this->router->url($this->request, array(
'new-context1',
'new?context2'));
280 self::assertEquals(
'http://mydomain.org/index.php/new-context1/new%3Fcontext2', $result);
282 $result = $this->router->url($this->request, array(),
'new-page');
283 self::assertEquals(
'http://mydomain.org/index.php/current-context1/current-context2/new-page', $result);
285 $result = $this->router->url($this->request, array(),
null,
'new-op');
286 self::assertEquals(
'http://mydomain.org/index.php/current-context1/current-context2/current-page/new-op', $result);
288 $result = $this->router->url($this->request,
'new-context1',
'new-page');
289 self::assertEquals(
'http://mydomain.org/index.php/new-context1/current-context2/new-page', $result);
291 $result = $this->router->url($this->request,
'new-context1',
'new-page',
'new-op');
292 self::assertEquals(
'http://mydomain.org/index.php/new-context1/current-context2/new-page/new-op', $result);
294 $result = $this->router->url($this->request,
'new-context1',
null,
'new-op');
295 self::assertEquals(
'http://mydomain.org/index.php/new-context1/current-context2/index/new-op', $result);
297 $result = $this->router->url($this->request,
'new-context1',
null,
null,
'add?path');
298 self::assertEquals(
'http://mydomain.org/index.php/new-context1/current-context2/index/index/add%3Fpath', $result);
300 $result = $this->router->url($this->request,
'new-context1',
null,
null, array(
'add-path1',
'add?path2'));
301 self::assertEquals(
'http://mydomain.org/index.php/new-context1/current-context2/index/index/add-path1/add%3Fpath2', $result);
303 $result = $this->router->url($this->request, array(
'firstContext' =>
null,
'secondContext' =>
null),
null,
'new-op',
'add-path');
304 self::assertEquals(
'http://mydomain.org/index.php/current-context1/current-context2/current-page/new-op/add-path', $result);
306 $result = $this->router->url($this->request,
'new-context1',
null,
null,
null,
309 'key2' => array(
'val2-1',
'val2?2')
312 self::assertEquals(
'http://mydomain.org/index.php/new-context1/current-context2?key1=val1%3F&key2[]=val2-1&key2[]=val2%3F2', $result);
314 $result = $this->router->url($this->request,
'new-context1',
null,
null,
null,
null,
'some?anchor');
315 self::assertEquals(
'http://mydomain.org/index.php/new-context1/current-context2#some%3Fanchor', $result);
317 $result = $this->router->url($this->request,
'new-context1',
null,
'new-op',
'add-path', array(
'key' =>
'val'),
'some-anchor');
318 self::assertEquals(
'http://mydomain.org/index.php/new-context1/current-context2/index/new-op/add-path?key=val#some-anchor', $result);
320 $result = $this->router->url($this->request,
'new-context1',
null,
null,
null, array(
'key1' =>
'val1',
'key2' =>
'val2'),
null,
true);
321 self::assertEquals(
'http://mydomain.org/index.php/new-context1/current-context2?key1=val1&key2=val2', $result);
333 'SERVER_NAME' =>
'mydomain.org',
334 'SCRIPT_NAME' =>
'/index.php',
335 'PATH_INFO' =>
'/overridden-context/current-context2/current-page/current-op'
338 $result = $this->router->url($this->request);
339 self::assertEquals(
'http://some-domain/xyz-context/current-context2/current-page/current-op', $result);
353 'SERVER_NAME' =>
'mydomain.org',
354 'SCRIPT_NAME' =>
'/index.php',
355 'PATH_INFO' =>
'/current-context1/current-context2/current-page/current-op'
357 $this->
_setUpMockDAOs(
'current-context1',
'current-context2',
true);
358 $result = $this->router->url($this->request,
'overridden-context',
'new-page');
359 self::assertEquals(
'http://some-domain/xyz-context/current-context2/new-page', $result);
368 'SERVER_NAME' =>
'mydomain.org',
369 'SCRIPT_NAME' =>
'/index.php',
370 'PATH_INFO' =>
'/current-context1/current-context2/current-page/current-op'
374 $this->
_setUpMockDAOs(
'current-context1',
'current-context2',
false,
true);
376 $result = $this->router->url($this->request);
377 self::assertEquals(
'http://mydomain.org/index.php/current-context1/index/current-page/current-op', $result);
386 'SERVER_NAME' =>
'mydomain.org',
387 'SCRIPT_NAME' =>
'/index.php',
390 'firstContext' =>
'current-context1',
391 'secondContext' =>
'current-context2',
392 'page' =>
'current-page',
399 $result = $this->router->url($this->request);
400 self::assertEquals(
'http://mydomain.org/index.php?firstContext=current-context1&secondContext=current-context2&page=current-page&op=current-op', $result);
402 $result = $this->router->url($this->request,
'new-context1');
403 self::assertEquals(
'http://mydomain.org/index.php?firstContext=new-context1&secondContext=current-context2', $result);
405 $result = $this->router->url($this->request, array(
'new-context1',
'new-context2'));
406 self::assertEquals(
'http://mydomain.org/index.php?firstContext=new-context1&secondContext=new-context2', $result);
408 $result = $this->router->url($this->request, array(),
'new-page');
409 self::assertEquals(
'http://mydomain.org/index.php?firstContext=current-context1&secondContext=current-context2&page=new-page', $result);
411 $result = $this->router->url($this->request, array(),
null,
'new-op');
412 self::assertEquals(
'http://mydomain.org/index.php?firstContext=current-context1&secondContext=current-context2&page=current-page&op=new-op', $result);
414 $result = $this->router->url($this->request,
'new-context1',
'new-page');
415 self::assertEquals(
'http://mydomain.org/index.php?firstContext=new-context1&secondContext=current-context2&page=new-page', $result);
417 $result = $this->router->url($this->request,
'new-context1',
'new-page',
'new-op');
418 self::assertEquals(
'http://mydomain.org/index.php?firstContext=new-context1&secondContext=current-context2&page=new-page&op=new-op', $result);
420 $result = $this->router->url($this->request,
'new-context1',
null,
'new-op');
421 self::assertEquals(
'http://mydomain.org/index.php?firstContext=new-context1&secondContext=current-context2&page=index&op=new-op', $result);
423 $result = $this->router->url($this->request,
'new-context1',
null,
null,
'add?path');
424 self::assertEquals(
'http://mydomain.org/index.php?firstContext=new-context1&secondContext=current-context2&page=index&op=index&path[]=add%3Fpath', $result);
426 $result = $this->router->url($this->request,
'new-context1',
null,
null, array(
'add-path1',
'add?path2'));
427 self::assertEquals(
'http://mydomain.org/index.php?firstContext=new-context1&secondContext=current-context2&page=index&op=index&path[]=add-path1&path[]=add%3Fpath2', $result);
429 $result = $this->router->url($this->request,
'new-context1',
null,
null,
null,
432 'key2' => array(
'val2-1',
'val2?2')
435 self::assertEquals(
'http://mydomain.org/index.php?firstContext=new-context1&secondContext=current-context2&key1=val1%3F&key2[]=val2-1&key2[]=val2%3F2', $result);
437 $result = $this->router->url($this->request,
'new-context1',
null,
null,
null,
null,
'some?anchor');
438 self::assertEquals(
'http://mydomain.org/index.php?firstContext=new-context1&secondContext=current-context2#some%3Fanchor', $result);
440 $result = $this->router->url($this->request,
'new-context1',
null,
'new-op',
'add-path', array(
'key' =>
'val'),
'some-anchor');
441 self::assertEquals(
'http://mydomain.org/index.php?firstContext=new-context1&secondContext=current-context2&page=index&op=new-op&path[]=add-path&key=val#some-anchor', $result);
443 $result = $this->router->url($this->request,
'new-context1',
null,
null,
null, array(
'key1' =>
'val1',
'key2' =>
'val2'),
null,
true);
444 self::assertEquals(
'http://mydomain.org/index.php?firstContext=new-context1&secondContext=current-context2&key1=val1&key2=val2', $result);
454 'SERVER_NAME' =>
'mydomain.org',
455 'SCRIPT_NAME' =>
'/index.php',
458 'firstContext' =>
'overridden-context',
459 'secondContext' =>
'current-context2',
460 'page' =>
'current-page',
469 $result = $this->router->url($this->request);
470 self::assertEquals(
'http://some-user:some-pass@some-domain:8080/?firstContext=xyz-context&secondContext=current-context2&page=current-page&op=current-op', $result);
480 'SERVER_NAME' =>
'mydomain.org',
481 'SCRIPT_NAME' =>
'/index.php',
484 'firstContext' =>
'current-context1',
485 'secondContext' =>
'current-context2',
486 'page' =>
'current-page',
491 $this->
_setUpMockDAOs(
'current-context1',
'current-context2',
false,
true);
494 $result = $this->router->url($this->request);
495 self::assertEquals(
'http://mydomain.org/?firstContext=current-context1&secondContext=index&page=current-page&op=current-op', $result);