Fix some broken tests

This commit is contained in:
Timothy Warren 2015-06-26 13:24:55 -04:00
parent 0c73343291
commit 0099d4f5ec
3 changed files with 32 additions and 22 deletions

View File

@ -43,8 +43,8 @@ function is_not_selected($a, $b)
* *
* @return string * @return string
*/ */
function asset_url(/*...*/) function asset_url(/*...*/)
{ {
global $config; global $config;
$args = func_get_args(); $args = func_get_args();
@ -53,17 +53,19 @@ function is_not_selected($a, $b)
array_unshift($args, $base_url); array_unshift($args, $base_url);
return implode("/", $args); return implode("/", $args);
} }
/** /**
* Get the base url from the config * Get the base url from the config
* *
* @param string $type - (optional) The controller * @param string $type - (optional) The controller
# @param object $config - (optional) Config
* @return string * @return string
*/ */
function base_url($type="anime") function base_url($type="anime", $config=NULL)
{ {
global $config; if (is_null($config)) global $config;
$config_path = trim($config->{"{$type}_path"}, "/"); $config_path = trim($config->{"{$type}_path"}, "/");
$config_host = $config->{"{$type}_host"}; $config_host = $config->{"{$type}_host"};
@ -80,11 +82,12 @@ function base_url($type="anime")
* *
* @param string $path - (optional) The route path * @param string $path - (optional) The route path
* @param string $type - (optional) The controller (anime or manga), defaults to anime * @param string $type - (optional) The controller (anime or manga), defaults to anime
# @param object $config - (optional) Config
* @return string * @return string
*/ */
function full_url($path="", $type="anime") function full_url($path="", $type="anime", $config=NULL)
{ {
global $config; if (is_null($config)) global $config;
$config_path = trim($config->{"{$type}_path"}, "/"); $config_path = trim($config->{"{$type}_path"}, "/");
$config_host = $config->{"{$type}_host"}; $config_host = $config->{"{$type}_host"};

View File

@ -17,5 +17,6 @@
</testsuites> </testsuites>
<php> <php>
<server name="HTTP_USER_AGENT" value="Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Firefox/38.0" /> <server name="HTTP_USER_AGENT" value="Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Firefox/38.0" />
<server name="HTTP_HOST" value="localhost" />
</php> </php>
</phpunit> </phpunit>

View File

@ -2,6 +2,21 @@
class FunctionsTest extends AnimeClient_TestCase { class FunctionsTest extends AnimeClient_TestCase {
public function setUp()
{
parent::setUp();
global $config;
$config = new Config([
'config' => [
'asset_path' => '//localhost/assets/'
],
'base_config' => [
]
]);
}
/** /**
* Basic sanity test for _dir function * Basic sanity test for _dir function
*/ */
@ -32,18 +47,12 @@ class FunctionsTest extends AnimeClient_TestCase {
{ {
return [ return [
'single argument' => [ 'single argument' => [
'config' => (object)[
'asset_path' => '//localhost/assets/'
],
'args' => [ 'args' => [
'images' 'images'
], ],
'expected' => '//localhost/assets/images', 'expected' => '//localhost/assets/images',
], ],
'multiple arguments' => [ 'multiple arguments' => [
'config' => (object)[
'asset_path' => '//localhost/assets/'
],
'args' => [ 'args' => [
'images', 'anime', 'foo.png' 'images', 'anime', 'foo.png'
], ],
@ -55,11 +64,8 @@ class FunctionsTest extends AnimeClient_TestCase {
/** /**
* @dataProvider assetUrlProvider * @dataProvider assetUrlProvider
*/ */
public function testAssetUrl($config, $args, $expected) public function testAssetUrl($args, $expected)
{ {
global $config;
$config = func_get_arg(0);
$result = call_user_func_array('asset_url', $args); $result = call_user_func_array('asset_url', $args);
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);