Open Journal Systems  3.3.0
CoreTest.inc.php
1 <?php
2 
17 import('lib.pkp.tests.PKPTestCase');
18 
19 class CoreTest extends PKPTestCase {
20 
30  public function testRemoveBaseUrl($baseUrl, $url, $expectUrl) {
31  $configData =& Config::getData();
32  $configData['general']['base_url'] = $baseUrl;
33 
34  $actualUrl = Core::removeBaseUrl($url);
35  $this->assertEquals($expectUrl, $actualUrl);
36  }
37 
48  public function testRemoveBaseUrlOverride($contextPath, $baseUrl, $url, $expectUrl) {
49  $configData =& Config::getData();
50  $configData['general']['base_url[' . $contextPath . ']'] = $baseUrl;
51  $configData['general']['base_url[test2]'] = $baseUrl . '/test';
52  // edge case: context matches a page
53  $configData['general']['base_url[art]'] = $baseUrl . '/art';
54 
55  $actualUrl = Core::removeBaseUrl($url);
56  $this->assertEquals($expectUrl, $actualUrl);
57  }
58 
63  public function testRemoveBaseUrlDataProvider() {
64  $cases = array();
65 
66  // Without host.
67  $cases[] = array('http://localhost/ojs', '/', '');
68  $cases[] = array('http://localhost/ojs', '/index.php', '');
69  $cases[] = array('http://localhost/ojs', '/ojs', '');
70  $cases[] = array('http://localhost/ojs', '/ojs/index.php/ojs/index', '/ojs/index');
71  $cases[] = array('http://localhost/ojs', '/ojs/index.php/ojstest/index', '/ojstest/index');
72  // Without host and rewrite rules removing index.php.
73  $cases[] = array('http://localhost/ojs', '/ojs/ojstest/index', '/ojstest/index');
74 
75  // With host.
76  $cases[] = array('http://localhost/ojs', 'http://localhost/ojs/', '');
77  $cases[] = array('http://localhost/ojs', 'http://localhost/ojs/index.php', '');
78  $cases[] = array('http://localhost/ojs', 'http://localhost/ojs/index.php/ojstest/index', '/ojstest/index');
79  $cases[] = array('http://localhost/ojs', 'http://localhost/ojs/index.php/ojstest/index/index/path?arg1=arg&arg2=arg', '/ojstest/index/index/path?arg1=arg&arg2=arg');
80  // With host and rewrite rules removing index.php.
81  $cases[] = array('http://localhost/ojs', 'http://localhost/ojs/ojstest/index', '/ojstest/index');
82 
83  // Path info disabled.
84  $cases[] = array('http://localhost/ojs', 'http://localhost/ojs/index.php?journal=test', '?journal=test');
85  $cases[] = array('http://localhost/ojs', 'http://localhost/ojs', '');
86  $cases[] = array('http://localhost/ojs', 'http://localhost/ojs/index.php', '');
87  $cases[] = array('http://localhost/ojs', 'http://localhost/ojs/index.php?', '?');
88  // Path info disabled and rewrite rules removing index.php.
89  $cases[] = array('http://localhost/ojs', 'http://localhost/ojs?journal=test', '?journal=test');
90 
91  // Path info disabled without host.
92  $cases[] = array('http://localhost/ojs', '/ojs/index.php?journal=test', '?journal=test');
93  $cases[] = array('http://localhost/ojs', '/ojs', '');
94  $cases[] = array('http://localhost/ojs', '/ojs/index.php', '');
95  $cases[] = array('http://localhost/ojs', '/ojs/index.php?', '?');
96  // Path info disabled without host and rewrite rules removing index.php.
97  $cases[] = array('http://localhost/ojs', '/ojs?journal=test', '?journal=test');
98 
99  // Edge cases
100  $cases[] = array('http://localhost/ojs', 'http://localhost/ojs/index.php/art/article/view/100', '/art/article/view/100');
101 
102  return $cases;
103  }
104 
110  $cases = array();
111 
112  // Url without context or any other url component.
113  $cases[] = array('test', 'http://localhost', '/', '/test');
114  $cases[] = array('test', 'http://localhost', '/?', '/test/?');
115 
116  // Url without context or any other path.
117  $cases[] = array('test', 'http://localhost', 'http://localhost', '/test');
118  $cases[] = array('test', 'http://localhost', 'http://localhost/?', '/test/?');
119 
120  // Url without context removed by rewrite rules.
121  $cases[] = array('test', 'http://localhost/ojs', '/ojs/index', '/test/index');
122  // Same as above but with index.php.
123  $cases[] = array('test', 'http://localhost/ojs', '/ojs/index.php/index', '/test/index');
124 
125  // Impossible to know which base url forms the url.
126  $cases[] = array('test', 'http://localhost/ojstest', '/ojstest/test/index', false);
127  // Same as above, but possible to know because of the 'index.php' presence.
128  $cases[] = array('test', 'http://localhost/ojstest', '/ojstest/index.php/test/index', '/test/index');
129 
130  // Overlaping contexts.
131  $cases[] = array('test1', 'http://localhost', '/test/index', '/test2/index');
132  $cases[] = array('test1', 'http://localhost', '/test/index', '/test2/index');
133  // Overlaping contexts, path info disabled.
134  $cases[] = array('test1', 'http://localhost', '/test/index.php?journal=test2&page=index', '/test2?journal=test2&page=index');
135  // Overlaping contexts, path info disabled, rewrite rules removing index.php.
136  $cases[] = array('test1', 'http://localhost', '/test?journal=test2&page=index', '/test2?journal=test2&page=index');
137 
138  // Path info disabled, overwrite rules removing index.php
139  $cases[] = array('test', 'http://localhost/ojstest', '/ojstest?journal=test&page=index', '/test?journal=test&page=index');
140  // Path info disabled only.
141  $cases[] = array('test', 'http://localhost/ojstest', '/ojstest/index.php?journal=test&page=index', '/test?journal=test&page=index');
142 
143  // Edge cases
144  $cases[] = array('art', 'http://localhost', 'http://localhost/art/article/view/100', '/art/article/view/100');
145 
146  return $cases;
147  }
148 }
149 
CoreTest\testRemoveBaseUrlOverride
testRemoveBaseUrlOverride($contextPath, $baseUrl, $url, $expectUrl)
Definition: CoreTest.inc.php:48
PKPTestCase
Class that implements functionality common to all PKP unit test cases.
Definition: PKPTestCase.inc.php:27
CoreTest
Tests for the Core class.
Definition: CoreTest.inc.php:19
CoreTest\testRemoveBaseUrlOverrideDataProvider
testRemoveBaseUrlOverrideDataProvider()
Definition: CoreTest.inc.php:109
Config\getData
static & getData()
Definition: Config.inc.php:44
CoreTest\testRemoveBaseUrl
testRemoveBaseUrl($baseUrl, $url, $expectUrl)
Definition: CoreTest.inc.php:30
CoreTest\testRemoveBaseUrlDataProvider
testRemoveBaseUrlDataProvider()
Definition: CoreTest.inc.php:63
Core\removeBaseUrl
removeBaseUrl($url)
Definition: Core.inc.php:233