mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
API Change: Turned Requirements::clear_combined_files() into Requirements::delete_combined_files() and Requirements::clear_combined_files()
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@60431 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
72b9d12aae
commit
4258361337
@ -436,12 +436,11 @@ class Requirements {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes all dynamically generated combined files
|
* Deletes all dynamically generated combined files from the filesystem.
|
||||||
* from the filesystem.
|
|
||||||
*
|
*
|
||||||
* @param string $combinedFileName If left blank, all combined files are deleted.
|
* @param string $combinedFileName If left blank, all combined files are deleted.
|
||||||
*/
|
*/
|
||||||
static function clear_combined_files($combinedFileName = null) {
|
static function delete_combined_files($combinedFileName = null) {
|
||||||
$combinedFiles = ($combinedFileName) ? array($combinedFileName => null) : self::$combine_files;
|
$combinedFiles = ($combinedFileName) ? array($combinedFileName => null) : self::$combine_files;
|
||||||
foreach($combinedFiles as $combinedFile => $sourceItems) {
|
foreach($combinedFiles as $combinedFile => $sourceItems) {
|
||||||
$filePath = Director::baseFolder() . '/' . $combinedFile;
|
$filePath = Director::baseFolder() . '/' . $combinedFile;
|
||||||
@ -451,6 +450,13 @@ class Requirements {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Re-sets the combined files definition
|
||||||
|
*/
|
||||||
|
static function clear_combined_files() {
|
||||||
|
self::$combine_files = array();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See {@link combine_files()}.
|
* See {@link combine_files()}.
|
||||||
*/
|
*/
|
||||||
|
@ -60,7 +60,7 @@ class RequirementsTest extends SapphireTest {
|
|||||||
/* NORMAL REQUIREMENTS ARE STILL INCLUDED */
|
/* NORMAL REQUIREMENTS ARE STILL INCLUDED */
|
||||||
$this->assertTrue((bool)preg_match('/src=".*\/a\.js/', $html), 'normal requirements are still included');
|
$this->assertTrue((bool)preg_match('/src=".*\/a\.js/', $html), 'normal requirements are still included');
|
||||||
|
|
||||||
Requirements::clear_combined_files('bc.js');
|
Requirements::delete_combined_files('bc.js');
|
||||||
}
|
}
|
||||||
|
|
||||||
function testBlockedCombinedJavascript() {
|
function testBlockedCombinedJavascript() {
|
||||||
@ -69,7 +69,7 @@ class RequirementsTest extends SapphireTest {
|
|||||||
/* BLOCKED COMBINED FILES ARE NOT INCLUDED */
|
/* BLOCKED COMBINED FILES ARE NOT INCLUDED */
|
||||||
$this->setupCombinedRequirements();
|
$this->setupCombinedRequirements();
|
||||||
Requirements::block('bc.js');
|
Requirements::block('bc.js');
|
||||||
Requirements::clear_combined_files('bc.js');
|
Requirements::delete_combined_files('bc.js');
|
||||||
|
|
||||||
clearstatcache(); // needed to get accurate file_exists() results
|
clearstatcache(); // needed to get accurate file_exists() results
|
||||||
$html = Requirements::includeInHTML(false, self::$html_template);
|
$html = Requirements::includeInHTML(false, self::$html_template);
|
||||||
@ -82,7 +82,7 @@ class RequirementsTest extends SapphireTest {
|
|||||||
// original arrays grml...
|
// original arrays grml...
|
||||||
$this->setupCombinedRequirements();
|
$this->setupCombinedRequirements();
|
||||||
Requirements::block('sapphire/tests/forms/b.js');
|
Requirements::block('sapphire/tests/forms/b.js');
|
||||||
Requirements::clear_combined_files('bc.js');
|
Requirements::delete_combined_files('bc.js');
|
||||||
clearstatcache(); // needed to get accurate file_exists() results
|
clearstatcache(); // needed to get accurate file_exists() results
|
||||||
$html = Requirements::includeInHTML(false, self::$html_template);
|
$html = Requirements::includeInHTML(false, self::$html_template);
|
||||||
$this->assertFalse((strpos(file_get_contents($combinedFilePath), "alert('b')") !== false), 'blocked uncombined files are not included');
|
$this->assertFalse((strpos(file_get_contents($combinedFilePath), "alert('b')") !== false), 'blocked uncombined files are not included');
|
||||||
@ -91,13 +91,16 @@ class RequirementsTest extends SapphireTest {
|
|||||||
/* A SINGLE FILE CAN'T BE INCLUDED IN TWO COMBINED FILES */
|
/* A SINGLE FILE CAN'T BE INCLUDED IN TWO COMBINED FILES */
|
||||||
$this->setupCombinedRequirements();
|
$this->setupCombinedRequirements();
|
||||||
clearstatcache(); // needed to get accurate file_exists() results
|
clearstatcache(); // needed to get accurate file_exists() results
|
||||||
Requirements::combine_files(
|
|
||||||
|
// This throws a notice-level error, so we prefix with @
|
||||||
|
@Requirements::combine_files(
|
||||||
'ac.js',
|
'ac.js',
|
||||||
array(
|
array(
|
||||||
'sapphire/tests/forms/a.js',
|
'sapphire/tests/forms/a.js',
|
||||||
'sapphire/tests/forms/c.js'
|
'sapphire/tests/forms/c.js'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$combinedFiles = Requirements::get_combine_files();
|
$combinedFiles = Requirements::get_combine_files();
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array_keys($combinedFiles),
|
array_keys($combinedFiles),
|
||||||
@ -105,7 +108,7 @@ class RequirementsTest extends SapphireTest {
|
|||||||
"A single file can't be included in two combined files"
|
"A single file can't be included in two combined files"
|
||||||
);
|
);
|
||||||
|
|
||||||
Requirements::clear_combined_files('bc.js');
|
Requirements::delete_combined_files('bc.js');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -118,7 +121,8 @@ class RequirementsTest extends SapphireTest {
|
|||||||
Requirements::clear();
|
Requirements::clear();
|
||||||
|
|
||||||
// clearing all previously generated requirements (just in case)
|
// clearing all previously generated requirements (just in case)
|
||||||
Requirements::clear_combined_files('bc.js');
|
Requirements::clear_combined_files();
|
||||||
|
Requirements::delete_combined_files('bc.js');
|
||||||
|
|
||||||
// require files normally (e.g. called from a FormField instance)
|
// require files normally (e.g. called from a FormField instance)
|
||||||
Requirements::javascript('sapphire/tests/forms/a.js');
|
Requirements::javascript('sapphire/tests/forms/a.js');
|
||||||
@ -133,7 +137,6 @@ class RequirementsTest extends SapphireTest {
|
|||||||
'sapphire/tests/forms/c.js'
|
'sapphire/tests/forms/c.js'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user