Skip to content

Commit

Permalink
Add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Dec 27, 2018
1 parent 73a7042 commit 3bc4d43
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
22 changes: 13 additions & 9 deletions src/View/Helper/UrlHelper.php
Expand Up @@ -143,17 +143,21 @@ public function script($path, array $options = [])
*
* Depending on options passed provides full URL with domain name. Also calls
* `Helper::assetTimestamp()` to add timestamp to local files.
*
* ### Options:
*
* - `fullBase` Boolean true or a string (e.g. https://example) to
* return full URL with protocol and domain name.
* - `pathPrefix` Path prefix for relative URLs
* - `ext` Asset extension to append
* - `plugin` False value will prevent parsing path as a plugin
* - `timestamp` Overrides the value of `Asset.timestamp` in Configure.
* Set to false to skip timestamp generation.
* Set to true to apply timestamps when debug is true. Set to 'force' to always
* enable timestamping regardless of debug value.
*
* @param string|array $path Path string or URL array
* @param array $options Options array. Possible keys:
* `fullBase` Return full URL with domain name. Bool or string.
* `pathPrefix` Path prefix for relative URLs
* `ext` Asset extension to append
* `plugin` False value will prevent parsing path as a plugin
* `timestamp` Overrides the value of `Asset.timestamp` in Configure.
* Set to false to skip timestamp generation.
* Set to true to apply timestamps when debug is true. Set to 'force' to always
* enable timestamping regardless of debug value.
* @param array $options Options array.
* @return string Generated URL
*/
public function assetUrl($path, array $options = [])
Expand Down
16 changes: 15 additions & 1 deletion tests/TestCase/View/Helper/UrlHelperTest.php
Expand Up @@ -290,6 +290,20 @@ public function testAssetUrlPlugin()
$this->removePlugins(['TestPlugin']);
}

/**
* Tests assetUrl() with full base URL.
*
* @return void
*/
public function testAssetUrlFullBase()
{
$result = $this->Helper->assetUrl('img/foo.jpg', ['fullBase' => true]);
$this->assertEquals(Router::fullBaseUrl() . '/img/foo.jpg', $result);

$result = $this->Helper->assetUrl('img/foo.jpg', ['fullBase' => 'https://xyz/']);
$this->assertEquals('https://xyz/img/foo.jpg', $result);
}

/**
* test assetUrl and Asset.timestamp = force
*
Expand Down Expand Up @@ -341,7 +355,7 @@ public function testAssetTimestampPluginsAndThemes()
$result = $this->Helper->assetTimestamp('/test_theme/js/non_existant.js');
$this->assertRegExp('#/test_theme/js/non_existant.js$#', $result, 'No error on missing file');
}

/**
* test script()
*
Expand Down

0 comments on commit 3bc4d43

Please sign in to comment.