summaryrefslogtreecommitdiffstats
path: root/tests/codeigniter/core/URI_test.php
diff options
context:
space:
mode:
authorPhil Sturgeon <email@philsturgeon.co.uk>2012-06-15 00:02:16 +0200
committerPhil Sturgeon <email@philsturgeon.co.uk>2012-06-15 00:02:16 +0200
commitc9bb0c5b7a3a349a5c255b02b5cc7ddbe32132e5 (patch)
tree905ff3f3153720c1d1547092e54feaf0e46568a6 /tests/codeigniter/core/URI_test.php
parent3061ee737ff2c1853428482e1704b0973b621118 (diff)
parentf11a1939c25de1e327c7c02001c8fbd1ec1fc7b4 (diff)
Merge branch 'develop' of github.com:EllisLab/CodeIgniter into develop
Diffstat (limited to 'tests/codeigniter/core/URI_test.php')
-rw-r--r--tests/codeigniter/core/URI_test.php230
1 files changed, 99 insertions, 131 deletions
diff --git a/tests/codeigniter/core/URI_test.php b/tests/codeigniter/core/URI_test.php
index e340ddf73..60ed1a4e9 100644
--- a/tests/codeigniter/core/URI_test.php
+++ b/tests/codeigniter/core/URI_test.php
@@ -1,7 +1,7 @@
<?php
class URI_test extends CI_TestCase {
-
+
public function set_up()
{
$this->uri = new Mock_Core_URI();
@@ -9,23 +9,21 @@ class URI_test extends CI_TestCase {
// --------------------------------------------------------------------
+ /* As of the following commit, _set_uri_string() is a protected method:
+
+ https://github.com/EllisLab/CodeIgniter/commit/d461934184d95b0cfb2feec93f27b621ef72a5c2
+
public function test_set_uri_string()
{
// Slashes get killed
$this->uri->_set_uri_string('/');
-
- $a = '';
- $b =& $this->uri->uri_string;
-
- $this->assertEquals($a, $b);
-
+ $this->assertEquals('', $this->uri->uri_string);
+
$this->uri->_set_uri_string('nice/uri');
-
- $a = 'nice/uri';
-
- $this->assertEquals($a, $b);
+ $this->assertEquals('nice/uri', $this->uri->uri_string);
}
-
+ */
+
// --------------------------------------------------------------------
public function test_fetch_uri_string()
@@ -34,75 +32,61 @@ class URI_test extends CI_TestCase {
// uri_protocol: AUTO
$this->uri->config->set_item('uri_protocol', 'AUTO');
-
+
// Test a variety of request uris
$requests = array(
'/index.php/controller/method' => 'controller/method',
'/index.php?/controller/method' => 'controller/method',
'/index.php?/controller/method/?var=foo' => 'controller/method'
);
-
+
foreach($requests as $request => $expected)
{
$_SERVER['SCRIPT_NAME'] = '/index.php';
$_SERVER['REQUEST_URI'] = $request;
-
+
$this->uri->_fetch_uri_string();
$this->assertEquals($expected, $this->uri->uri_string );
}
-
+
// Test a subfolder
$_SERVER['SCRIPT_NAME'] = '/subfolder/index.php';
$_SERVER['REQUEST_URI'] = '/subfolder/index.php/controller/method';
-
+
$this->uri->_fetch_uri_string();
-
- $a = 'controller/method';
- $b = $this->uri->uri_string;
-
- $this->assertEquals($a, $b);
-
+ $this->assertEquals('controller/method', $this->uri->uri_string);
+
// death to request uri
unset($_SERVER['REQUEST_URI']);
-
+
// life to path info
- $_SERVER['PATH_INFO'] = '/controller/method/';
-
+ $_SERVER['PATH_INFO'] = $a = '/controller/method/';
+
$this->uri->_fetch_uri_string();
-
- $a = '/controller/method/';
- $b =& $this->uri->uri_string;
+ $this->assertEquals($a, $this->uri->uri_string);
- $this->assertEquals($a, $b);
-
// death to path info
// At this point your server must be seriously drunk
unset($_SERVER['PATH_INFO']);
-
+
$_SERVER['QUERY_STRING'] = '/controller/method/';
-
+
$this->uri->_fetch_uri_string();
+ $this->assertEquals($a, $this->uri->uri_string);
- $a = '/controller/method/';
- $b = $this->uri->uri_string;
-
- $this->assertEquals($a, $b);
-
// At this point your server is a labotomy victim
-
unset($_SERVER['QUERY_STRING']);
-
+
$_GET['/controller/method/'] = '';
-
+
$this->uri->_fetch_uri_string();
- $this->assertEquals($a, $b);
+ $this->assertEquals($a, $this->uri->uri_string);
// Test coverage implies that these will work
// uri_protocol: REQUEST_URI
// uri_protocol: CLI
-
}
-
+
// --------------------------------------------------------------------
public function test_explode_segments()
@@ -113,18 +97,15 @@ class URI_test extends CI_TestCase {
'/test2/uri2' => array('test2', 'uri2'),
'//test3/test3///' => array('test3', 'test3')
);
-
- foreach($uris as $uri => $a)
+
+ foreach ($uris as $uri => $a)
{
$this->uri->segments = array();
$this->uri->uri_string = $uri;
$this->uri->_explode_segments();
-
- $b = $this->uri->segments;
-
- $this->assertEquals($a, $b);
+
+ $this->assertEquals($a, $this->uri->segments);
}
-
}
// --------------------------------------------------------------------
@@ -133,7 +114,7 @@ class URI_test extends CI_TestCase {
{
$this->uri->config->set_item('enable_query_strings', FALSE);
$this->uri->config->set_item('permitted_uri_chars', 'a-z 0-9~%.:_\-');
-
+
$str_in = 'abc01239~%.:_-';
$str = $this->uri->_filter_uri($str_in);
@@ -145,52 +126,52 @@ class URI_test extends CI_TestCase {
public function test_filter_uri_escaping()
{
// ensure escaping even if dodgey characters are permitted
-
+
$this->uri->config->set_item('enable_query_strings', FALSE);
$this->uri->config->set_item('permitted_uri_chars', 'a-z 0-9~%.:_\-()$');
$str = $this->uri->_filter_uri('$destroy_app(foo)');
-
+
$this->assertEquals($str, '&#36;destroy_app&#40;foo&#41;');
}
// --------------------------------------------------------------------
- public function test_filter_uri_throws_error()
- {
+ public function test_filter_uri_throws_error()
+ {
$this->setExpectedException('RuntimeException');
-
+
$this->uri->config->set_item('enable_query_strings', FALSE);
$this->uri->config->set_item('permitted_uri_chars', 'a-z 0-9~%.:_\-');
$this->uri->_filter_uri('$this()');
- }
+ }
// --------------------------------------------------------------------
public function test_remove_url_suffix()
{
$this->uri->config->set_item('url_suffix', '.html');
-
+
$this->uri->uri_string = 'controller/method/index.html';
$this->uri->_remove_url_suffix();
-
+
$this->assertEquals($this->uri->uri_string, 'controller/method/index');
-
+
$this->uri->uri_string = 'controller/method/index.htmlify.html';
$this->uri->_remove_url_suffix();
-
+
$this->assertEquals($this->uri->uri_string, 'controller/method/index.htmlify');
}
// --------------------------------------------------------------------
-
+
public function test_segment()
{
$this->uri->segments = array(1 => 'controller');
$this->assertEquals($this->uri->segment(1), 'controller');
$this->assertEquals($this->uri->segment(2, 'default'), 'default');
}
-
+
// --------------------------------------------------------------------
public function test_rsegment()
@@ -205,32 +186,33 @@ class URI_test extends CI_TestCase {
public function test_uri_to_assoc()
{
$this->uri->segments = array('a', '1', 'b', '2', 'c', '3');
-
- $a = array('a' => '1', 'b' => '2', 'c' => '3');
- $b = $this->uri->uri_to_assoc(1);
- $this->assertEquals($a, $b);
-
- $a = array('b' => '2', 'c' => '3');
- $b = $this->uri->uri_to_assoc(3);
- $this->assertEquals($a, $b);
-
-
+
+ $this->assertEquals(
+ array('a' => '1', 'b' => '2', 'c' => '3'),
+ $this->uri->uri_to_assoc(1)
+ );
+
+ $this->assertEquals(
+ array('b' => '2', 'c' => '3'),
+ $this->uri->uri_to_assoc(3)
+ );
+
$this->uri->keyval = array(); // reset cache
-
$this->uri->segments = array('a', '1', 'b', '2', 'c');
-
- $a = array('a' => '1', 'b' => '2', 'c' => FALSE);
- $b = $this->uri->uri_to_assoc(1);
- $this->assertEquals($a, $b);
-
+
+ $this->assertEquals(
+ array('a' => '1', 'b' => '2', 'c' => FALSE),
+ $this->uri->uri_to_assoc(1)
+ );
+
$this->uri->keyval = array(); // reset cache
-
$this->uri->segments = array('a', '1');
-
+
// test default
- $a = array('a' => '1', 'b' => FALSE);
- $b = $this->uri->uri_to_assoc(1, array('a', 'b'));
- $this->assertEquals($a, $b);
+ $this->assertEquals(
+ array('a' => '1', 'b' => FALSE),
+ $this->uri->uri_to_assoc(1, array('a', 'b'))
+ );
}
// --------------------------------------------------------------------
@@ -238,33 +220,33 @@ class URI_test extends CI_TestCase {
public function test_ruri_to_assoc()
{
$this->uri->rsegments = array('x', '1', 'y', '2', 'z', '3');
-
- $a = array('x' => '1', 'y' => '2', 'z' => '3');
- $b = $this->uri->ruri_to_assoc(1);
- $this->assertEquals($a, $b);
-
- $a = array('y' => '2', 'z' => '3');
- $b = $this->uri->ruri_to_assoc(3);
- $this->assertEquals($a, $b);
-
-
+
+ $this->assertEquals(
+ array('x' => '1', 'y' => '2', 'z' => '3'),
+ $this->uri->ruri_to_assoc(1)
+ );
+
+ $this->assertEquals(
+ array('y' => '2', 'z' => '3'),
+ $this->uri->ruri_to_assoc(3)
+ );
+
$this->uri->keyval = array(); // reset cache
-
$this->uri->rsegments = array('x', '1', 'y', '2', 'z');
-
- $a = array('x' => '1', 'y' => '2', 'z' => FALSE);
- $b = $this->uri->ruri_to_assoc(1);
- $this->assertEquals($a, $b);
-
+
+ $this->assertEquals(
+ array('x' => '1', 'y' => '2', 'z' => FALSE),
+ $this->uri->ruri_to_assoc(1)
+ );
+
$this->uri->keyval = array(); // reset cache
-
$this->uri->rsegments = array('x', '1');
-
- // test default
- $a = array('x' => '1', 'y' => FALSE);
- $b = $this->uri->ruri_to_assoc(1, array('x', 'y'));
- $this->assertEquals($a, $b);
+ // test default
+ $this->assertEquals(
+ array('x' => '1', 'y' => FALSE),
+ $this->uri->ruri_to_assoc(1, array('x', 'y'))
+ );
}
// --------------------------------------------------------------------
@@ -272,11 +254,7 @@ class URI_test extends CI_TestCase {
public function test_assoc_to_uri()
{
$this->uri->config->set_item('uri_string_slashes', 'none');
-
- $arr = array('a' => 1, 'b' => 2);
- $a = 'a/1/b/2';
- $b = $this->uri->assoc_to_uri($arr);
- $this->assertEquals($a, $b);
+ $this->assertEquals('a/1/b/2', $this->uri->assoc_to_uri(array('a' => '1', 'b' => '2')));
}
// --------------------------------------------------------------------
@@ -286,28 +264,18 @@ class URI_test extends CI_TestCase {
$this->uri->segments[1] = 'segment';
$this->uri->rsegments[1] = 'segment';
- $a = '/segment/';
- $b = $this->uri->slash_segment(1, 'both');
- $this->assertEquals($a, $b);
- $b = $this->uri->slash_rsegment(1, 'both');
- $this->assertEquals($a, $b);
-
+ $this->assertEquals('/segment/', $this->uri->slash_segment(1, 'both'));
+ $this->assertEquals('/segment/', $this->uri->slash_rsegment(1, 'both'));
+
$a = '/segment';
- $b = $this->uri->slash_segment(1, 'leading');
- $this->assertEquals($a, $b);
- $b = $this->uri->slash_rsegment(1, 'leading');
- $this->assertEquals($a, $b);
-
- $a = 'segment/';
- $b = $this->uri->slash_segment(1, 'trailing');
- $this->assertEquals($a, $b);
- $b = $this->uri->slash_rsegment(1, 'trailing');
- $this->assertEquals($a, $b);
- }
+ $this->assertEquals('/segment', $this->uri->slash_segment(1, 'leading'));
+ $this->assertEquals('/segment', $this->uri->slash_rsegment(1, 'leading'));
+ $this->assertEquals('segment/', $this->uri->slash_segment(1, 'trailing'));
+ $this->assertEquals('segment/', $this->uri->slash_rsegment(1, 'trailing'));
+ }
}
-// END URI_test Class
/* End of file URI_test.php */
-/* Location: ./tests/core/URI_test.php */
+/* Location: ./tests/core/URI_test.php */ \ No newline at end of file