public function setUp() { Config::nest(); // additional nesting here necessary Config::inst()->update('File', 'migrate_legacy_file', false); parent::setUp(); // Set backend root to /FileMigrationHelperTest/assets AssetStoreTest_SpyStore::activate('FileMigrationHelperTest/assets'); // Ensure that each file has a local record file in this new assets base $from = FRAMEWORK_PATH . '/tests/model/testimages/test-image-low-quality.jpg'; foreach (File::get()->exclude('ClassName', 'Folder') as $file) { $dest = AssetStoreTest_SpyStore::base_path() . '/' . $file->generateFilename(); SS_Filesystem::makeFolder(dirname($dest)); copy($from, $dest); } }
public function testBlockedCombinedJavascript() { $basePath = $this->getCurrentRelativePath(); $backend = Injector::inst()->create('Requirements_Backend'); $this->setupCombinedRequirements($backend); $combinedFileName = '/_combinedfiles/RequirementsTest_bc-51622b5.js'; $combinedFilePath = AssetStoreTest_SpyStore::base_path() . $combinedFileName; /* BLOCKED COMBINED FILES ARE NOT INCLUDED */ $backend->block('RequirementsTest_bc.js'); clearstatcache(); // needed to get accurate file_exists() results $html = $backend->includeInHTML(false, self::$html_template); $this->assertFileNotExists($combinedFilePath); $this->assertNotRegExp('/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($basePath . '/RequirementsTest_b.js'); $combinedFileName2 = '/_combinedfiles/RequirementsTest_bc-fc7468e.js'; // SHA1 without file c included $combinedFilePath2 = AssetStoreTest_SpyStore::base_path() . $combinedFileName2; clearstatcache(); // needed to get accurate file_exists() results $html = $backend->includeInHTML(false, self::$html_template); $this->assertFileExists($combinedFilePath2); $this->assertTrue(strpos(file_get_contents($combinedFilePath2), "alert('b')") === false, 'blocked uncombined files are not included'); $backend->unblock($basePath . '/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 // Exception generated from including invalid file $this->setExpectedException('InvalidArgumentException', sprintf("Requirements_Backend::combine_files(): Already included file(s) %s in combined file '%s'", $basePath . '/RequirementsTest_c.js', 'RequirementsTest_bc.js')); $backend->combineFiles('RequirementsTest_ac.js', array($basePath . '/RequirementsTest_a.js', $basePath . '/RequirementsTest_c.js')); }
/** * Test fallback to file generation API with enable_static_file disabled */ public function testGeneratedFile() { Config::inst()->update('ErrorPage', 'enable_static_file', false); $this->logInWithPermission('ADMIN'); $page = new ErrorPage(); $page->ErrorCode = 405; $page->Title = 'Method Not Allowed'; $page->write(); $page->doPublish(); // Dynamic content is available $response = ErrorPage::response_for('405'); $this->assertNotEmpty($response); $this->assertNotEmpty($response->getBody()); $this->assertEquals(405, (int) $response->getStatusCode()); // Static content is not available $this->assertEmpty(ErrorPage::get_content_for_errorcode('405')); $expectedErrorPagePath = AssetStoreTest_SpyStore::base_path() . '/error-405.html'; $this->assertFileNotExists($expectedErrorPagePath, 'Error page is not cached in static location'); }
/** * Test fallback to file generation API with enable_static_file disabled */ public function testGeneratedFile() { Config::inst()->update('ErrorPage', 'enable_static_file', false); $this->logInWithPermission('ADMIN'); $page = new ErrorPage(); $page->ErrorCode = 405; $page->Title = 'Method Not Allowed'; $page->write(); $page->doPublish(); // Error content is available, even though the static file does not exist (only in assetstore) $this->assertNotEmpty(ErrorPage::get_content_for_errorcode('405')); $expectedErrorPagePath = AssetStoreTest_SpyStore::base_path() . '/error-405.html'; $this->assertFileNotExists($expectedErrorPagePath, 'Error page is not cached in static location'); }