Permalink
Browse files

Minor Moved from RedirectorPageTest, SiteTreeActionsTest, SiteTreeBac…

…kLinksTest, SiteTreePermissionsTest, SiteTreeTest, WidgetAreaTest /Sites/cgps/sapphire/tests to cms module cms/tests/
  • Loading branch information...
Paul Meyrick authored and chillu committed Mar 18, 2011
1 parent e280929 commit d4af221e0ac76140cb00ec1fc1f948f81d8d11e9
@@ -0,0 +1,53 @@
+<?php
+
+class RedirectorPageTest extends FunctionalTest {
+ static $fixture_file = 'sapphire/tests/RedirectorPageTest.yml';
+ static $use_draft_site = true;
+
+ function testGoodRedirectors() {
+ /* For good redirectors, the final destination URL will be returned */
+ $this->assertEquals("http://www.google.com", $this->objFromFixture('RedirectorPage','goodexternal')->Link());
+ $this->assertEquals(Director::baseURL() . "redirection-dest/", $this->objFromFixture('RedirectorPage','goodinternal')->redirectionLink());
+ $this->assertEquals(Director::baseURL() . "redirection-dest/", $this->objFromFixture('RedirectorPage','goodinternal')->Link());
+ }
+
+ function testEmptyRedirectors() {
+ /* If a redirector page is misconfigured, then its link method will just return the usual URLSegment-generated value */
+ $page1 = $this->objFromFixture('RedirectorPage','badexternal');
+ $this->assertEquals(Director::baseURL() . 'bad-external/', $page1->Link());
+
+ /* An error message will be shown if you visit it */
+ $content = $this->get(Director::makeRelative($page1->Link()))->getBody();
+ $this->assertContains('message-setupWithoutRedirect', $content);
+
+ /* This also applies for internal links */
+ $page2 = $this->objFromFixture('RedirectorPage','badinternal');
+ $this->assertEquals(Director::baseURL() . 'bad-internal/', $page2->Link());
+ $content = $this->get(Director::makeRelative($page2->Link()))->getBody();
+ $this->assertContains('message-setupWithoutRedirect', $content);
+ }
+
+ function testReflexiveAndTransitiveInternalRedirectors() {
+ /* Reflexive redirectors are those that point to themselves. They should behave the same as an empty redirector */
+ $page = $this->objFromFixture('RedirectorPage','reflexive');
+ $this->assertEquals(Director::baseURL() . 'reflexive/', $page->Link());
+ $content = $this->get(Director::makeRelative($page->Link()))->getBody();
+ $this->assertContains('message-setupWithoutRedirect', $content);
+
+ /* Transitive redirectors are those that point to another redirector page. They should send people to the URLSegment
+ * of the destination page - the middle-stop, so to speak. That should redirect to the final destination */
+ $page = $this->objFromFixture('RedirectorPage','transitive');
+ $this->assertEquals(Director::baseURL() . 'good-internal/', $page->Link());
+
+ $this->autoFollowRedirection = false;
+ $response = $this->get(Director::makeRelative($page->Link()));
+ $this->assertEquals(Director::baseURL() . "redirection-dest/", $response->getHeader("Location"));
+ }
+
+ function testExternalURLGetsPrefixIfNotSet() {
+ $page = $this->objFromFixture('RedirectorPage', 'externalnoprefix');
+ $this->assertEquals($page->ExternalURL, 'http://google.com', 'onBeforeWrite has prefixed with http');
+ $page->write();
+ $this->assertEquals($page->ExternalURL, 'http://google.com', 'onBeforeWrite will not double prefix if written again!');
+ }
+}
@@ -0,0 +1,39 @@
+Page:
+ dest:
+ Title: Redirection Dest
+ URLSegment: redirection-dest
+
+RedirectorPage:
+ goodexternal:
+ Title: Good External
+ URLSegment: good-external
+ RedirectionType: External
+ ExternalURL: http://www.google.com
+ goodinternal:
+ Title: Good Internal
+ URLSegment: good-internal
+ RedirectionType: Internal
+ LinkTo: =>Page.dest
+ badexternal:
+ Title: Bad External
+ RedirectionType: External
+ URLSegment: bad-external
+ externalnoprefix:
+ Title: External no prefix
+ RedirectionType: External
+ URLSegment: external-no-prefix
+ ExternalURL: google.com
+ badinternal:
+ Title: Bad Internal
+ RedirectionType: Internal
+ URLSegment: bad-internal
+ reflexive:
+ Title: Reflexive
+ RedirectionType: Internal
+ LinkTo: =>RedirectorPage.reflexive
+ URLSegment: reflexive
+ transitive:
+ Title: Transitive
+ RedirectionType: Internal
+ LinkTo: =>RedirectorPage.goodinternal
+ URLSegment: transitive
@@ -0,0 +1,186 @@
+<?php
+/**
+ * Possible actions:
+ * - action_save
+ * - action_publish
+ * - action_unpublish
+ * - action_delete
+ * - action_deletefromlive
+ * - action_rollback
+ * - action_revert
+ *
+ * @package sapphire
+ * @subpackage tests
+ */
+class SiteTreeActionsTest extends FunctionalTest {
+
+ static $fixture_file = 'cms/tests/SiteTreeActionsTest.yml';
+
+ static function set_up_once() {
+ SiteTreeTest::set_up_once();
+
+ parent::set_up_once();
+ }
+
+ static function tear_down_once() {
+ SiteTreeTest::tear_down_once();
+
+ parent::tear_down_once();
+ }
+
+ function testActionsReadonly() {
+ if(class_exists('SiteTreeCMSWorkflow')) return true;
+
+ $readonlyEditor = $this->objFromFixture('Member', 'cmsreadonlyeditor');
+ $this->session()->inst_set('loggedInAs', $readonlyEditor->ID);
+
+ $page = new SiteTreeActionsTest_Page();
+ $page->CanEditType = 'LoggedInUsers';
+ $page->write();
+ $page->doPublish();
+
+ $actionsArr = $page->getCMSActions()->column('Name');
+
+ $this->assertNotContains('action_save',$actionsArr);
+ $this->assertNotContains('action_publish',$actionsArr);
+ $this->assertNotContains('action_unpublish',$actionsArr);
+ $this->assertNotContains('action_delete',$actionsArr);
+ $this->assertNotContains('action_deletefromlive',$actionsArr);
+ $this->assertNotContains('action_rollback',$actionsArr);
+ $this->assertNotContains('action_revert',$actionsArr);
+ }
+
+ function testActionsNoDeletePublishedRecord() {
+ if(class_exists('SiteTreeCMSWorkflow')) return true;
+
+ $this->logInWithPermission('ADMIN');
+
+ $page = new SiteTreeActionsTest_Page();
+ $page->CanEditType = 'LoggedInUsers';
+ $page->write();
+ $pageID = $page->ID;
+ $page->doPublish();
+ $page->deleteFromStage('Stage');
+
+ // Get the live version of the page
+ $page = Versioned::get_one_by_stage("SiteTree", "Live", "\"SiteTree\".\"ID\" = $pageID");
+ $this->assertType("SiteTree", $page);
+
+ // Check that someone without the right permission can't delete the page
+ $editor = $this->objFromFixture('Member', 'cmsnodeleteeditor');
+ $this->session()->inst_set('loggedInAs', $editor->ID);
+
+ $actionsArr = $page->getCMSActions()->column('Name');
+ $this->assertNotContains('action_deletefromlive',$actionsArr);
+
+ // Check that someone with the right permission can delete the page
+ $this->objFromFixture('Member', 'cmseditor')->logIn();
+ $actionsArr = $page->getCMSActions()->column('Name');
+ $this->assertContains('action_deletefromlive',$actionsArr);
+ }
+
+ function testActionsPublishedRecord() {
+ if(class_exists('SiteTreeCMSWorkflow')) return true;
+
+ $author = $this->objFromFixture('Member', 'cmseditor');
+ $this->session()->inst_set('loggedInAs', $author->ID);
+
+ $page = new Page();
+ $page->CanEditType = 'LoggedInUsers';
+ $page->write();
+ $page->doPublish();
+
+ $actionsArr = $page->getCMSActions()->column('Name');
+
+ $this->assertContains('action_save',$actionsArr);
+ $this->assertContains('action_publish',$actionsArr);
+ $this->assertContains('action_unpublish',$actionsArr);
+ $this->assertContains('action_delete',$actionsArr);
+ $this->assertNotContains('action_deletefromlive',$actionsArr);
+ $this->assertNotContains('action_rollback',$actionsArr);
+ $this->assertNotContains('action_revert',$actionsArr);
+ }
+
+ function testActionsDeletedFromStageRecord() {
+ if(class_exists('SiteTreeCMSWorkflow')) return true;
+
+ $author = $this->objFromFixture('Member', 'cmseditor');
+ $this->session()->inst_set('loggedInAs', $author->ID);
+
+ $page = new Page();
+ $page->CanEditType = 'LoggedInUsers';
+ $page->write();
+ $pageID = $page->ID;
+ $page->doPublish();
+ $page->deleteFromStage('Stage');
+
+ // Get the live version of the page
+ $page = Versioned::get_one_by_stage("SiteTree", "Live", "\"SiteTree\".\"ID\" = $pageID");
+ $this->assertType('SiteTree', $page);
+
+ $actionsArr = $page->getCMSActions()->column('Name');
+
+ $this->assertNotContains('action_save',$actionsArr);
+ $this->assertNotContains('action_publish',$actionsArr);
+ $this->assertNotContains('action_unpublish',$actionsArr);
+ $this->assertNotContains('action_delete',$actionsArr);
+ $this->assertContains('action_deletefromlive',$actionsArr);
+ $this->assertNotContains('action_rollback',$actionsArr);
+ $this->assertContains('action_revert',$actionsArr);
+ }
+
+ function testActionsChangedOnStageRecord() {
+ if(class_exists('SiteTreeCMSWorkflow')) return true;
+
+ $author = $this->objFromFixture('Member', 'cmseditor');
+ $this->session()->inst_set('loggedInAs', $author->ID);
+
+ $page = new Page();
+ $page->CanEditType = 'LoggedInUsers';
+ $page->write();
+ $page->doPublish();
+ $page->Content = 'Changed on Stage';
+ $page->write();
+ $page->flushCache();
+
+ $actionsArr = $page->getCMSActions()->column('Name');
+
+ $this->assertContains('action_save',$actionsArr);
+ $this->assertContains('action_publish',$actionsArr);
+ $this->assertContains('action_unpublish',$actionsArr);
+ $this->assertContains('action_delete',$actionsArr);
+ $this->assertNotContains('action_deletefromlive',$actionsArr);
+ $this->assertContains('action_rollback',$actionsArr);
+ $this->assertNotContains('action_revert',$actionsArr);
+ }
+
+ function testActionsViewingOldVersion() {
+ $p = new Page();
+ $p->Content = 'test page first version';
+ $p->write();
+ $p->Content = 'new content';
+ $p->write();
+
+ // Looking at the old version, the ability to rollback to that version is available
+ $version = DB::query('SELECT "Version" FROM "SiteTree_versions" WHERE "Content" = \'test page first version\'')->value();
+ $old = Versioned::get_version('Page', $p->ID, $version);
+ $actions = $old->getCMSActions()->column('Name');
+ $this->assertNotContains('action_save', $actions);
+ $this->assertNotContains('action_publish', $actions);
+ $this->assertNotContains('action_unpublish', $actions);
+ $this->assertNotContains('action_delete', $actions);
+ $this->assertContains('action_email', $actions);
+ $this->assertContains('action_rollback', $actions);
+ }
+
+}
+
+class SiteTreeActionsTest_Page extends Page implements TestOnly {
+ function canEdit($member = null) {
+ return Permission::checkMember($member, 'SiteTreeActionsTest_Page_CANEDIT');
+ }
+
+ function canDelete($member = null) {
+ return Permission::checkMember($member, 'SiteTreeActionsTest_Page_CANDELETE');
+ }
+}
@@ -0,0 +1,33 @@
+Permission:
+ cmsmain1:
+ Code: CMS_ACCESS_CMSMain
+ cmsmain2:
+ Code: CMS_ACCESS_CMSMain
+ cmsmain3:
+ Code: CMS_ACCESS_CMSMain
+ candelete:
+ Code: SiteTreeActionsTest_Page_CANDELETE
+ canedit1:
+ Code: SiteTreeActionsTest_Page_CANEDIT
+ canedit2:
+ Code: SiteTreeActionsTest_Page_CANEDIT
+Group:
+ cmseditors:
+ Title: CMS Editors
+ Permissions: =>Permission.cmsmain1,=>Permission.canedit1,=>Permission.candelete
+ cmsreadonly:
+ Title: CMS Readonly
+ Permissions: =>Permission.cmsmain2
+ cmsnodelete:
+ Title: CMS No Delete
+ Permissions: =>Permission.cmsmain3,=>Permission.canedit2
+Member:
+ cmseditor:
+ Email: cmseditor@test.com
+ Groups: =>Group.cmseditors
+ cmsreadonlyeditor:
+ Email: cmsreadonlyeditor@test.com
+ Groups: =>Group.cmsreadonly
+ cmsnodeleteeditor:
+ Email: cmsnodeleteeditor@test.com
+ Groups: =>Group.cmsnodelete
Oops, something went wrong.

0 comments on commit d4af221

Please sign in to comment.