Open Journal Systems  3.3.0
DispatcherTest.php
1 <?php
2 
17 import('lib.pkp.tests.PKPTestCase');
18 import('lib.pkp.classes.core.Registry');
19 import('classes.core.Application');
20 import('lib.pkp.classes.core.Dispatcher');
21 import('lib.pkp.classes.core.PKPRequest');
22 import('lib.pkp.classes.plugins.HookRegistry');
23 
24 class DispatcherTest extends PKPTestCase {
25  const
28 
29  private
30  $dispatcher,
32 
36  protected function getMockedRegistryKeys() {
37  return array('application', 'dispatcher');
38  }
39 
43  protected function setUp() : void {
44  parent::setUp();
45 
46  // Mock application object without calling its constructor.
47  $mockApplication = $this->getMockBuilder(Application::class)
48  ->setMethods(array('getContextDepth', 'getContextList'))
49  ->getMock();
50 
51  // Set up the getContextDepth() method
52  $mockApplication->expects($this->any())
53  ->method('getContextDepth')
54  ->will($this->returnValue(2));
55 
56  // Set up the getContextList() method
57  $mockApplication->expects($this->any())
58  ->method('getContextList')
59  ->will($this->returnValue(array('firstContext', 'secondContext')));
60 
61  $this->dispatcher = $mockApplication->getDispatcher(); // this also adds the component router
62  $this->dispatcher->addRouterName('lib.pkp.classes.core.PKPPageRouter', 'page');
63 
64  $this->request = new PKPRequest();
65  }
66 
70  public function testUrl() {
71  if (Config::getVar('general', 'disable_path_info')) $this->markTestSkipped();
72  $baseUrl = $this->request->getBaseUrl();
73 
74  $url = $this->dispatcher->url($this->request, ROUTE_PAGE, array('context1', 'context2'), 'somepage', 'someop');
75  self::assertEquals($baseUrl.'/index.php/context1/context2/somepage/someop', $url);
76 
77  $url = $this->dispatcher->url($this->request, ROUTE_COMPONENT, array('context1', 'context2'), 'some.ComponentHandler', 'someOp');
78  self::assertEquals($baseUrl.'/index.php/context1/context2/$$$call$$$/some/component/some-op', $url);
79  }
80 }
81 
82 
DispatcherTest
Tests for the Dispatcher class.
Definition: DispatcherTest.php:24
PKPTestCase
Class that implements functionality common to all PKP unit test cases.
Definition: PKPTestCase.inc.php:27
DispatcherTest\getMockedRegistryKeys
getMockedRegistryKeys()
Definition: DispatcherTest.php:36
DispatcherTest\testUrl
testUrl()
Definition: DispatcherTest.php:70
DispatcherTest\setUp
setUp()
Definition: DispatcherTest.php:43
PKPRequest
Class providing operations associated with HTTP requests.
Definition: PKPRequest.inc.php:17
DispatcherTest\PATHINFO_ENABLED
const PATHINFO_ENABLED
Definition: DispatcherTest.php:26
DispatcherTest\PATHINFO_DISABLED
const PATHINFO_DISABLED
Definition: DispatcherTest.php:27
Config\getVar
static getVar($section, $key, $default=null)
Definition: Config.inc.php:35
DispatcherTest\$request
$request
Definition: DispatcherTest.php:31