Browse Source

Add test case

mscherer 7 years ago
parent
commit
3bc4d43079
2 changed files with 28 additions and 10 deletions
  1. 13 9
      src/View/Helper/UrlHelper.php
  2. 15 1
      tests/TestCase/View/Helper/UrlHelperTest.php

+ 13 - 9
src/View/Helper/UrlHelper.php

@@ -143,17 +143,21 @@ class UrlHelper extends Helper
      *
      * 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 = [])

+ 15 - 1
tests/TestCase/View/Helper/UrlHelperTest.php

@@ -291,6 +291,20 @@ class UrlHelperTest extends TestCase
     }
 
     /**
+     * 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
      *
      * @return void
@@ -341,7 +355,7 @@ class UrlHelperTest extends TestCase
         $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()
      *