Merge branch '4.10' into 4

This commit is contained in:
Steve Boyd 2022-01-27 09:43:54 +13:00
commit ab22108c85
2 changed files with 211 additions and 1 deletions

View File

@ -2365,7 +2365,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
// "unpublish"
if ($isPublished && $isOnDraft && $canUnpublish) {
$moreOptions->push(
FormAction::create('unpublish', _t(__CLASS__.'.BUTTONUNPUBLISH', 'Unpublish'), 'delete')
FormAction::create('unpublish', _t(__CLASS__.'.BUTTONUNPUBLISH', 'Unpublish'))
->setDescription(_t(__CLASS__.'.BUTTONUNPUBLISHDESC', 'Remove this page from the published site'))
->addExtraClass('btn-secondary' . ($this->isHomePage() ? ' homepage-warning' : ''))
);

View File

@ -1744,4 +1744,214 @@ class SiteTreeTest extends SapphireTest
});
}
}
public function testGetCMSActions()
{
// Create new page on DRAFT
$page = SiteTree::create();
$page->Content = md5(rand(0, PHP_INT_MAX));
$page->write();
// BEGIN DRAFT
$actions = $page->getCMSActions();
$this->assertNotNull(
$actions->fieldByName('MajorActions.action_save'),
'save action present for a saved draft page'
);
$this->assertNotNull(
$actions->fieldByName('MajorActions.action_publish'),
'publish action present for a saved draft page'
);
$this->assertNotNull(
$actions->fieldByName('ActionMenus.MoreOptions.action_archive'),
'archive action present for a saved draft page'
);
$this->assertNotNull(
$actions->fieldByName('ActionMenus.MoreOptions.action_addtocampaign'),
'addtocampaign action present for a saved draft page'
);
$this->assertNull(
$actions->fieldByName('ActionMenus.MoreOptions.action_unpublish'),
'no unpublish action present for a saved draft page'
);
$this->assertNull(
$actions->fieldByName('ActionMenus.MoreOptions.action_rollback'),
'no rollback action present for a saved draft page'
);
$this->assertNull(
$actions->fieldByName('MajorActions.action_restore'),
'no restore action present for a saved draft page'
);
// END DRAFT
// BEGIN PUBLISHED
$page->doPublish();
$actions = $page->getCMSActions();
$this->assertNull(
$actions->fieldByName('MajorActions.action_save'),
'no save action present for a published page'
);
$this->assertNull(
$actions->fieldByName('ActionMenus.MoreOptions.action_archive'),
'no archive action present for a saved draft page'
);
$this->assertNotNull(
$actions->fieldByName('ActionMenus.MoreOptions.action_rollback'),
'rollback action present for a published page'
);
$this->assertNull(
$actions->fieldByName('ActionMenus.MoreOptions.action_unpublish'),
'no unpublish action present for a published page'
);
$this->assertNotNull(
$actions->fieldByName('ActionMenus.MoreOptions.action_addtocampaign'),
'addtocampaign action present for a published page'
);
$this->assertNull(
$actions->fieldByName('MajorActions.action_restore'),
'no restore action present for a published page'
);
// END PUBLISHED
// BEGIN DRAFT AFTER PUBLISHED
$page->Content = md5(rand(0, PHP_INT_MAX));
$page->write();
$actions = $page->getCMSActions();
$this->assertNotNull(
$actions->fieldByName('MajorActions.action_save'),
'save action present for a changed published page'
);
$this->assertNotNull(
$actions->fieldByName('ActionMenus.MoreOptions.action_unpublish'),
'unpublish action present for a changed published page'
);
$this->assertNotNull(
$actions->fieldByName('ActionMenus.MoreOptions.action_archive'),
'archive action present for a changed published page'
);
$this->assertNotNull(
$actions->fieldByName('ActionMenus.MoreOptions.action_rollback'),
'rollback action present for a changed published page'
);
$this->assertNotNull(
$actions->fieldByName('ActionMenus.MoreOptions.action_addtocampaign'),
'addtocampaign action present for a changed published page'
);
$this->assertNull(
$actions->fieldByName('MajorActions.action_restore'),
'no restore action present for a changed published page'
);
// END DRAFT AFTER PUBLISHED
// BEGIN ARCHIVED
$page->doArchive();
$actions = $page->getCMSActions();
$this->assertNull(
$actions->fieldByName('MajorActions.action_save'),
'no save action present for a archived page'
);
$this->assertNull(
$actions->fieldByName('ActionMenus.MoreOptions.action_unpublish'),
'no unpublish action present for a archived page'
);
$this->assertNull(
$actions->fieldByName('ActionMenus.MoreOptions.action_archive'),
'no archive action present for a archived page'
);
$this->assertNull(
$actions->fieldByName('ActionMenus.MoreOptions.action_rollback'),
'no rollback action present for a archived page'
);
$this->assertNull(
$actions->fieldByName('ActionMenus.MoreOptions.action_addtocampaign'),
'no addtocampaign action present for a archived page'
);
$this->assertNotNull(
$actions->fieldByName('MajorActions.action_restore'),
'restore action present for a archived page'
);
// END ARCHIVED
}
public function testGetCMSActionsWithoutForms()
{
// Create new page on DRAFT
$page = SiteTree::create();
$page->Content = md5(rand(0, PHP_INT_MAX));
$page->write();
// BEGIN DRAFT
$actions = $page->getCMSActions();
$this->assertEmpty(
$actions->fieldByName('MajorActions.action_save')->getForm(),
'save action has no form when page is draft'
);
$this->assertEmpty(
$actions->fieldByName('MajorActions.action_publish')->getForm(),
'publish action has no form when page is draft'
);
$this->assertEmpty(
$actions->fieldByName('ActionMenus.MoreOptions.action_archive')->getForm(),
'archive action has no form when page is draft'
);
$this->assertEmpty(
$actions->fieldByName('ActionMenus.MoreOptions.action_addtocampaign')->getForm(),
'addtocampaign action has no form when page is draft'
);
// END DRAFT
// BEGIN PUBLISHED
$page->doPublish();
$actions = $page->getCMSActions();
$this->assertEmpty(
$actions->fieldByName('ActionMenus.MoreOptions.action_rollback')->getForm(),
'rollback action has no form when page is published'
);
$this->assertEmpty(
$actions->fieldByName('ActionMenus.MoreOptions.action_addtocampaign')->getForm(),
'addtocampaign action has no form when page is published'
);
// END PUBLISHED
// BEGIN DRAFT AFTER PUBLISHED
$page->Content = md5(rand(0, PHP_INT_MAX));
$page->write();
$actions = $page->getCMSActions();
$this->assertEmpty(
$actions->fieldByName('MajorActions.action_save')->getForm(),
'save action has no form when page is draft after published'
);
$this->assertEmpty(
$actions->fieldByName('ActionMenus.MoreOptions.action_unpublish')->getForm(),
'unpublish action has no form when page is draft after published'
);
$this->assertEmpty(
$actions->fieldByName('ActionMenus.MoreOptions.action_archive')->getForm(),
'archive action has no form when page is draft after published'
);
$this->assertEmpty(
$actions->fieldByName('ActionMenus.MoreOptions.action_rollback')->getForm(),
'rollback action has no form when page is draft after published'
);
$this->assertEmpty(
$actions->fieldByName('ActionMenus.MoreOptions.action_addtocampaign')->getForm(),
'addtocampaign action has no form when page is draft after published'
);
// END DRAFT AFTER PUBLISHED
// BEGIN ARCHIVED
$page->doArchive();
$actions = $page->getCMSActions();
$this->assertEmpty(
$actions->fieldByName('MajorActions.action_restore')->getForm(),
'retore action has no form when page archived'
);
// END ARCHIVED
}
}