Browse Source

Merge pull request #11310 from makallio85/master

Error supressing is causing problems with asset files inside plugin
Mark Story 8 years ago
parent
commit
17921aaebd
2 changed files with 8 additions and 6 deletions
  1. 6 4
      src/View/Helper/UrlHelper.php
  2. 2 2
      tests/TestCase/View/Helper/UrlHelperTest.php

+ 6 - 4
src/View/Helper/UrlHelper.php

@@ -210,7 +210,7 @@ class UrlHelper extends Helper
             $webrootPath = WWW_ROOT . str_replace('/', DIRECTORY_SEPARATOR, $filepath);
             if (file_exists($webrootPath)) {
                 //@codingStandardsIgnoreStart
-                return $path . '?' . @filemtime($webrootPath);
+                return $path . '?' . filemtime($webrootPath);
                 //@codingStandardsIgnoreEnd
             }
             $segments = explode('/', ltrim($filepath, '/'));
@@ -218,9 +218,11 @@ class UrlHelper extends Helper
             if (Plugin::loaded($plugin)) {
                 unset($segments[0]);
                 $pluginPath = Plugin::path($plugin) . 'webroot' . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $segments);
-                //@codingStandardsIgnoreStart
-                return $path . '?' . @filemtime($pluginPath);
-                //@codingStandardsIgnoreEnd
+                if (file_exists($pluginPath)) {
+                    //@codingStandardsIgnoreStart
+                    return $path . '?' . filemtime($pluginPath);
+                    //@codingStandardsIgnoreEnd4
+                }
             }
         }
 

+ 2 - 2
tests/TestCase/View/Helper/UrlHelperTest.php

@@ -269,13 +269,13 @@ class UrlHelperTest extends TestCase
         $this->assertRegExp('#/test_plugin/css/test_plugin_asset.css\?[0-9]+$#', $result, 'Missing timestamp plugin');
 
         $result = $this->Helper->assetTimestamp('/test_plugin/css/i_dont_exist.css');
-        $this->assertRegExp('#/test_plugin/css/i_dont_exist.css\?$#', $result, 'No error on missing file');
+        $this->assertRegExp('#/test_plugin/css/i_dont_exist.css$#', $result, 'No error on missing file');
 
         $result = $this->Helper->assetTimestamp('/test_theme/js/theme.js');
         $this->assertRegExp('#/test_theme/js/theme.js\?[0-9]+$#', $result, 'Missing timestamp theme');
 
         $result = $this->Helper->assetTimestamp('/test_theme/js/non_existant.js');
-        $this->assertRegExp('#/test_theme/js/non_existant.js\?$#', $result, 'No error on missing file');
+        $this->assertRegExp('#/test_theme/js/non_existant.js$#', $result, 'No error on missing file');
     }
 
     /**