8000 Fixing a double slash bug in URL generation with languages. add tests. · allforweb/laravel@4e21cfc · GitHub
[go: up one dir, main page]

Skip to content

Commit 4e21cfc

Browse files
committed
Fixing a double slash bug in URL generation with languages. add tests.
1 parent cfe5fa1 commit 4e21cfc

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

laravel/tests/cases/url.test.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ public function testToAssetGeneratesURLWithoutFrontControllerInURL()
8484
Request::foundation()->server->add(array('HTTPS' => 'on'));
8585

8686
$this->assertEquals('https://localhost/image.jpg', URL::to_asset('image.jpg'));
87+
88+
Request::foundation()->server->add(array('HTTPS' => 'off'));
8789
}
8890

8991
/**
@@ -103,4 +105,26 @@ public function testToRouteMethodGeneratesURLsToRoutes()
103105
$this->assertEquals('http://localhost/index.php/url/test/taylor/otwell', URL::to_route('url-test-2', array('taylor', 'otwell')));
104106
}
105107

108+
109+
/**
110+
* Test language based URL generation.
111+
*
112+
* @group laravel
113+
*/
114+
public function testUrlsGeneratedWithLanguages()
115+
{
116+
Config::set('application.languages', array('sp', 'fr'));
117+
Config::set('application.language', 'sp');
118+
$this->assertEquals('http://localhost/index.php/sp/foo', URL::to('foo'));
119+
$this->assertEquals('http://localhost/foo.jpg', URL::to_asset('foo.jpg'));
120+
121+
Config::set('application.index', '');
122+
$this->assertEquals('http://localhost/sp/foo', URL::to('foo'));
123+
124+
Config::set('application.index', 'index.php');
125+
Config::set('application.language', 'en');
126+
$this->assertEquals('http://localhost/index.php/foo', URL::to('foo'));
127+
Config::set('application.languages', array());
128+
}
129+
106130
}

laravel/url.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,14 @@ public static function to($url = '', $https = null, $asset = false, $locale = tr
114114
$root .= '/'.Config::get('application.index');
115115
}
116116

117-
if ( ! $asset and $locale and count(Config::get('application.languages')) > 0)
117+
$languages = Config::get('application.languages');
118+
119+
if ( ! $asset and $locale and count($languages) > 0)
118120
{
119-
$root .= '/'.Config::get('application.language');
121+
if (in_array($default = Config::get('application.language'), $languages))
122+
{
123+
$root = rtrim($root, '/').'/'.$default;
124+
}
120125
}
121126

122127
// Since SSL is not often used while developing the application, we allow the

phpunit.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<phpunit colors="true"
2+
bootstrap="/Users/taylor/Code/Laravel/framework/laravel/tests/phpunit.php"
3+
backupGlobals="false">
4+
<testsuites>
5+
<testsuite name="Test Suite">
6+
<directory suffix=".test.php">/Users/taylor/Code/Laravel/framework/laravel/tests/cases</directory>
7+
</testsuite>
8+
</testsuites>
9+
</phpunit>

0 commit comments

Comments
 (0)
0