Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ENHANCEMENT: remove dependencies between framework tests and cms module.

  • Loading branch information...
commit a4bce3fc4471b06b038d1df21afccf84681b5baa 1 parent e57dd60
Will Rossiter wilr authored chillu committed
16 filesystem/File.php
View
@@ -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 @@ function getCMSFields() {
sprintf('<a href="%s" target="_blank">%s</a>', $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');
6 security/Member.php
View
@@ -1037,7 +1037,11 @@ public static function mapInCMSGroups($groups = null) {
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)));
33 tests/filesystem/FileTest.php
View
@@ -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 @@ public function testLinkShortcodeHandler() {
$fileShortcode = '[file_link id="-1"]';
$fileEnclosed = '[file_link id="-1"]Example Content[/file_link]';
- $fileShortcodeExpected = $errorPage->Link();
- $fileEnclosedExpected = sprintf('<a href="%s">Example Content</a>', $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('<a href="%s">Example Content</a>', $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 @@ function setUp() {
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() {
4 tests/filesystem/FileTest.yml
View
@@ -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
15 tests/security/PermissionTest.php
View
@@ -68,16 +68,13 @@ function testGettingMembersByPermission() {
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());
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.