mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
ENHANCEMENT: in referencing a file in combine_files() it should fall back to standard requirement tags if combining has been disabled eg dev mode (from r107091)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112549 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
fbbe0b4b39
commit
25a0c3e7fb
@ -840,6 +840,45 @@ class Requirements_Backend {
|
||||
}
|
||||
}
|
||||
|
||||
foreach($files as $index=>$file) {
|
||||
if(is_array($file)) {
|
||||
// Either associative array path=>path type=>type or numeric 0=>path 1=>type
|
||||
// Otherwise, assume path is the first item
|
||||
if (isset($file['type']) && ($file['type'] == 'css' || $file['type'] == 'javascript' || $file['type'] == 'js')) {
|
||||
switch ($file['type']) {
|
||||
case 'css':
|
||||
$this->css($file['path']);
|
||||
break;
|
||||
default:
|
||||
$this->javascript($file['path']);
|
||||
break;
|
||||
}
|
||||
$files[$index] = $file['path'];
|
||||
} elseif (isset($file[1]) && ($file[1] == 'css' || $file[1] == 'javascript' || $file[1] == 'js')) {
|
||||
switch ($file[1]) {
|
||||
case 'css':
|
||||
$this->css($file[0]);
|
||||
break;
|
||||
default:
|
||||
$this->javascript($file[0]);
|
||||
break;
|
||||
}
|
||||
$files[$index] = $file[0];
|
||||
} else {
|
||||
$file = array_shift($file);
|
||||
}
|
||||
}
|
||||
if (!is_array($file)) {
|
||||
if(substr($file, -2) == 'js') {
|
||||
$this->javascript($file);
|
||||
} elseif(substr($file, -3) == 'css') {
|
||||
$this->css($file);
|
||||
} else {
|
||||
user_error("Requirements_Backend::combine_files(): Couldn't guess file type for file '$file', please specify by passing using an array instead.", E_USER_NOTICE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->combine_files[$combinedFileName] = $files;
|
||||
}
|
||||
|
||||
|
@ -63,6 +63,24 @@ class RequirementsTest extends SapphireTest {
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
protected function setupCombinedNonrequiredRequirements($backend) {
|
||||
$backend->clear();
|
||||
$backend->setCombinedFilesFolder('assets');
|
||||
|
||||
// clearing all previously generated requirements (just in case)
|
||||
$backend->clear_combined_files();
|
||||
$backend->delete_combined_files('RequirementsTest_bc.js');
|
||||
|
||||
// require files as combined includes
|
||||
$backend->combine_files(
|
||||
'RequirementsTest_bc.js',
|
||||
array(
|
||||
SAPPHIRE_DIR . '/tests/forms/RequirementsTest_b.js',
|
||||
SAPPHIRE_DIR . '/tests/forms/RequirementsTest_c.js'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function testCombinedJavascript() {
|
||||
$backend = new Requirements_Backend;
|
||||
@ -93,6 +111,33 @@ class RequirementsTest extends SapphireTest {
|
||||
$this->assertTrue((bool)preg_match('/src=".*\/RequirementsTest_a\.js/', $html), 'normal requirements are still included');
|
||||
|
||||
$backend->delete_combined_files('RequirementsTest_bc.js');
|
||||
|
||||
// Then do it again, this time not requiring the files beforehand
|
||||
$backend = new Requirements_Backend;
|
||||
$backend->set_combined_files_enabled(true);
|
||||
$backend->setCombinedFilesFolder('assets');
|
||||
|
||||
$this->setupCombinedNonrequiredRequirements($backend);
|
||||
|
||||
$combinedFilePath = Director::baseFolder() . '/assets/' . 'RequirementsTest_bc.js';
|
||||
|
||||
$html = $backend->includeInHTML(false, self::$html_template);
|
||||
|
||||
/* COMBINED JAVASCRIPT FILE IS INCLUDED IN HTML HEADER */
|
||||
$this->assertTrue((bool)preg_match('/src=".*\/RequirementsTest_bc\.js/', $html), 'combined javascript file is included in html header');
|
||||
|
||||
/* COMBINED JAVASCRIPT FILE EXISTS */
|
||||
$this->assertTrue(file_exists($combinedFilePath), 'combined javascript file exists');
|
||||
|
||||
/* COMBINED JAVASCRIPT HAS CORRECT CONTENT */
|
||||
$this->assertTrue((strpos(file_get_contents($combinedFilePath), "alert('b')") !== false), 'combined javascript has correct content');
|
||||
$this->assertTrue((strpos(file_get_contents($combinedFilePath), "alert('c')") !== false), 'combined javascript has correct content');
|
||||
|
||||
/* COMBINED FILES ARE NOT INCLUDED TWICE */
|
||||
$this->assertFalse((bool)preg_match('/src=".*\/RequirementsTest_b\.js/', $html), 'combined files are not included twice');
|
||||
$this->assertFalse((bool)preg_match('/src=".*\/RequirementsTest_c\.js/', $html), 'combined files are not included twice');
|
||||
|
||||
$backend->delete_combined_files('RequirementsTest_bc.js');
|
||||
}
|
||||
|
||||
function testBlockedCombinedJavascript() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user