From e45f4c923c001fa057adff288b4e1fd62ad9989f Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Tue, 22 Feb 2011 10:52:56 +1300 Subject: [PATCH] MINOR: Misc fixes to clean up the 2.4 mergeback. --- code/AssetAdmin.php | 3 +- code/CMSBatchAction.php | 6 +++ code/CMSMain.php | 85 ++++++++++++++++++++++++++++++ tests/CommentAdminTest.php | 39 -------------- tests/PageCommentsTest.php | 105 ------------------------------------- tests/PageCommentsTest.yml | 62 ---------------------- 6 files changed, 93 insertions(+), 207 deletions(-) delete mode 100644 tests/CommentAdminTest.php delete mode 100644 tests/PageCommentsTest.php delete mode 100644 tests/PageCommentsTest.yml diff --git a/code/AssetAdmin.php b/code/AssetAdmin.php index 931d92c2..cf1a6aca 100755 --- a/code/AssetAdmin.php +++ b/code/AssetAdmin.php @@ -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 diff --git a/code/CMSBatchAction.php b/code/CMSBatchAction.php index 9bab3464..990e7355 100644 --- a/code/CMSBatchAction.php +++ b/code/CMSBatchAction.php @@ -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', diff --git a/code/CMSMain.php b/code/CMSMain.php index 781faaf5..104b0470 100755 --- a/code/CMSMain.php +++ b/code/CMSMain.php @@ -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 */ diff --git a/tests/CommentAdminTest.php b/tests/CommentAdminTest.php deleted file mode 100644 index ecf6d68e..00000000 --- a/tests/CommentAdminTest.php +++ /dev/null @@ -1,39 +0,0 @@ -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); - } - -} -?> \ No newline at end of file diff --git a/tests/PageCommentsTest.php b/tests/PageCommentsTest.php deleted file mode 100644 index dc708422..00000000 --- a/tests/PageCommentsTest.php +++ /dev/null @@ -1,105 +0,0 @@ -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'); - } - } -} diff --git a/tests/PageCommentsTest.yml b/tests/PageCommentsTest.yml deleted file mode 100644 index 5ec73a0e..00000000 --- a/tests/PageCommentsTest.yml +++ /dev/null @@ -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 \ No newline at end of file