mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 11:05:53 +02:00
MINOR: Misc fixes to clean up the 2.4 mergeback.
This commit is contained in:
parent
5a23f69f0b
commit
e45f4c923c
@ -309,7 +309,7 @@ HTML;
|
||||
/**
|
||||
* Return the form that displays the details of a folder, including a file list and fields for editing the folder name.
|
||||
*/
|
||||
function getEditForm($id) {
|
||||
function getEditForm($id = null) {
|
||||
if($id && $id != "root") {
|
||||
$record = DataObject::get_by_id("File", $id);
|
||||
} else {
|
||||
@ -498,6 +498,7 @@ JS;
|
||||
|
||||
$parent = ($_REQUEST['ParentID'] && is_numeric($_REQUEST['ParentID'])) ? (int)$_REQUEST['ParentID'] : 0;
|
||||
$name = (isset($_REQUEST['Name'])) ? basename($_REQUEST['Name']) : _t('AssetAdmin.NEWFOLDER',"NewFolder");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Form
|
||||
|
@ -139,6 +139,9 @@ class CMSBatchAction_Publish extends CMSBatchAction {
|
||||
function getActionTitle() {
|
||||
return _t('CMSBatchActions.PUBLISH_PAGES', 'Publish');
|
||||
}
|
||||
function getDoingText() {
|
||||
return _t('CMSBatchActions.PUBLISHING_PAGES', 'Publishing selected pages');
|
||||
}
|
||||
|
||||
function run(DataObjectSet $pages) {
|
||||
return $this->batchaction($pages, 'doPublish',
|
||||
@ -161,6 +164,9 @@ class CMSBatchAction_Unpublish extends CMSBatchAction {
|
||||
function getActionTitle() {
|
||||
return _t('CMSBatchActions.UNPUBLISH_PAGES', 'Un-publish');
|
||||
}
|
||||
function getDoingText() {
|
||||
return _t('CMSBatchActions.UNPUBLISHING_PAGES', 'Un-publishing selected pages');
|
||||
}
|
||||
|
||||
function run(DataObjectSet $pages) {
|
||||
return $this->batchaction($pages, 'doUnpublish',
|
||||
|
@ -46,6 +46,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
|
||||
'versions',
|
||||
'EditForm',
|
||||
'AddForm',
|
||||
'SearchTreeForm',
|
||||
'SiteTreeAsUL',
|
||||
'getshowdeletedsubtree',
|
||||
'getfilteredsubtree',
|
||||
@ -1292,7 +1293,91 @@ JS;
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Form used to filter the sitetree. It can only be used via javascript for now.
|
||||
*
|
||||
* @return Form
|
||||
*/
|
||||
function SearchTreeForm() {
|
||||
// get all page types in a dropdown-compatible format
|
||||
$pageTypes = SiteTree::page_type_classes();
|
||||
array_unshift($pageTypes, 'All');
|
||||
$pageTypes = array_combine($pageTypes, $pageTypes);
|
||||
asort($pageTypes);
|
||||
|
||||
// get all filter instances
|
||||
$filters = ClassInfo::subclassesFor('CMSSiteTreeFilter');
|
||||
$filterMap = array();
|
||||
// remove base class
|
||||
array_shift($filters);
|
||||
// add filters to map
|
||||
foreach($filters as $filter) {
|
||||
$filterMap[$filter] = call_user_func(array($filter, 'title'));
|
||||
}
|
||||
// ensure that 'all pages' filter is on top position
|
||||
uasort($filterMap,
|
||||
create_function('$a,$b', 'return ($a == "CMSSiteTreeFilter_Search") ? 1 : -1;')
|
||||
);
|
||||
|
||||
$showDefaultFields = array();
|
||||
$form = new Form(
|
||||
$this,
|
||||
'SearchTreeForm',
|
||||
new FieldSet(
|
||||
$showDefaultFields[] = new DropdownField(
|
||||
'FilterClass',
|
||||
_t('CMSMain.SearchTreeFormPagesDropdown', 'Pages'),
|
||||
$filterMap
|
||||
),
|
||||
$showDefaultFields[] = new TextField(
|
||||
'Title',
|
||||
_t('CMSMain.TITLEOPT', 'Title')
|
||||
),
|
||||
new TextField('Content', 'Text'),
|
||||
new DateField('EditedSince', _t('CMSMain_left.ss.EDITEDSINCE','Edited Since')),
|
||||
new DropdownField('ClassName', 'Page Type', $pageTypes, null, null, 'Any'),
|
||||
new TextField(
|
||||
'MenuTitle',
|
||||
_t('CMSMain.MENUTITLEOPT', 'Navigation Label')
|
||||
),
|
||||
new TextField(
|
||||
'Status',
|
||||
_t('CMSMain.STATUSOPT', 'Status')
|
||||
),
|
||||
new TextField(
|
||||
'MetaDescription',
|
||||
_t('CMSMain.METADESCOPT', 'Description')
|
||||
),
|
||||
new TextField(
|
||||
'MetaKeywords',
|
||||
_t('CMSMain.METAKEYWORDSOPT', 'Keywords')
|
||||
)
|
||||
),
|
||||
new FieldSet(
|
||||
new ResetFormAction(
|
||||
'clear',
|
||||
_t('CMSMain_left.ss.CLEAR', 'Clear')
|
||||
),
|
||||
new FormAction(
|
||||
'doSearchTree',
|
||||
_t('CMSMain_left.ss.SEARCH', 'Search')
|
||||
)
|
||||
)
|
||||
);
|
||||
$form->setFormMethod('GET');
|
||||
$form->disableSecurityToken();
|
||||
$form->unsetValidator();
|
||||
|
||||
foreach($showDefaultFields as $f) $f->addExtraClass('show-default');
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
function doSearchTree($data, $form) {
|
||||
return $this->getsubtree($this->request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to get page count
|
||||
*/
|
||||
|
@ -1,39 +0,0 @@
|
||||
<?php
|
||||
|
||||
class CommentAdminTest extends FunctionalTest {
|
||||
|
||||
static $fixture_file = 'cms/tests/CMSMainTest.yml';
|
||||
|
||||
function testNumModerated() {
|
||||
|
||||
$comm = new CommentAdmin();
|
||||
$resp = $comm->NumModerated();
|
||||
$this->assertEquals(1, $resp);
|
||||
}
|
||||
|
||||
function testNumUnmoderated(){
|
||||
|
||||
$comm = new CommentAdmin();
|
||||
$resp = $comm->NumUnmoderated();
|
||||
$this->assertEquals(2, $resp);
|
||||
}
|
||||
|
||||
function testNumSpam(){
|
||||
|
||||
$comm = new CommentAdmin();
|
||||
$resp = $comm->NumSpam();
|
||||
$this->assertEquals(0, $resp);
|
||||
}
|
||||
|
||||
function testdeletemarked(){
|
||||
$comm = $this->objFromFixture('PageComment', 'Comment1');
|
||||
$id = $comm->ID;
|
||||
$this->logInWithPermission('CMS_ACCESS_CommentAdmin');
|
||||
$response = $this->get("admin/comments/EditForm/field/Comments/item/$id/delete");
|
||||
$checkComm = DataObject::get_by_id('PageComment',$id);
|
||||
|
||||
$this->assertFalse($checkComm);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
@ -1,105 +0,0 @@
|
||||
<?php
|
||||
|
||||
class PageCommentsTest extends FunctionalTest {
|
||||
|
||||
static $fixture_file = 'cms/tests/PageCommentsTest.yml';
|
||||
|
||||
static $use_draft_site = true;
|
||||
|
||||
function testCanView() {
|
||||
$visitor = $this->objFromFixture('Member', 'visitor');
|
||||
$admin = $this->objFromFixture('Member', 'commentadmin');
|
||||
$comment = $this->objFromFixture('PageComment', 'firstComA');
|
||||
|
||||
$this->assertTrue($comment->canView($visitor),
|
||||
'Unauthenticated members can view comments associated to a page with ProvideComments=1'
|
||||
);
|
||||
$this->assertTrue($comment->canView($admin),
|
||||
'Admins with CMS_ACCESS_CommentAdmin permissions can view comments associated to a page with ProvideComments=1'
|
||||
);
|
||||
|
||||
$disabledComment = $this->objFromFixture('PageComment', 'disabledCom');
|
||||
|
||||
$this->assertFalse($disabledComment->canView($visitor),
|
||||
'Unauthenticated members can not view comments associated to a page with ProvideComments=0'
|
||||
);
|
||||
$this->assertTrue($disabledComment->canView($admin),
|
||||
'Admins with CMS_ACCESS_CommentAdmin permissions can view comments associated to a page with ProvideComments=0'
|
||||
);
|
||||
}
|
||||
|
||||
function testCanEdit() {
|
||||
$visitor = $this->objFromFixture('Member', 'visitor');
|
||||
$admin = $this->objFromFixture('Member', 'commentadmin');
|
||||
$comment = $this->objFromFixture('PageComment', 'firstComA');
|
||||
|
||||
$this->assertFalse($comment->canEdit($visitor));
|
||||
$this->assertTrue($comment->canEdit($admin));
|
||||
}
|
||||
|
||||
function testCanDelete() {
|
||||
$visitor = $this->objFromFixture('Member', 'visitor');
|
||||
$admin = $this->objFromFixture('Member', 'commentadmin');
|
||||
$comment = $this->objFromFixture('PageComment', 'firstComA');
|
||||
|
||||
$this->assertFalse($comment->canEdit($visitor));
|
||||
$this->assertTrue($comment->canEdit($admin));
|
||||
}
|
||||
|
||||
function testDeleteComment() {
|
||||
$firstPage = $this->objFromFixture('Page', 'first');
|
||||
$this->autoFollowRedirection = false;
|
||||
$this->logInAs('commentadmin');
|
||||
|
||||
$firstComment = $this->objFromFixture('PageComment', 'firstComA');
|
||||
$firstCommentID = $firstComment->ID;
|
||||
$response = $this->get($firstPage->RelativeLink());
|
||||
$token = SecurityToken::inst();
|
||||
$url = sprintf('PageComment/deletecomment/%d/', $firstComment->ID);
|
||||
$url = $token->addToUrl($url);
|
||||
$response = $this->get($url);
|
||||
|
||||
$this->assertFalse(DataObject::get_by_id('PageComment', $firstCommentID));
|
||||
}
|
||||
|
||||
function testDeleteAllCommentsOnPage() {
|
||||
$second = $this->objFromFixture('Page', 'second');
|
||||
$this->autoFollowRedirection = false;
|
||||
$this->logInAs('commentadmin');
|
||||
|
||||
$response = $this->get($second->RelativeLink());
|
||||
$token = SecurityToken::inst();
|
||||
$url = sprintf('PageComment/deleteallcomments?pageid=%d', $second->ID);
|
||||
$url = $token->addToUrl($url);
|
||||
$response = $this->get($url);
|
||||
$response = $this->get($second->RelativeLink());
|
||||
|
||||
$secondComments = DataObject::get('PageComment', '"ParentID" = '.$second->ID);
|
||||
$this->assertNull($secondComments);
|
||||
|
||||
$first = $this->objFromFixture('Page', 'first');
|
||||
$firstComments = DataObject::get('PageComment', '"ParentID" = '.$first->ID);
|
||||
$this->assertNotNull($firstComments);
|
||||
|
||||
$third = $this->objFromFixture('Page', 'third');
|
||||
$thirdComments = DataObject::get('PageComment', '"ParentID" = '.$third->ID);
|
||||
$this->assertEquals($thirdComments->Count(), 3);
|
||||
}
|
||||
|
||||
function testCommenterURLWrite() {
|
||||
$comment = new PageComment();
|
||||
// We only care about the CommenterURL, so only set that
|
||||
// Check a http and https URL. Add more test urls here as needed.
|
||||
$protocols = array(
|
||||
'Http',
|
||||
'Https',
|
||||
);
|
||||
$url = '://example.com';
|
||||
foreach($protocols as $protocol) {
|
||||
$comment->CommenterURL = $protocol . $url;
|
||||
// The protocol should stay as if, assuming it is valid
|
||||
$comment->write();
|
||||
$this->assertEquals($comment->CommenterURL, $protocol . $url, $protocol . ':// is a valid protocol');
|
||||
}
|
||||
}
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
Member:
|
||||
commentadmin:
|
||||
FirstName: admin
|
||||
visitor:
|
||||
FirstName: visitor
|
||||
|
||||
Group:
|
||||
commentadmins:
|
||||
Title: Admin
|
||||
Members: =>Member.commentadmin
|
||||
|
||||
Permission:
|
||||
admin:
|
||||
Code: CMS_ACCESS_CommentAdmin
|
||||
Group: =>Group.commentadmins
|
||||
|
||||
Page:
|
||||
first:
|
||||
Title: First page
|
||||
URLSegment: first-page
|
||||
ProvideComments: 1
|
||||
second:
|
||||
Title: Second page
|
||||
URLSegment: second-page
|
||||
ProvideComments: 1
|
||||
third:
|
||||
Title: Third page
|
||||
URLSegment:third-page
|
||||
ProvideComments: 1
|
||||
pageNoComments:
|
||||
Title: No comments
|
||||
URLSegment: no-comments
|
||||
ProvideComments: 0
|
||||
|
||||
PageComment:
|
||||
firstComA:
|
||||
ParentID: =>Page.first
|
||||
Name: FA
|
||||
Comment: textFA
|
||||
secondComA:
|
||||
ParentID: =>Page.second
|
||||
Name: SA
|
||||
Comment: textSA
|
||||
secondComB:
|
||||
ParentID: =>Page.second
|
||||
Name: SB
|
||||
Comment: textSB
|
||||
thirdComA:
|
||||
ParentID: =>Page.third
|
||||
Name: TA
|
||||
Comment: textTA
|
||||
thirdComB:
|
||||
ParentID: =>Page.third
|
||||
Name: TB
|
||||
Comment: textTB
|
||||
thirdComC:
|
||||
ParentID: =>Page.third
|
||||
Name: TC
|
||||
Comment: textTC
|
||||
disabledCom:
|
||||
ParentID: =>Page.pageNoComments
|
||||
Name: Disabled
|
Loading…
Reference in New Issue
Block a user