/usr/share/php/kohana3.2/system/tests/kohana/URLTest.php is in libkohana3.2-core-php 3.2.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | <?php defined('SYSPATH') OR die('Kohana bootstrap needs to be included before tests run');
/**
* Tests URL
*
* @group kohana
* @group kohana.core
* @group kohana.core.url
*
* @package Kohana
* @category Tests
* @author Kohana Team
* @author BRMatt <matthew@sigswitch.com>
* @copyright (c) 2008-2012 Kohana Team
* @license http://kohanaframework.org/license
*/
class Kohana_URLTest extends Unittest_TestCase
{
/**
* Default values for the environment, see setEnvironment
* @var array
*/
protected $environmentDefault = array(
'Kohana::$base_url' => '/kohana/',
'Kohana::$index_file'=> 'index.php',
'HTTP_HOST' => 'example.com',
'_GET' => array(),
);
/**
* Provides test data for test_base()
*
* @return array
*/
public function provider_base()
{
return array(
// $protocol, $index, $expected, $enviroment
// Test with different combinations of parameters for max code coverage
array(NULL, FALSE, '/kohana/'),
array('http', FALSE, 'http://example.com/kohana/'),
array(NULL, TRUE, '/kohana/index.php/'),
array(NULL, TRUE, '/kohana/index.php/'),
array('http', TRUE, 'http://example.com/kohana/index.php/'),
array('https', TRUE, 'https://example.com/kohana/index.php/'),
array('ftp', TRUE, 'ftp://example.com/kohana/index.php/'),
// Test for automatic protocol detection, protocol = TRUE
array(TRUE, TRUE, 'cli://example.com/kohana/index.php/', array('HTTPS' => FALSE, 'Request::$initial' => Request::factory('/')->protocol('cli'))),
// Change base url'
array('https', FALSE, 'https://example.com/kohana/', array('Kohana::$base_url' => 'omglol://example.com/kohana/')),
// Use port in base url, issue #3307
array('http', FALSE, 'http://example.com:8080/', array('Kohana::$base_url' => 'example.com:8080/')),
// Use protocol from base url if none specified
array(NULL, FALSE, 'http://www.example.com/', array('Kohana::$base_url' => 'http://www.example.com/')),
// Use HTTP_HOST before SERVER_NAME
array('http', FALSE, 'http://example.com/kohana/', array('HTTP_HOST' => 'example.com', 'SERVER_NAME' => 'example.org')),
// Use SERVER_NAME if HTTP_HOST DNX
array('http', FALSE, 'http://example.org/kohana/', array('HTTP_HOST' => NULL, 'SERVER_NAME' => 'example.org')),
);
}
/**
* Tests URL::base()
*
* @test
* @dataProvider provider_base
* @param boolean $protocol Parameter for Url::base()
* @param boolean $index Parameter for Url::base()
* @param string $expected Expected url
* @param array $enviroment Array of enviroment vars to change @see Kohana_URLTest::setEnvironment()
*/
public function test_base($protocol, $index, $expected, array $enviroment = array())
{
$this->setEnvironment($enviroment);
$this->assertSame(
$expected,
URL::base($protocol, $index)
);
}
/**
* Provides test data for test_site()
*
* @return array
*/
public function provider_site()
{
return array(
array('', NULL, '/kohana/index.php/'),
array('', 'http', 'http://example.com/kohana/index.php/'),
array('my/site', NULL, '/kohana/index.php/my/site'),
array('my/site', 'http', 'http://example.com/kohana/index.php/my/site'),
// @ticket #3110
array('my/site/page:5', NULL, '/kohana/index.php/my/site/page:5'),
array('my/site/page:5', 'http', 'http://example.com/kohana/index.php/my/site/page:5'),
array('my/site?var=asd&kohana=awesome', NULL, '/kohana/index.php/my/site?var=asd&kohana=awesome'),
array('my/site?var=asd&kohana=awesome', 'http', 'http://example.com/kohana/index.php/my/site?var=asd&kohana=awesome'),
array('?kohana=awesome&life=good', NULL, '/kohana/index.php/?kohana=awesome&life=good'),
array('?kohana=awesome&life=good', 'http', 'http://example.com/kohana/index.php/?kohana=awesome&life=good'),
array('?kohana=awesome&life=good#fact', NULL, '/kohana/index.php/?kohana=awesome&life=good#fact'),
array('?kohana=awesome&life=good#fact', 'http', 'http://example.com/kohana/index.php/?kohana=awesome&life=good#fact'),
array('some/long/route/goes/here?kohana=awesome&life=good#fact', NULL, '/kohana/index.php/some/long/route/goes/here?kohana=awesome&life=good#fact'),
array('some/long/route/goes/here?kohana=awesome&life=good#fact', 'http', 'http://example.com/kohana/index.php/some/long/route/goes/here?kohana=awesome&life=good#fact'),
array('/route/goes/here?kohana=awesome&life=good#fact', 'https', 'https://example.com/kohana/index.php/route/goes/here?kohana=awesome&life=good#fact'),
array('/route/goes/here?kohana=awesome&life=good#fact', 'ftp', 'ftp://example.com/kohana/index.php/route/goes/here?kohana=awesome&life=good#fact'),
);
}
/**
* Tests URL::site()
*
* @test
* @dataProvider provider_site
* @param string $uri URI to use
* @param boolean|string $protocol Protocol to use
* @param string $expected Expected result
* @param array $enviroment Array of enviroment vars to set
*/
public function test_site($uri, $protocol, $expected, array $enviroment = array())
{
$this->setEnvironment($enviroment);
$this->assertSame(
$expected,
URL::site($uri, $protocol)
);
}
/**
* Provides test data for test_site_url_encode_uri()
* See issue #2680
*
* @return array
*/
public function provider_site_url_encode_uri()
{
$provider = array(
array('test', 'encode'),
array('test', 'éñçø∂ë∂'),
array('†é߆', 'encode'),
array('†é߆', 'éñçø∂ë∂', 'µåñ¥'),
);
foreach ($provider as $i => $params)
{
// Every non-ASCII character except for forward slash should be encoded...
$expected = implode('/', array_map('rawurlencode', $params));
// ... from a URI that is not encoded
$uri = implode('/', $params);
$provider[$i] = array("/kohana/index.php/{$expected}", $uri);
}
return $provider;
}
/**
* Tests URL::site for proper URL encoding when working with non-ASCII characters.
*
* @test
* @dataProvider provider_site_url_encode_uri
*/
public function test_site_url_encode_uri($expected, $uri)
{
$this->assertSame($expected, URL::site($uri, FALSE));
}
/**
* Provides test data for test_title()
* @return array
*/
public function provider_title()
{
return array(
// Tests that..
// Title is converted to lowercase
array('we-shall-not-be-moved', 'WE SHALL NOT BE MOVED', '-'),
// Excessive white space is removed and replaced with 1 char
array('thissssss-is-it', 'THISSSSSS IS IT ', '-'),
// separator is either - (dash) or _ (underscore) & others are converted to underscores
array('some-title', 'some title', '-'),
array('some_title', 'some title', '_'),
array('some!title', 'some title', '!'),
array('some:title', 'some title', ':'),
// Numbers are preserved
array('99-ways-to-beat-apple', '99 Ways to beat apple', '-'),
// ... with lots of spaces & caps
array('99_ways_to_beat_apple', '99 ways TO beat APPLE', '_'),
array('99-ways-to-beat-apple', '99 ways TO beat APPLE', '-'),
// Invalid characters are removed
array('each-gbp-is-now-worth-32-usd', 'Each GBP(£) is now worth 32 USD($)', '-'),
// ... inc. separator
array('is-it-reusable-or-re-usable', 'Is it reusable or re-usable?', '-'),
// Doing some crazy UTF8 tests
array('espana-wins', 'España-wins', '-', TRUE),
);
}
/**
* Tests URL::title()
*
* @test
* @dataProvider provider_title
* @param string $title Input to convert
* @param string $separator Seperate to replace invalid characters with
* @param string $expected Expected result
*/
public function test_title($expected, $title, $separator, $ascii_only = FALSE)
{
$this->assertSame(
$expected,
URL::title($title, $separator, $ascii_only)
);
}
/**
* Provides test data for URL::query()
* @return array
*/
public function provider_query()
{
return array(
array(array(), '', NULL),
array(array('_GET' => array('test' => 'data')), '?test=data', NULL),
array(array(), '?test=data', array('test' => 'data')),
array(array('_GET' => array('more' => 'data')), '?more=data&test=data', array('test' => 'data')),
array(array('_GET' => array('sort' => 'down')), '?test=data', array('test' => 'data'), FALSE),
// http://dev.kohanaframework.org/issues/3362
array(array(), '', array('key' => NULL)),
array(array(), '?key=0', array('key' => FALSE)),
array(array(), '?key=1', array('key' => TRUE)),
array(array('_GET' => array('sort' => 'down')), '?sort=down&key=1', array('key' => TRUE)),
array(array('_GET' => array('sort' => 'down')), '?sort=down&key=0', array('key' => FALSE)),
// @issue 4240
array(array('_GET' => array('foo' => array('a' => 100))), '?foo%5Ba%5D=100&foo%5Bb%5D=bar', array('foo' => array('b' => 'bar'))),
array(array('_GET' => array('a' => 'a')), '?a=b', array('a' => 'b')),
);
}
/**
* Tests URL::query()
*
* @test
* @dataProvider provider_query
* @param array $enviroment Set environment
* @param string $expected Expected result
* @param array $params Query string
* @param boolean $use_get Combine with GET parameters
*/
public function test_query($enviroment, $expected, $params, $use_get = TRUE)
{
$this->setEnvironment($enviroment);
$this->assertSame(
$expected,
URL::query($params, $use_get)
);
}
}
|