logInWithPermission('ADMIN'); // Write file contents $files = File::get()->exclude('ClassName', 'SilverStripe\\Assets\\Folder'); foreach ($files as $file) { $destPath = TestAssetStore::getLocalPath($file); Filesystem::makeFolder(dirname($destPath)); file_put_contents($destPath, str_repeat('x', 1000000)); } } public function tearDown() { TestAssetStore::reset(); parent::tearDown(); } public function testLinkTracking() { $sitetree = $this->objFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'home'); $editor = new HTMLEditorField('Content'); $aboutID = $this->idFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'about'); $contactID = $this->idFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'contact'); $editor->setValue("Example Link"); $editor->saveInto($sitetree); $sitetree->write(); $this->assertEquals(array($aboutID => $aboutID), $sitetree->LinkTracking()->getIdList(), 'Basic link tracking works.'); $editor->setValue( "" ); $editor->saveInto($sitetree); $sitetree->write(); $this->assertEquals( array($aboutID => $aboutID, $contactID => $contactID), $sitetree->LinkTracking()->getIdList(), 'Tracking works on multiple links' ); $editor->setValue(null); $editor->saveInto($sitetree); $sitetree->write(); $this->assertEquals(array(), $sitetree->LinkTracking()->getIdList(), 'Link tracking is removed when links are.'); // Legacy support - old CMS versions added link shortcodes with spaces instead of commas $editor->setValue("Example Link"); $editor->saveInto($sitetree); $sitetree->write(); $this->assertEquals( array($aboutID => $aboutID), $sitetree->LinkTracking()->getIdList(), 'Link tracking with space instead of comma in shortcode works.' ); } public function testFileLinkTracking() { $sitetree = $this->objFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'home'); $editor = new HTMLEditorField('Content'); $fileID = $this->idFromFixture('SilverStripe\\Assets\\File', 'example_file'); $editor->setValue(sprintf( '
', $fileID )); $editor->saveInto($sitetree); $sitetree->write(); $this->assertEquals( array($fileID => $fileID), $sitetree->ImageTracking()->getIDList(), 'Links to assets are tracked.' ); $editor->setValue(null); $editor->saveInto($sitetree); $sitetree->write(); $this->assertEquals(array(), $sitetree->ImageTracking()->getIdList(), 'Asset tracking is removed with links.'); // Legacy support - old CMS versions added link shortcodes with spaces instead of commas $editor->setValue(sprintf( '', $fileID )); $editor->saveInto($sitetree); $sitetree->write(); $this->assertEquals( array($fileID => $fileID), $sitetree->ImageTracking()->getIDList(), 'Link tracking with space instead of comma in shortcode works.' ); } public function testImageInsertion() { $sitetree = new SiteTree(); $editor = new HTMLEditorField('Content'); $editor->setValue('