We are moving to Git Issues for bug tracking in future releases. During transition, content will be in both tools. If you'd like to file a new bug, please create an issue.

View | Details | Raw Unified | Return to bug 4934 | Differences between
and this patch

Collapse All | Expand All

(-)lib/pkp/classes/core/PKPRequest.inc.php (-1 / +8 lines)
 Lines 640-646    Link Here 
640
	 */
640
	 */
641
	function getRequestedContextPath($contextLevel = null) {
641
	function getRequestedContextPath($contextLevel = null) {
642
		$_this =& PKPRequest::_checkThis();
642
		$_this =& PKPRequest::_checkThis();
643
		return $_this->_delegateToRouter('getRequestedContextPath', $contextLevel);
643
644
		// Emulate the old behavior of getRequestedContextPath for
645
		// backwards compatibility.
646
		if (is_null($contextLevel)) {
647
			return $_this->_delegateToRouter('getRequestedContextPaths');
648
		} else {
649
			return array($_this->_delegateToRouter('getRequestedContextPath', $contextLevel));
650
		}
644
	}
651
	}
645
652
646
	/**
653
	/**
(-)lib/pkp/classes/core/PKPRouter.inc.php (-24 / +29 lines)
 Lines 135-158    Link Here 
135
	}
135
	}
136
136
137
	/**
137
	/**
138
	 * A Generic call to a context-defined path (e.g. a Press or a Conference's path)
138
	 * A generic method to return an array of context paths (e.g. a Press or a Conference/SchedConf paths)
139
	 * @param $request PKPRequest the request to be routed
139
	 * @param $request PKPRequest the request to be routed
140
	 * @param $requestedContextLevel int (optional) the number of levels of context to return in the path
140
	 * @param $requestedContextLevel int (optional) the context level to return in the path
141
	 * @param $asArray boolean false to return a scalar for the given context level
141
	 * @return array of string (each element the path to one context element)
142
	 * @return array of String (each element the path to one context element)
143
	 */
142
	 */
144
	function getRequestedContextPath(&$request, $requestedContextLevel = null, $asArray = true) {
143
	function getRequestedContextPaths(&$request) {
145
		assert(isset($this->_contextDepth) && isset($this->_contextList));
146
147
		// Handle context depth 0
144
		// Handle context depth 0
148
		if (!$this->_contextDepth) {
145
		if (!$this->_contextDepth) return array();
149
			if ($asArray) return array();
150
			else return null;
151
		}
152
146
153
		// Validate the context level
147
		// Validate context parameters
154
		assert(is_null($requestedContextLevel) ||
148
		assert(isset($this->_contextDepth) && isset($this->_contextList));
155
				($requestedContextLevel > 0 && $requestedContextLevel <= $this->_contextDepth));
156
149
157
		// Determine the context path
150
		// Determine the context path
158
		if (empty($this->_contextPaths)) {
151
		if (empty($this->_contextPaths)) {
 Lines 182-199    Link Here 
182
				$this->_contextPaths[$key] = Core::cleanFileVar($this->_contextPaths[$key]);
175
				$this->_contextPaths[$key] = Core::cleanFileVar($this->_contextPaths[$key]);
183
			}
176
			}
184
177
185
			HookRegistry::call('Router::getRequestedContextPath', array(&$this->_contextPaths));
178
			HookRegistry::call('Router::getRequestedContextPaths', array(&$this->_contextPaths));
186
		}
179
		}
187
180
188
		if (is_null($requestedContextLevel)) {
181
		return $this->_contextPaths;
189
			return $this->_contextPaths;
182
	}
190
		} else {
183
191
			if ($asArray) {
184
	/**
192
				return array($this->_contextPaths[$requestedContextLevel - 1]);
185
	 * A generic method to return a single context path (e.g. a Press or a SchedConf path)
193
			} else {
186
	 * @param $request PKPRequest the request to be routed
194
				return $this->_contextPaths[$requestedContextLevel - 1];
187
	 * @param $requestedContextLevel int (optional) the context level to return
195
			}
188
	 * @return string
196
		}
189
	 */
190
	function getRequestedContextPath(&$request, $requestedContextLevel = 1) {
191
		// Handle context depth 0
192
		if (!$this->_contextDepth) return null;
193
194
		// Validate the context level
195
		assert(isset($this->_contextDepth) && isset($this->_contextList));
196
		assert($requestedContextLevel > 0 && $requestedContextLevel <= $this->_contextDepth);
197
198
		// Return the full context, then retrieve the requested context path
199
		$contextPaths = $this->getRequestedContextPaths($request);
200
		assert(isset($this->_contextPaths[$requestedContextLevel - 1]));
201
		return $this->_contextPaths[$requestedContextLevel - 1];
197
	}
202
	}
198
203
199
	/**
204
	/**
(-)lib/pkp/tests/classes/core/PKPRouterTest.inc.php (-21 / +20 lines)
 Lines 79-84    Link Here 
79
79
80
	/**
80
	/**
81
	 * @covers PKPRouter::getRequestedContextPath
81
	 * @covers PKPRouter::getRequestedContextPath
82
	 * @covers PKPRouter::getRequestedContextPaths
82
	 * @expectedException PHPUnit_Framework_Error
83
	 * @expectedException PHPUnit_Framework_Error
83
	 */
84
	 */
84
	public function testGetRequestedContextPathWithInvalidLevel() {
85
	public function testGetRequestedContextPathWithInvalidLevel() {
 Lines 88-103    Link Here 
88
	}
89
	}
89
90
90
	/**
91
	/**
91
	 * @covers PKPRouter::getRequestedContextPath
92
	 * @covers PKPRouter::getRequestedContextPaths
92
	 */
93
	 */
93
	public function testGetRequestedContextPathWithEmptyPathInfo() {
94
	public function testGetRequestedContextPathWithEmptyPathInfo() {
94
		$this->_setUpMockEnvironment(self::PATHINFO_ENABLED);
95
		$this->_setUpMockEnvironment(self::PATHINFO_ENABLED);
95
		$_SERVER['PATH_INFO'] = null;
96
		$_SERVER['PATH_INFO'] = null;
96
		self::assertEquals(array('index', 'index'),
97
		self::assertEquals(array('index', 'index'),
97
				$this->router->getRequestedContextPath($this->request));
98
				$this->router->getRequestedContextPaths($this->request));
98
	}
99
	}
99
100
100
	/**
101
	/**
102
	 * @covers PKPRouter::getRequestedContextPaths
101
	 * @covers PKPRouter::getRequestedContextPath
103
	 * @covers PKPRouter::getRequestedContextPath
102
	 */
104
	 */
103
	public function testGetRequestedContextPathWithFullPathInfo() {
105
	public function testGetRequestedContextPathWithFullPathInfo() {
 Lines 105-158    Link Here 
105
		HookRegistry::resetCalledHooks();
107
		HookRegistry::resetCalledHooks();
106
		$_SERVER['PATH_INFO'] = '/context1/context2/other/path/vars';
108
		$_SERVER['PATH_INFO'] = '/context1/context2/other/path/vars';
107
		self::assertEquals(array('context1', 'context2'),
109
		self::assertEquals(array('context1', 'context2'),
108
				$this->router->getRequestedContextPath($this->request));
110
				$this->router->getRequestedContextPaths($this->request));
109
		self::assertEquals(array('context1'),
110
				$this->router->getRequestedContextPath($this->request, 1));
111
		self::assertEquals(array('context2'),
112
				$this->router->getRequestedContextPath($this->request, 2));
113
		self::assertEquals('context1',
111
		self::assertEquals('context1',
114
				$this->router->getRequestedContextPath($this->request, 1, false));
112
				$this->router->getRequestedContextPath($this->request, 1));
115
		self::assertEquals('context2',
113
		self::assertEquals('context2',
116
				$this->router->getRequestedContextPath($this->request, 2, false));
114
				$this->router->getRequestedContextPath($this->request, 2));
117
		self::assertEquals(
115
		self::assertEquals(
118
			array(array('Router::getRequestedContextPath', array(array('context1', 'context2')))),
116
			array(array('Router::getRequestedContextPaths', array(array('context1', 'context2')))),
119
			HookRegistry::getCalledHooks()
117
			HookRegistry::getCalledHooks()
120
		);
118
		);
121
	}
119
	}
122
120
123
	/**
121
	/**
124
	 * @covers PKPRouter::getRequestedContextPath
122
	 * @covers PKPRouter::getRequestedContextPaths
125
	 */
123
	 */
126
	public function testGetRequestedContextPathWithPartialPathInfo() {
124
	public function testGetRequestedContextPathWithPartialPathInfo() {
127
		$this->_setUpMockEnvironment(self::PATHINFO_ENABLED);
125
		$this->_setUpMockEnvironment(self::PATHINFO_ENABLED);
128
		$_SERVER['PATH_INFO'] = '/context';
126
		$_SERVER['PATH_INFO'] = '/context';
129
		self::assertEquals(array('context', 'index'),
127
		self::assertEquals(array('context', 'index'),
130
				$this->router->getRequestedContextPath($this->request));
128
				$this->router->getRequestedContextPaths($this->request));
131
	}
129
	}
132
130
133
	/**
131
	/**
134
	 * @covers PKPRouter::getRequestedContextPath
132
	 * @covers PKPRouter::getRequestedContextPaths
135
	 */
133
	 */
136
	public function testGetRequestedContextPathWithInvalidPathInfo() {
134
	public function testGetRequestedContextPathWithInvalidPathInfo() {
137
		$this->_setUpMockEnvironment(self::PATHINFO_ENABLED);
135
		$this->_setUpMockEnvironment(self::PATHINFO_ENABLED);
138
		$_SERVER['PATH_INFO'] = '/context:?#/';
136
		$_SERVER['PATH_INFO'] = '/context:?#/';
139
		self::assertEquals(array('context', 'index'),
137
		self::assertEquals(array('context', 'index'),
140
				$this->router->getRequestedContextPath($this->request));
138
				$this->router->getRequestedContextPaths($this->request));
141
	}
139
	}
142
140
143
	/**
141
	/**
144
	 * @covers PKPRouter::getRequestedContextPath
142
	 * @covers PKPRouter::getRequestedContextPaths
145
	 */
143
	 */
146
	public function testGetRequestedContextPathWithEmptyContextParameters() {
144
	public function testGetRequestedContextPathWithEmptyContextParameters() {
147
		$this->_setUpMockEnvironment(self::PATHINFO_DISABLED);
145
		$this->_setUpMockEnvironment(self::PATHINFO_DISABLED);
148
		$_GET['firstContext'] = null;
146
		$_GET['firstContext'] = null;
149
		$_GET['secondContext'] = null;
147
		$_GET['secondContext'] = null;
150
		self::assertEquals(array('index', 'index'),
148
		self::assertEquals(array('index', 'index'),
151
				$this->router->getRequestedContextPath($this->request));
149
				$this->router->getRequestedContextPaths($this->request));
152
	}
150
	}
153
151
154
	/**
152
	/**
155
	 * @covers PKPRouter::getRequestedContextPath
153
	 * @covers PKPRouter::getRequestedContextPath
154
	 * @covers PKPRouter::getRequestedContextPaths
156
	 */
155
	 */
157
	public function testGetRequestedContextPathWithFullContextParameters() {
156
	public function testGetRequestedContextPathWithFullContextParameters() {
158
		$this->_setUpMockEnvironment(self::PATHINFO_DISABLED);
157
		$this->_setUpMockEnvironment(self::PATHINFO_DISABLED);
 Lines 160-169    Link Here 
160
		$_GET['firstContext'] = 'context1';
159
		$_GET['firstContext'] = 'context1';
161
		$_GET['secondContext'] = 'context2';
160
		$_GET['secondContext'] = 'context2';
162
		self::assertEquals(array('context1', 'context2'),
161
		self::assertEquals(array('context1', 'context2'),
163
				$this->router->getRequestedContextPath($this->request));
162
				$this->router->getRequestedContextPaths($this->request));
164
		self::assertEquals(array('context1'),
163
		self::assertEquals('context1',
165
				$this->router->getRequestedContextPath($this->request, 1));
164
				$this->router->getRequestedContextPath($this->request, 1));
166
		self::assertEquals(array('context2'),
165
		self::assertEquals('context2',
167
				$this->router->getRequestedContextPath($this->request, 2));
166
				$this->router->getRequestedContextPath($this->request, 2));
168
		self::assertEquals(
167
		self::assertEquals(
169
			array(array('Router::getRequestedContextPath', array(array('context1', 'context2')))),
168
			array(array('Router::getRequestedContextPath', array(array('context1', 'context2')))),
 Lines 172-184    Link Here 
172
	}
171
	}
173
172
174
	/**
173
	/**
175
	 * @covers PKPRouter::getRequestedContextPath
174
	 * @covers PKPRouter::getRequestedContextPaths
176
	 */
175
	 */
177
	public function testGetRequestedContextPathWithPartialContextParameters() {
176
	public function testGetRequestedContextPathWithPartialContextParameters() {
178
		$this->_setUpMockEnvironment(self::PATHINFO_DISABLED);
177
		$this->_setUpMockEnvironment(self::PATHINFO_DISABLED);
179
		$_GET['firstContext'] = 'context';
178
		$_GET['firstContext'] = 'context';
180
		self::assertEquals(array('context', 'index'),
179
		self::assertEquals(array('context', 'index'),
181
				$this->router->getRequestedContextPath($this->request));
180
				$this->router->getRequestedContextPaths($this->request));
182
	}
181
	}
183
182
184
	/**
183
	/**

Return to bug 4934