diff --git a/filesystem/File.php b/filesystem/File.php index 380f124a9..6712ee6f4 100644 --- a/filesystem/File.php +++ b/filesystem/File.php @@ -168,11 +168,14 @@ class File extends DataObject { public static function link_shortcode_handler($arguments, $content = null, $parser = null) { if(!isset($arguments['id']) || !is_numeric($arguments['id'])) return; - if ( - !($record = DataObject::get_by_id('File', $arguments['id'])) // Get the file by ID. - && !($record = DataObject::get_one('ErrorPage', '"ErrorCode" = \'404\'')) // Link to 404 page directly. - ) { - return; // There were no suitable matches at all. + $record = DataObject::get_by_id('File', $arguments['id']); + + if (!$record) { + if(class_exists('ErrorPage')) { + $record = DataObject::get_one('ErrorPage', '"ErrorCode" = \'404\''); + } + + if (!$record) return; // There were no suitable matches at all. } // build the HTML tag @@ -360,8 +363,7 @@ class File extends DataObject { sprintf('%s', $this->Link(), $this->RelativeLink()) ), new DateField_Disabled("Created", _t('AssetTableField.CREATED','First uploaded') . ':'), - new DateField_Disabled("LastEdited", _t('AssetTableField.LASTEDIT','Last changed') . ':'), - new ReadonlyField('BackLinkCount', _t('AssetTableField.BACKLINKCOUNT', 'Used on:'), $this->BackLinkTracking()->Count() . ' ' . _t('AssetTableField.PAGES', 'page(s)')) + new DateField_Disabled("LastEdited", _t('AssetTableField.LASTEDIT','Last changed') . ':') ) )->setName("FilePreviewData")->addExtraClass('cms-file-info-data') )->setName("FilePreview")->addExtraClass('cms-file-info'); diff --git a/security/Member.php b/security/Member.php index 3521b7524..c885706ec 100644 --- a/security/Member.php +++ b/security/Member.php @@ -1037,7 +1037,11 @@ class Member extends DataObject implements TemplateGlobalProvider { if(!$groups || $groups->Count() == 0) { $perms = array('ADMIN', 'CMS_ACCESS_AssetAdmin'); - $cmsPerms = singleton('CMSMain')->providePermissions(); + if(class_exists('CMSMain')) { + $cmsPerms = singleton('CMSMain')->providePermissions(); + } else { + $cmsPerms = singleton('LeftAndMain')->providePermissions(); + } if(!empty($cmsPerms)) { $perms = array_unique(array_merge($perms, array_keys($cmsPerms))); diff --git a/tests/filesystem/FileTest.php b/tests/filesystem/FileTest.php index 04e18361f..72f4645f5 100644 --- a/tests/filesystem/FileTest.php +++ b/tests/filesystem/FileTest.php @@ -11,7 +11,6 @@ class FileTest extends SapphireTest { public function testLinkShortcodeHandler() { $testFile = $this->objFromFixture('File', 'asdf'); - $errorPage = $this->objFromFixture('ErrorPage', '404'); $parser = new ShortcodeParser(); $parser->register('file_link', array('File', 'link_shortcode_handler')); @@ -30,15 +29,25 @@ class FileTest extends SapphireTest { $fileShortcode = '[file_link id="-1"]'; $fileEnclosed = '[file_link id="-1"]Example Content[/file_link]'; - $fileShortcodeExpected = $errorPage->Link(); - $fileEnclosedExpected = sprintf('Example Content', $errorPage->Link()); - - $this->assertEquals($fileShortcodeExpected, $parser->parse($fileShortcode), 'Test link to 404 page if no suitable matches.'); - $this->assertEquals($fileEnclosedExpected, $parser->parse($fileEnclosed)); - $this->assertEquals('', $parser->parse('[file_link]'), 'Test that invalid ID attributes are not parsed.'); $this->assertEquals('', $parser->parse('[file_link id="text"]')); $this->assertEquals('', $parser->parse('[file_link]Example Content[/file_link]')); + + if(class_exists('ErrorPage')) { + $errorPage = ErrorPage::get()->filter('ErrorCode', 404)->First(); + $this->assertEquals( + $errorPage->Link(), + $parser->parse($fileShortcode), + 'Test link to 404 page if no suitable matches.' + ); + $this->assertEquals( + sprintf('Example Content', $errorPage->Link()), + $parser->parse($fileEnclosed) + ); + } else { + $this->assertEquals('', $parser->parse($fileShortcode), 'Short code is removed if file record is not present.'); + $this->assertEquals('', $parser->parse($fileEnclosed)); + } } function testCreateWithFilenameWithSubfolder() { @@ -372,6 +381,16 @@ class FileTest extends SapphireTest { fwrite($fh, str_repeat('x',1000000)); fclose($fh); } + + // Conditional fixture creation in case the 'cms' module is installed + if(class_exists('ErrorPage')) { + $page = new ErrorPage(array( + 'Title' => 'Page not Found', + 'ErrorCode' => 404 + )); + $page->write(); + $page->publish('Stage', 'Live'); + } } function tearDown() { diff --git a/tests/filesystem/FileTest.yml b/tests/filesystem/FileTest.yml index 63e8df2c5..e4eeab45c 100644 --- a/tests/filesystem/FileTest.yml +++ b/tests/filesystem/FileTest.yml @@ -28,7 +28,3 @@ File: Filename: assets/FileTest-folder1/File1.txt Name: File1.txt ParentID: =>Folder.folder1 -ErrorPage: - 404: - Title: Page not Found - ErrorCode: 404 diff --git a/tests/security/PermissionTest.php b/tests/security/PermissionTest.php index f88539a0d..2d89aa4d5 100644 --- a/tests/security/PermissionTest.php +++ b/tests/security/PermissionTest.php @@ -68,16 +68,13 @@ class PermissionTest extends SapphireTest { function testHiddenPermissions(){ $permissionCheckboxSet = new PermissionCheckboxSetField('Permissions','Permissions','Permission','GroupID'); - $this->assertContains('CMS_ACCESS_CMSMain', $permissionCheckboxSet->Field()); - $this->assertContains('CMS_ACCESS_AssetAdmin', $permissionCheckboxSet->Field()); + $this->assertContains('CMS_ACCESS_LeftAndMain', $permissionCheckboxSet->Field()); - Permission::add_to_hidden_permissions('CMS_ACCESS_CMSMain'); - Permission::add_to_hidden_permissions('CMS_ACCESS_AssetAdmin'); - $this->assertNotContains('CMS_ACCESS_CMSMain', $permissionCheckboxSet->Field()); - $this->assertNotContains('CMS_ACCESS_AssetAdmin', $permissionCheckboxSet->Field()); + Permission::add_to_hidden_permissions('CMS_ACCESS_LeftAndMain'); + + $this->assertNotContains('CMS_ACCESS_LeftAndMain', $permissionCheckboxSet->Field()); - Permission::remove_from_hidden_permissions('CMS_ACCESS_AssetAdmin'); - $this->assertContains('CMS_ACCESS_AssetAdmin', $permissionCheckboxSet->Field()); - Permission::remove_from_hidden_permissions('CMS_ACCESS_CMSMain'); + Permission::remove_from_hidden_permissions('CMS_ACCESS_LeftAndMain'); + $this->assertContains('CMS_ACCESS_LeftAndMain', $permissionCheckboxSet->Field()); } }