/**
  * Setup new backend
  *
  * @param Requirements_Backend $backend
  */
 protected function setupRequirements($backend)
 {
     // Flush requirements
     $backend->clear();
     $backend->clearCombinedFiles();
     $backend->setCombinedFilesFolder('_combinedfiles');
     $backend->setMinifyCombinedJSFiles(false);
     Requirements::flush();
 }
 function testBlockedCombinedJavascript()
 {
     $backend = new Requirements_Backend();
     $backend->set_combined_files_enabled(true);
     $backend->setCombinedFilesFolder('assets');
     $combinedFilePath = Director::baseFolder() . '/assets/' . 'RequirementsTest_bc.js';
     /* BLOCKED COMBINED FILES ARE NOT INCLUDED */
     $this->setupCombinedRequirements($backend);
     $backend->block('RequirementsTest_bc.js');
     $backend->delete_combined_files('RequirementsTest_bc.js');
     clearstatcache();
     // needed to get accurate file_exists() results
     $html = $backend->includeInHTML(false, self::$html_template);
     $this->assertFalse((bool) preg_match('/src=".*\\/RequirementsTest_bc\\.js/', $html), 'blocked combined files are not included ');
     $backend->unblock('RequirementsTest_bc.js');
     /* BLOCKED UNCOMBINED FILES ARE NOT INCLUDED */
     $this->setupCombinedRequirements($backend);
     $backend->block('sapphire/tests/forms/RequirementsTest_b.js');
     $backend->delete_combined_files('RequirementsTest_bc.js');
     clearstatcache();
     // needed to get accurate file_exists() results
     $html = $backend->includeInHTML(false, self::$html_template);
     $this->assertFalse(strpos(file_get_contents($combinedFilePath), "alert('b')") !== false, 'blocked uncombined files are not included');
     $backend->unblock('RequirementsTest_b.js');
     /* A SINGLE FILE CAN'T BE INCLUDED IN TWO COMBINED FILES */
     $this->setupCombinedRequirements($backend);
     clearstatcache();
     // needed to get accurate file_exists() results
     // This throws a notice-level error, so we prefix with @
     @$backend->combine_files('RequirementsTest_ac.js', array('sapphire/tests/forms/RequirementsTest_a.js', 'sapphire/tests/forms/RequirementsTest_c.js'));
     $combinedFiles = $backend->get_combine_files();
     $this->assertEquals(array_keys($combinedFiles), array('RequirementsTest_bc.js'), "A single file can't be included in two combined files");
     $backend->delete_combined_files('RequirementsTest_bc.js');
 }
예제 #3
0
 function testBlockedCombinedJavascript()
 {
     $backend = new Requirements_Backend();
     $backend->set_combined_files_enabled(true);
     $backend->setCombinedFilesFolder('assets');
     $combinedFilePath = DOCROOT . '/media/uploads/' . 'RequirementsTest_bc.js';
     /* BLOCKED COMBINED FILES ARE NOT INCLUDED */
     $this->setupCombinedRequirements($backend);
     $backend->block('RequirementsTest_bc.js');
     $backend->delete_combined_files('RequirementsTest_bc.js');
     clearstatcache();
     // needed to get accurate file_exists() results
     $html = $backend->render();
     $this->assertNotContains('RequirementsTest_bc.js', $html, 'blocked combined files are not included ');
     $backend->unblock('RequirementsTest_bc.js');
     /* BLOCKED UNCOMBINED FILES ARE NOT INCLUDED */
     $this->setupCombinedRequirements($backend);
     $backend->block('tests/phpunit/data/RequirementsTest_b.js');
     $backend->delete_combined_files('RequirementsTest_bc.js');
     clearstatcache();
     // needed to get accurate file_exists() results
     $html = $backend->render();
     $combinedFileContents = @file_get_contents($combinedFilePath);
     $this->assertNotContains("alert('b')", (string) $combinedFileContents, 'blocked uncombined files are not included');
     $backend->unblock('RequirementsTest_b.js');
     /* A SINGLE FILE CAN'T BE INCLUDED IN TWO COMBINED FILES */
     $this->setupCombinedRequirements($backend);
     clearstatcache();
     // needed to get accurate file_exists() results
     // This throws a notice-level error, so we prefix with @
     @$backend->combine_files('RequirementsTest_ac.js', array('tests/phpunit/data/RequirementsTest_a.js', 'tests/phpunit/data/RequirementsTest_c.js'));
     $combinedFiles = $backend->get_combine_files();
     $this->assertEquals(array_keys($combinedFiles['js']), array('RequirementsTest_bc.js'), "A single file can't be included in two combined files");
     $backend->delete_combined_files('RequirementsTest_bc.js');
 }