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,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"};

View File

@ -17,5 +17,6 @@
</testsuites>
<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_HOST" value="localhost" />
</php>
</phpunit>

View File

@ -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);