mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
ENHANCEMENT: remove dependencies between framework tests and cms module.
This commit is contained in:
parent
8b43780e23
commit
d82b67cf97
@ -168,11 +168,14 @@ class File extends DataObject {
|
|||||||
public static function link_shortcode_handler($arguments, $content = null, $parser = null) {
|
public static function link_shortcode_handler($arguments, $content = null, $parser = null) {
|
||||||
if(!isset($arguments['id']) || !is_numeric($arguments['id'])) return;
|
if(!isset($arguments['id']) || !is_numeric($arguments['id'])) return;
|
||||||
|
|
||||||
if (
|
$record = DataObject::get_by_id('File', $arguments['id']);
|
||||||
!($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.
|
if (!$record) {
|
||||||
) {
|
if(class_exists('ErrorPage')) {
|
||||||
return; // There were no suitable matches at all.
|
$record = DataObject::get_one('ErrorPage', '"ErrorCode" = \'404\'');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$record) return; // There were no suitable matches at all.
|
||||||
}
|
}
|
||||||
|
|
||||||
// build the HTML tag
|
// build the HTML tag
|
||||||
@ -360,8 +363,7 @@ class File extends DataObject {
|
|||||||
sprintf('<a href="%s" target="_blank">%s</a>', $this->Link(), $this->RelativeLink())
|
sprintf('<a href="%s" target="_blank">%s</a>', $this->Link(), $this->RelativeLink())
|
||||||
),
|
),
|
||||||
new DateField_Disabled("Created", _t('AssetTableField.CREATED','First uploaded') . ':'),
|
new DateField_Disabled("Created", _t('AssetTableField.CREATED','First uploaded') . ':'),
|
||||||
new DateField_Disabled("LastEdited", _t('AssetTableField.LASTEDIT','Last changed') . ':'),
|
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)'))
|
|
||||||
)
|
)
|
||||||
)->setName("FilePreviewData")->addExtraClass('cms-file-info-data')
|
)->setName("FilePreviewData")->addExtraClass('cms-file-info-data')
|
||||||
)->setName("FilePreview")->addExtraClass('cms-file-info');
|
)->setName("FilePreview")->addExtraClass('cms-file-info');
|
||||||
|
@ -1037,7 +1037,11 @@ class Member extends DataObject implements TemplateGlobalProvider {
|
|||||||
if(!$groups || $groups->Count() == 0) {
|
if(!$groups || $groups->Count() == 0) {
|
||||||
$perms = array('ADMIN', 'CMS_ACCESS_AssetAdmin');
|
$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)) {
|
if(!empty($cmsPerms)) {
|
||||||
$perms = array_unique(array_merge($perms, array_keys($cmsPerms)));
|
$perms = array_unique(array_merge($perms, array_keys($cmsPerms)));
|
||||||
|
@ -11,7 +11,6 @@ class FileTest extends SapphireTest {
|
|||||||
|
|
||||||
public function testLinkShortcodeHandler() {
|
public function testLinkShortcodeHandler() {
|
||||||
$testFile = $this->objFromFixture('File', 'asdf');
|
$testFile = $this->objFromFixture('File', 'asdf');
|
||||||
$errorPage = $this->objFromFixture('ErrorPage', '404');
|
|
||||||
|
|
||||||
$parser = new ShortcodeParser();
|
$parser = new ShortcodeParser();
|
||||||
$parser->register('file_link', array('File', 'link_shortcode_handler'));
|
$parser->register('file_link', array('File', 'link_shortcode_handler'));
|
||||||
@ -30,15 +29,25 @@ class FileTest extends SapphireTest {
|
|||||||
$fileShortcode = '[file_link id="-1"]';
|
$fileShortcode = '[file_link id="-1"]';
|
||||||
$fileEnclosed = '[file_link id="-1"]Example Content[/file_link]';
|
$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]'), 'Test that invalid ID attributes are not parsed.');
|
||||||
$this->assertEquals('', $parser->parse('[file_link id="text"]'));
|
$this->assertEquals('', $parser->parse('[file_link id="text"]'));
|
||||||
$this->assertEquals('', $parser->parse('[file_link]Example Content[/file_link]'));
|
$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() {
|
function testCreateWithFilenameWithSubfolder() {
|
||||||
@ -372,6 +381,16 @@ class FileTest extends SapphireTest {
|
|||||||
fwrite($fh, str_repeat('x',1000000));
|
fwrite($fh, str_repeat('x',1000000));
|
||||||
fclose($fh);
|
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() {
|
function tearDown() {
|
||||||
|
@ -28,7 +28,3 @@ File:
|
|||||||
Filename: assets/FileTest-folder1/File1.txt
|
Filename: assets/FileTest-folder1/File1.txt
|
||||||
Name: File1.txt
|
Name: File1.txt
|
||||||
ParentID: =>Folder.folder1
|
ParentID: =>Folder.folder1
|
||||||
ErrorPage:
|
|
||||||
404:
|
|
||||||
Title: Page not Found
|
|
||||||
ErrorCode: 404
|
|
||||||
|
@ -68,16 +68,13 @@ class PermissionTest extends SapphireTest {
|
|||||||
|
|
||||||
function testHiddenPermissions(){
|
function testHiddenPermissions(){
|
||||||
$permissionCheckboxSet = new PermissionCheckboxSetField('Permissions','Permissions','Permission','GroupID');
|
$permissionCheckboxSet = new PermissionCheckboxSetField('Permissions','Permissions','Permission','GroupID');
|
||||||
$this->assertContains('CMS_ACCESS_CMSMain', $permissionCheckboxSet->Field());
|
$this->assertContains('CMS_ACCESS_LeftAndMain', $permissionCheckboxSet->Field());
|
||||||
$this->assertContains('CMS_ACCESS_AssetAdmin', $permissionCheckboxSet->Field());
|
|
||||||
|
|
||||||
Permission::add_to_hidden_permissions('CMS_ACCESS_CMSMain');
|
Permission::add_to_hidden_permissions('CMS_ACCESS_LeftAndMain');
|
||||||
Permission::add_to_hidden_permissions('CMS_ACCESS_AssetAdmin');
|
|
||||||
$this->assertNotContains('CMS_ACCESS_CMSMain', $permissionCheckboxSet->Field());
|
|
||||||
$this->assertNotContains('CMS_ACCESS_AssetAdmin', $permissionCheckboxSet->Field());
|
|
||||||
|
|
||||||
Permission::remove_from_hidden_permissions('CMS_ACCESS_AssetAdmin');
|
$this->assertNotContains('CMS_ACCESS_LeftAndMain', $permissionCheckboxSet->Field());
|
||||||
$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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user