diff --git a/app/base/functions.php b/app/base/functions.php index b5297c5d..ee84069e 100644 --- a/app/base/functions.php +++ b/app/base/functions.php @@ -43,27 +43,29 @@ function is_not_selected($a, $b) * * @return string */ - function asset_url(/*...*/) - { - global $config; +function asset_url(/*...*/) +{ + global $config; - $args = func_get_args(); - $base_url = rtrim($config->asset_path, '/'); + $args = func_get_args(); + $base_url = rtrim($config->asset_path, '/'); - array_unshift($args, $base_url); + array_unshift($args, $base_url); - return implode("/", $args); - } + return implode("/", $args); +} /** * Get the base url from the config * * @param string $type - (optional) The controller + # @param object $config - (optional) Config * @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_host = $config->{"{$type}_host"}; @@ -80,11 +82,12 @@ function base_url($type="anime") * * @param string $path - (optional) The route path * @param string $type - (optional) The controller (anime or manga), defaults to anime + # @param object $config - (optional) Config * @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_host = $config->{"{$type}_host"}; diff --git a/phpunit.xml b/phpunit.xml index aa2cbb5c..1fcb09dc 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -17,5 +17,6 @@ + \ No newline at end of file diff --git a/tests/base/FunctionsTest.php b/tests/base/FunctionsTest.php index 60a7221e..b6436448 100644 --- a/tests/base/FunctionsTest.php +++ b/tests/base/FunctionsTest.php @@ -2,6 +2,21 @@ 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 */ @@ -32,18 +47,12 @@ class FunctionsTest extends AnimeClient_TestCase { { return [ 'single argument' => [ - 'config' => (object)[ - 'asset_path' => '//localhost/assets/' - ], 'args' => [ 'images' ], 'expected' => '//localhost/assets/images', ], 'multiple arguments' => [ - 'config' => (object)[ - 'asset_path' => '//localhost/assets/' - ], 'args' => [ 'images', 'anime', 'foo.png' ], @@ -55,11 +64,8 @@ class FunctionsTest extends AnimeClient_TestCase { /** * @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); $this->assertEquals($expected, $result);