logInWithPermission('ADMIN'); // Write file contents $files = File::get()->exclude('ClassName', 'Folder'); foreach($files as $file) { $destPath = AssetStoreTest_SpyStore::getLocalPath($file); Filesystem::makeFolder(dirname($destPath)); file_put_contents($destPath, str_repeat('x', 1000000)); } // Since we can't hard-code IDs, manually inject image tracking shortcode $imageID = $this->idFromFixture('Image', 'file1'); $page = $this->objFromFixture('Page', 'page1'); $page->Content = sprintf( '
', $imageID ); $page->write(); } public function tearDown() { AssetStoreTest_SpyStore::reset(); parent::tearDown(); } public function testFileRenameUpdatesDraftAndPublishedPages() { $page = $this->objFromFixture('Page', 'page1'); $this->assertTrue($page->doPublish()); $this->assertContains( 'ID))->value() ); $file = $this->objFromFixture('Image', 'file1'); $file->Name = 'renamed-test-file.jpg'; $file->write(); $this->assertContains( 'ID))->value() ); $this->assertContains( 'ID))->value() ); } public function testFileLinkRewritingOnVirtualPages() { // Publish the source page $page = $this->objFromFixture('Page', 'page1'); $this->assertTrue($page->doPublish()); // Create a virtual page from it, and publish that $svp = new VirtualPage(); $svp->CopyContentFromID = $page->ID; $svp->write(); $svp->doPublish(); // Rename the file $file = $this->objFromFixture('Image', 'file1'); $file->Name = 'renamed-test-file.jpg'; $file->write(); // Verify that the draft and publish virtual pages both have the corrected link $this->assertContains( 'ID))->value() ); $this->assertContains( 'ID))->value() ); } public function testLinkRewritingOnAPublishedPageDoesntMakeItEditedOnDraft() { // Publish the source page $page = $this->objFromFixture('Page', 'page1'); $this->assertTrue($page->doPublish()); $this->assertFalse($page->getIsModifiedOnStage()); // Rename the file $file = $this->objFromFixture('Image', 'file1'); $file->Name = 'renamed-test-file.jpg'; $file->write(); // Caching hack Versioned::prepopulate_versionnumber_cache('SiteTree', 'Stage', array($page->ID)); Versioned::prepopulate_versionnumber_cache('SiteTree', 'Live', array($page->ID)); // Confirm that the page hasn't gone green. $this->assertFalse($page->getIsModifiedOnStage()); } public function testTwoFileRenamesInARowWork() { $page = $this->objFromFixture('Page', 'page1'); $this->assertTrue($page->doPublish()); $this->assertContains( 'ID))->value()); // Rename the file twice $file = $this->objFromFixture('Image', 'file1'); $file->Name = 'renamed-test-file.jpg'; $file->write(); // TODO Workaround for bug in DataObject->getChangedFields(), which returns stale data, // and influences File->updateFilesystem() $file = DataObject::get_by_id('File', $file->ID); $file->Name = 'renamed-test-file-second-time.jpg'; $file->write(); // Confirm that the correct image is shown in both the draft and live site $this->assertContains( 'ID))->value() ); $this->assertContains( 'ID))->value() ); } }