From d7857ebbe001f20de59e29902089108f2a8bf465 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Sat, 6 Aug 2022 19:07:24 +1200 Subject: [PATCH] API Migrate SilverStripeNagivator classes These classes are useful with `silverstripe/admin` and `silverstripe/versioned` without needing `silverstripe/cms`. --- code/Controllers/CMSMain.php | 1 + code/Controllers/ContentController.php | 1 + code/Controllers/SilverStripeNavigator.php | 107 -------- .../Controllers/SilverStripeNavigatorItem.php | 136 ---------- .../SilverStripeNavigatorItem_ArchiveLink.php | 71 ------ .../SilverStripeNavigatorItem_CMSLink.php | 1 + .../SilverStripeNavigatorItem_LiveLink.php | 89 ------- .../SilverStripeNavigatorItem_StageLink.php | 99 -------- .../SilverStripeNavigatorItem_Unversioned.php | 80 ------ lang/en.yml | 5 - .../Includes/CMSMain_PreviewPanel.ss | 16 -- .../Controllers/SilverStripeNavigatorTest.php | 238 ------------------ .../UnstagedRecord.php | 48 ---- .../UnversionedRecord.php | 36 --- .../VersionedRecord.php | 42 ---- .../SilverStripeNavigatorTest_TestItem.php | 19 -- 16 files changed, 3 insertions(+), 986 deletions(-) delete mode 100644 code/Controllers/SilverStripeNavigator.php delete mode 100644 code/Controllers/SilverStripeNavigatorItem.php delete mode 100644 code/Controllers/SilverStripeNavigatorItem_ArchiveLink.php delete mode 100644 code/Controllers/SilverStripeNavigatorItem_LiveLink.php delete mode 100644 code/Controllers/SilverStripeNavigatorItem_StageLink.php delete mode 100644 code/Controllers/SilverStripeNavigatorItem_Unversioned.php delete mode 100644 templates/SilverStripe/CMS/Controllers/Includes/CMSMain_PreviewPanel.ss delete mode 100644 tests/php/Controllers/SilverStripeNavigatorTest.php delete mode 100644 tests/php/Controllers/SilverStripeNavigatorTest/UnstagedRecord.php delete mode 100644 tests/php/Controllers/SilverStripeNavigatorTest/UnversionedRecord.php delete mode 100644 tests/php/Controllers/SilverStripeNavigatorTest/VersionedRecord.php delete mode 100644 tests/php/Controllers/SilverStripeNavigatorTest_TestItem.php diff --git a/code/Controllers/CMSMain.php b/code/Controllers/CMSMain.php index 3074b337..27f540ad 100644 --- a/code/Controllers/CMSMain.php +++ b/code/Controllers/CMSMain.php @@ -8,6 +8,7 @@ use SilverStripe\Admin\AdminRootController; use SilverStripe\Admin\CMSBatchActionHandler; use SilverStripe\Admin\LeftAndMain; use SilverStripe\Admin\LeftAndMainFormRequestHandler; +use SilverStripe\Admin\Navigator\SilverStripeNavigator; use SilverStripe\CMS\BatchActions\CMSBatchAction_Archive; use SilverStripe\CMS\BatchActions\CMSBatchAction_Publish; use SilverStripe\CMS\BatchActions\CMSBatchAction_Restore; diff --git a/code/Controllers/ContentController.php b/code/Controllers/ContentController.php index 3fcb51f9..204fd2e3 100644 --- a/code/Controllers/ContentController.php +++ b/code/Controllers/ContentController.php @@ -2,6 +2,7 @@ namespace SilverStripe\CMS\Controllers; +use SilverStripe\Admin\Navigator\SilverStripeNavigator; use SilverStripe\CMS\Model\SiteTree; use SilverStripe\Control\Controller; use SilverStripe\Control\Director; diff --git a/code/Controllers/SilverStripeNavigator.php b/code/Controllers/SilverStripeNavigator.php deleted file mode 100644 index dce05372..00000000 --- a/code/Controllers/SilverStripeNavigator.php +++ /dev/null @@ -1,107 +0,0 @@ -record = $record; - } - - /** - * @return SS_List of SilverStripeNavigatorItem - */ - public function getItems() - { - $items = []; - - $classes = ClassInfo::subclassesFor(SilverStripeNavigatorItem::class); - array_shift($classes); - - // Sort menu items according to priority - foreach ($classes as $class) { - /** @var SilverStripeNavigatorItem $item */ - $item = new $class($this->record); - if (!$item->canView()) { - continue; - } - - // This funny litle formula ensures that the first item added with the same priority will be left-most. - $priority = $item->getPriority() * 100 - 1; - - // Ensure that we can have duplicates with the same (default) priority - while (isset($items[$priority])) { - $priority++; - } - - $items[$priority] = $item; - } - ksort($items); - - // Drop the keys and let the ArrayList handle the numbering, so $First, $Last and others work properly. - return new ArrayList(array_values($items ?? [])); - } - - /** - * @return DataObject|\SilverStripe\ORM\CMSPreviewable - */ - public function getRecord() - { - return $this->record; - } - - /** - * @param DataObject|CMSPreviewable $record - * @return array template data - */ - public static function get_for_record($record) - { - $html = ''; - $message = ''; - $navigator = new SilverStripeNavigator($record); - $items = $navigator->getItems(); - foreach ($items as $item) { - $text = $item->getHTML(); - if ($text) { - $html .= $text; - } - $newMessage = $item->getMessage(); - if ($newMessage && $item->isActive()) { - $message = $newMessage; - } - } - - return [ - 'items' => $html, - 'message' => $message - ]; - } -} diff --git a/code/Controllers/SilverStripeNavigatorItem.php b/code/Controllers/SilverStripeNavigatorItem.php deleted file mode 100644 index 4c5644a4..00000000 --- a/code/Controllers/SilverStripeNavigatorItem.php +++ /dev/null @@ -1,136 +0,0 @@ -record = $record; - } - - /** - * @return string HTML, mostly a link - but can be more complex as well. - * For example, a "future state" item might show a date selector. - */ - abstract public function getHTML(); - - /** - * @return string - * Get the Title of an item - */ - abstract public function getTitle(); - - /** - * Machine-friendly name. - * - * @return string - */ - public function getName() - { - return substr(static::class, strpos(static::class, '_') + 1); - } - - /** - * Optional link to a specific view of this record. - * Not all items are simple links, please use {@link getHTML()} - * to represent an item in markup unless you know what you're doing. - * - * @return string - */ - public function getLink() - { - return null; - } - - /** - * @return string - */ - public function getMessage() - { - return null; - } - - /** - * @return DataObject - */ - public function getRecord() - { - return $this->record; - } - - /** - * @return int - */ - public function getPriority() - { - return $this->config()->get('priority'); - } - - /** - * As items might convey different record states like a "stage" or "live" table, - * an item can be active (showing the record in this state). - * - * @return boolean - */ - public function isActive() - { - return false; - } - - /** - * Filters items based on member permissions or other criteria, - * such as if a state is generally available for the current record. - * - * @param Member $member - * @return Boolean - */ - public function canView($member = null) - { - return true; - } - - /** - * Counts as "archived" if the current record is a different version from both live and draft. - * - * @return boolean - */ - public function isArchived() - { - /** @var Versioned|DataObject $record */ - $record = $this->record; - if (!$record->hasExtension(Versioned::class) || !$record->hasStages()) { - return false; - } - - if (!isset($record->_cached_isArchived)) { - $record->_cached_isArchived = $record->isArchived(); - } - - return $record->_cached_isArchived; - } -} diff --git a/code/Controllers/SilverStripeNavigatorItem_ArchiveLink.php b/code/Controllers/SilverStripeNavigatorItem_ArchiveLink.php deleted file mode 100644 index 52627557..00000000 --- a/code/Controllers/SilverStripeNavigatorItem_ArchiveLink.php +++ /dev/null @@ -1,71 +0,0 @@ -isActive() ? 'ss-ui-button current' : 'ss-ui-button'; - $linkTitle = _t('SilverStripe\\CMS\\Controllers\\ContentController.ARCHIVEDSITE', 'Preview version'); - $recordLink = Convert::raw2att(Controller::join_links( - $this->record->AbsoluteLink(), - '?archiveDate=' . urlencode($this->record->LastEdited ?? '') - )); - return "$linkTitle"; - } - - public function getTitle() - { - return _t('SilverStripe\\CMS\\Controllers\\SilverStripeNavigator.ARCHIVED', 'Archived'); - } - - public function getMessage() - { - $date = Versioned::current_archived_date(); - if (empty($date)) { - return null; - } - /** @var DBDatetime $dateObj */ - $dateObj = DBField::create_field('Datetime', $date); - $title = _t('SilverStripe\\CMS\\Controllers\\ContentController.NOTEWONTBESHOWN', 'Note: this message will not be shown to your visitors'); - return "
" - . _t('SilverStripe\\CMS\\Controllers\\ContentController.ARCHIVEDSITEFROM', 'Archived site from') - . "
" . $dateObj->Nice() . "
"; - } - - public function getLink() - { - $link = $this->record->PreviewLink(); - return $link ? Controller::join_links($link, '?archiveDate=' . urlencode($this->record->LastEdited ?? '')) : ''; - } - - public function canView($member = null) - { - /** @var Versioned|DataObject $record */ - $record = $this->record; - return ( - $record->hasExtension(Versioned::class) - && $record->hasStages() - && $this->isArchived() - // Don't follow redirects in preview, they break the CMS editing form - && !($record instanceof RedirectorPage) - && $this->getLink() - ); - } - - public function isActive() - { - return $this->isArchived(); - } -} diff --git a/code/Controllers/SilverStripeNavigatorItem_CMSLink.php b/code/Controllers/SilverStripeNavigatorItem_CMSLink.php index 85f85fce..eb888e67 100644 --- a/code/Controllers/SilverStripeNavigatorItem_CMSLink.php +++ b/code/Controllers/SilverStripeNavigatorItem_CMSLink.php @@ -3,6 +3,7 @@ namespace SilverStripe\CMS\Controllers; use SilverStripe\Admin\LeftAndMain; +use SilverStripe\Admin\Navigator\SilverStripeNavigatorItem; use SilverStripe\CMS\Model\RedirectorPage; use SilverStripe\Control\Controller; diff --git a/code/Controllers/SilverStripeNavigatorItem_LiveLink.php b/code/Controllers/SilverStripeNavigatorItem_LiveLink.php deleted file mode 100644 index 32d72029..00000000 --- a/code/Controllers/SilverStripeNavigatorItem_LiveLink.php +++ /dev/null @@ -1,89 +0,0 @@ -getLivePage(); - if (!$livePage) { - return null; - } - - $linkClass = $this->isActive() ? 'class="current" ' : ''; - $linkTitle = _t('SilverStripe\\CMS\\Controllers\\ContentController.PUBLISHEDSITE', 'Published Site'); - $recordLink = Convert::raw2att(Controller::join_links($livePage->AbsoluteLink(), "?stage=Live")); - return "$linkTitle"; - } - - public function getTitle() - { - return _t( - 'SilverStripe\\CMS\\Controllers\\ContentController.PUBLISHED', - 'Published', - 'Used for the Switch between draft and published view mode. Needs to be a short label' - ); - } - - public function getMessage() - { - return "
" . _t( - 'SilverStripe\\CMS\\Controllers\\ContentController.PUBLISHEDSITE', - 'Published Site' - ) . "
"; - } - - public function getLink() - { - $link = $this->getLivePage()->PreviewLink(); - return $link ? Controller::join_links($link, '?stage=Live') : ''; - } - - public function canView($member = null) - { - /** @var Versioned|DataObject $record */ - $record = $this->record; - return ( - $record->hasExtension(Versioned::class) - && $this->showLiveLink() - && $record->hasStages() - && $this->getLivePage() - && $this->getLink() - ); - } - - /** - * @return bool - */ - public function showLiveLink() - { - return (bool)Config::inst()->get(get_class($this->record), 'show_live_link'); - } - - public function isActive() - { - return ( - (!Versioned::get_stage() || Versioned::get_stage() == 'Live') - && !$this->isArchived() - ); - } - - protected function getLivePage() - { - $baseClass = $this->record->baseClass(); - return Versioned::get_by_stage($baseClass, Versioned::LIVE)->byID($this->record->ID); - } -} diff --git a/code/Controllers/SilverStripeNavigatorItem_StageLink.php b/code/Controllers/SilverStripeNavigatorItem_StageLink.php deleted file mode 100644 index 280f8cd9..00000000 --- a/code/Controllers/SilverStripeNavigatorItem_StageLink.php +++ /dev/null @@ -1,99 +0,0 @@ -getDraftPage(); - if (!$draftPage) { - return null; - } - $linkClass = $this->isActive() ? 'class="current" ' : ''; - $linkTitle = _t('SilverStripe\\CMS\\Controllers\\ContentController.DRAFTSITE', 'Draft Site'); - $recordLink = Convert::raw2att(Controller::join_links($draftPage->AbsoluteLink(), "?stage=Stage")); - return "$linkTitle"; - } - - public function getTitle() - { - return _t( - 'SilverStripe\\CMS\\Controllers\\ContentController.DRAFT', - 'Draft', - 'Used for the Switch between draft and published view mode. Needs to be a short label' - ); - } - - public function getMessage() - { - return "
" . _t( - 'SilverStripe\\CMS\\Controllers\\ContentController.DRAFTSITE', - 'Draft Site' - ) . "
"; - } - - public function getLink() - { - $date = Versioned::current_archived_date(); - $link = $this->record->PreviewLink(); - if (!$link) { - return ''; - } - return Controller::join_links( - $link, - '?stage=Stage', - $date ? '?archiveDate=' . $date : null - ); - } - - public function canView($member = null) - { - /** @var Versioned|DataObject $record */ - $record = $this->record; - return ( - $record->hasExtension(Versioned::class) - && $this->showStageLink() - && $record->hasStages() - && $this->getDraftPage() - && $this->getLink() - ); - } - - /** - * @return bool - */ - public function showStageLink() - { - return (bool)Config::inst()->get(get_class($this->record), 'show_stage_link'); - } - - public function isActive() - { - return ( - Versioned::get_stage() == 'Stage' - && !(ClassInfo::exists('SiteTreeFutureState') && SiteTreeFutureState::get_future_datetime()) - && !$this->isArchived() - ); - } - - protected function getDraftPage() - { - $baseClass = $this->record->baseClass(); - return Versioned::get_by_stage($baseClass, Versioned::DRAFT)->byID($this->record->ID); - } -} diff --git a/code/Controllers/SilverStripeNavigatorItem_Unversioned.php b/code/Controllers/SilverStripeNavigatorItem_Unversioned.php deleted file mode 100644 index 2ee5f4e3..00000000 --- a/code/Controllers/SilverStripeNavigatorItem_Unversioned.php +++ /dev/null @@ -1,80 +0,0 @@ -getLink()); - $linkTitle = _t('SilverStripe\\CMS\\Controllers\\ContentController.UNVERSIONEDPREVIEW', 'Preview'); - return "$linkTitle"; - } - - public function getLink() - { - return $this->getRecord()->PreviewLink() ?? ''; - } - - public function getTitle() - { - return _t( - 'SilverStripe\\CMS\\Controllers\\ContentController.UNVERSIONEDPREVIEW', - 'Preview', - 'Used for the Switch between states (if any other other states are added). Needs to be a short label' - ); - } - - /** - * True if the record doesn't have the Versioned extension and is configured to display this item. - * - * @param Member $member - * @return bool - */ - public function canView($member = null) - { - return ( - $this->recordIsUnversioned() - && $this->showUnversionedLink() - && $this->getLink() - ); - } - - private function recordIsUnversioned(): bool - { - $record = $this->getRecord(); - // If the record has the Versioned extension, it can be considered unversioned - // for the purposes of this class if it has no stages and is not archived. - if ($record->hasExtension(Versioned::class)) { - return (!$record->hasStages()) && !$this->isArchived(); - } - // Completely unversioned. - return true; - } - - /** - * True if the record is configured to display this item. - * - * @return bool - */ - public function showUnversionedLink(): bool - { - return (bool) Config::inst()->get(get_class($this->record), 'show_unversioned_preview_link'); - } - - /** - * This item is always active, as there are unlikely to be other preview states available for the record. - * - * @return bool - */ - public function isActive() - { - return true; - } -} diff --git a/lang/en.yml b/lang/en.yml index a539d294..7f71d59a 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -114,8 +114,6 @@ en: SilverStripe\CMS\Controllers\CMSSiteTreeFilter_StatusRemovedFromDraftPages: Title: 'Live but removed from draft' SilverStripe\CMS\Controllers\ContentController: - ARCHIVEDSITE: 'Preview version' - ARCHIVEDSITEFROM: 'Archived site from' CMS: CMS DRAFT: Draft DRAFTSITE: 'Draft Site' @@ -134,11 +132,8 @@ en: Password: Password PostInstallTutorialIntro: 'This website is a simplistic version of a SilverStripe 3 site. To extend this, please take a look at {link}.' StartEditing: 'You can start editing your content by opening the CMS.' - UNVERSIONEDPREVIEW: Preview UnableDeleteInstall: 'Unable to delete installation files. Please delete the files below manually' VIEWPAGEIN: 'View Page in:' - SilverStripe\CMS\Controllers\SilverStripeNavigator: - ARCHIVED: Archived SilverStripe\CMS\Forms\AnchorLinkFormFactory: ANCHORVALUE: Anchor SilverStripe\CMS\Forms\InternalLinkFormFactory: diff --git a/templates/SilverStripe/CMS/Controllers/Includes/CMSMain_PreviewPanel.ss b/templates/SilverStripe/CMS/Controllers/Includes/CMSMain_PreviewPanel.ss deleted file mode 100644 index 65e1bbab..00000000 --- a/templates/SilverStripe/CMS/Controllers/Includes/CMSMain_PreviewPanel.ss +++ /dev/null @@ -1,16 +0,0 @@ -
-
-
-
- <%t SilverStripe\CMS\Controllers\CMSPageHistoryController.NO_PREVIEW 'No preview available' %> -
-
-
-
- -
-
-
-
-
-
diff --git a/tests/php/Controllers/SilverStripeNavigatorTest.php b/tests/php/Controllers/SilverStripeNavigatorTest.php deleted file mode 100644 index 1e799f64..00000000 --- a/tests/php/Controllers/SilverStripeNavigatorTest.php +++ /dev/null @@ -1,238 +0,0 @@ -PreviewLinkTestProperty = 'some-value'; - $record->write(); - $navigator = new SilverStripeNavigator($record); - $classes = array_map('get_class', $navigator->getItems()->toArray()); - - $this->assertContains( - SilverStripeNavigatorTest_TestItem::class, - $classes, - 'Autodiscovers new classes' - ); - } - - public function testGetItemsPublished(): void - { - $record = new SilverStripeNavigatorTest\VersionedRecord(); - $record->PreviewLinkTestProperty = 'some-value'; - $record->write(); - $record->publishRecursive(); - $navigator = new SilverStripeNavigator($record); - $classes = array_map('get_class', $navigator->getItems()->toArray()); - - // Has the live and staged links - $this->assertContains(SilverStripeNavigatorItem_LiveLink::class, $classes); - $this->assertContains(SilverStripeNavigatorItem_StageLink::class, $classes); - - // Does not have the other links - $this->assertNotContains(SilverStripeNavigatorItem_ArchiveLink::class, $classes); - $this->assertNotContains(SilverStripeNavigatorItem_Unversioned::class, $classes); - } - - public function testGetItemsStaged(): void - { - $record = new SilverStripeNavigatorTest\VersionedRecord(); - $record->PreviewLinkTestProperty = 'some-value'; - $record->write(); - $navigator = new SilverStripeNavigator($record); - $classes = array_map('get_class', $navigator->getItems()->toArray()); - - // Has the stage link - $this->assertContains(SilverStripeNavigatorItem_StageLink::class, $classes); - - // Does not have the other links - $this->assertNotContains(SilverStripeNavigatorItem_ArchiveLink::class, $classes); - $this->assertNotContains(SilverStripeNavigatorItem_LiveLink::class, $classes); - $this->assertNotContains(SilverStripeNavigatorItem_Unversioned::class, $classes); - } - - public function testGetItemsArchived(): void - { - $record = new SilverStripeNavigatorTest\VersionedRecord(); - $record->PreviewLinkTestProperty = 'some-value'; - $record->write(); - $record->doArchive(); - $navigator = new SilverStripeNavigator($record); - $classes = array_map('get_class', $navigator->getItems()->toArray()); - - // Has the archived link - $this->assertContains(SilverStripeNavigatorItem_ArchiveLink::class, $classes); - - // Does not have the other links - $this->assertNotContains(SilverStripeNavigatorItem_LiveLink::class, $classes); - $this->assertNotContains(SilverStripeNavigatorItem_StageLink::class, $classes); - $this->assertNotContains(SilverStripeNavigatorItem_UnversionedLink::class, $classes); - } - - public function testGetItemsUnstaged(): void - { - $record = new SilverStripeNavigatorTest\UnstagedRecord(); - $record->previewLinkTestProperty = 'some-value'; - $record->write(); - $navigator = new SilverStripeNavigator($record); - $classes = array_map('get_class', $navigator->getItems()->toArray()); - - // Has the unversioned link - $this->assertContains(SilverStripeNavigatorItem_Unversioned::class, $classes); - - // Does not have the other links - $this->assertNotContains(SilverStripeNavigatorItem_ArchiveLink::class, $classes); - $this->assertNotContains(SilverStripeNavigatorItem_LiveLink::class, $classes); - $this->assertNotContains(SilverStripeNavigatorItem_StageLink::class, $classes); - } - - public function testGetItemsUnversioned(): void - { - $record = new SilverStripeNavigatorTest\UnversionedRecord(); - $record->previewLinkTestProperty = 'some-value'; - $record->write(); - $navigator = new SilverStripeNavigator($record); - $classes = array_map('get_class', $navigator->getItems()->toArray()); - - // Has the unversioned link - $this->assertContains(SilverStripeNavigatorItem_Unversioned::class, $classes); - - // Does not have the other links - $this->assertNotContains(SilverStripeNavigatorItem_ArchiveLink::class, $classes); - $this->assertNotContains(SilverStripeNavigatorItem_LiveLink::class, $classes); - $this->assertNotContains(SilverStripeNavigatorItem_StageLink::class, $classes); - } - - public function testCanViewPublished(): void - { - $record = new SilverStripeNavigatorTest\VersionedRecord(); - $record->write(); - $record->publishRecursive(); - $liveLinkItem = new SilverStripeNavigatorItem_LiveLink($record); - $stagedLinkItem = new SilverStripeNavigatorItem_StageLink($record); - $archivedLinkItem = new SilverStripeNavigatorItem_ArchiveLink($record); - $unversionedLinkItem = new SilverStripeNavigatorItem_Unversioned($record); - - // Cannot view staged and live links when there's no preview link - $this->assertFalse($liveLinkItem->canView()); - $this->assertFalse($stagedLinkItem->canView()); - - $record->PreviewLinkTestProperty = 'some-value'; - $record->write(); - $record->publishRecursive(); - - // Can view staged and live links - $this->assertTrue($liveLinkItem->canView()); - $this->assertTrue($stagedLinkItem->canView()); - // Cannot view the other links - $this->assertFalse($archivedLinkItem->canView()); - $this->assertFalse($unversionedLinkItem->canView()); - } - - public function testCanViewStaged(): void - { - $record = new SilverStripeNavigatorTest\VersionedRecord(); - $record->write(); - $liveLinkItem = new SilverStripeNavigatorItem_LiveLink($record); - $stagedLinkItem = new SilverStripeNavigatorItem_StageLink($record); - $archivedLinkItem = new SilverStripeNavigatorItem_ArchiveLink($record); - $unversionedLinkItem = new SilverStripeNavigatorItem_Unversioned($record); - - // Cannot view staged link when there's no preview link - $this->assertFalse($stagedLinkItem->canView()); - - $record->PreviewLinkTestProperty = 'some-value'; - - // Can view staged link - $this->assertTrue($stagedLinkItem->canView()); - // Cannot view the other links - $this->assertFalse($liveLinkItem->canView()); - $this->assertFalse($archivedLinkItem->canView()); - $this->assertFalse($unversionedLinkItem->canView()); - } - - public function testCanViewArchived(): void - { - $record = new SilverStripeNavigatorTest\VersionedRecord(); - $record->write(); - $record->doArchive(); - $liveLinkItem = new SilverStripeNavigatorItem_LiveLink($record); - $stagedLinkItem = new SilverStripeNavigatorItem_StageLink($record); - $archivedLinkItem = new SilverStripeNavigatorItem_ArchiveLink($record); - $unversionedLinkItem = new SilverStripeNavigatorItem_Unversioned($record); - - // Cannot view archived link when there's no preview link - $this->assertFalse($archivedLinkItem->canView()); - - $record->PreviewLinkTestProperty = 'some-value'; - - // Can view archived link - $this->assertTrue($archivedLinkItem->canView()); - // Cannot view the other links - $this->assertFalse($liveLinkItem->canView()); - $this->assertFalse($stagedLinkItem->canView()); - $this->assertFalse($unversionedLinkItem->canView()); - } - - public function testCanViewUnstaged(): void - { - $record = new SilverStripeNavigatorTest\UnstagedRecord(); - $record->write(); - $liveLinkItem = new SilverStripeNavigatorItem_LiveLink($record); - $stagedLinkItem = new SilverStripeNavigatorItem_StageLink($record); - $archivedLinkItem = new SilverStripeNavigatorItem_ArchiveLink($record); - $unversionedLinkItem = new SilverStripeNavigatorItem_Unversioned($record); - - // Cannot view unversioned link when there's no preview link - $this->assertFalse($unversionedLinkItem->canView()); - - $record->previewLinkTestProperty = 'some-value'; - - // Can view unversioned link - $this->assertTrue($unversionedLinkItem->canView()); - // Cannot view the other links - $this->assertFalse($liveLinkItem->canView()); - $this->assertFalse($stagedLinkItem->canView()); - $this->assertFalse($archivedLinkItem->canView()); - } - - public function testCanViewUnversioned(): void - { - $record = new SilverStripeNavigatorTest\UnversionedRecord(); - $record->write(); - $liveLinkItem = new SilverStripeNavigatorItem_LiveLink($record); - $stagedLinkItem = new SilverStripeNavigatorItem_StageLink($record); - $archivedLinkItem = new SilverStripeNavigatorItem_ArchiveLink($record); - $unversionedLinkItem = new SilverStripeNavigatorItem_Unversioned($record); - - // Cannot view unversioned link when there's no preview link - $this->assertFalse($unversionedLinkItem->canView()); - - $record->previewLinkTestProperty = 'some-value'; - - // Can view unversioned link - $this->assertTrue($unversionedLinkItem->canView()); - // Cannot view the other links - $this->assertFalse($liveLinkItem->canView()); - $this->assertFalse($stagedLinkItem->canView()); - $this->assertFalse($archivedLinkItem->canView()); - } -} diff --git a/tests/php/Controllers/SilverStripeNavigatorTest/UnstagedRecord.php b/tests/php/Controllers/SilverStripeNavigatorTest/UnstagedRecord.php deleted file mode 100644 index c85889b1..00000000 --- a/tests/php/Controllers/SilverStripeNavigatorTest/UnstagedRecord.php +++ /dev/null @@ -1,48 +0,0 @@ -previewLinkTestProperty; - } - - /** - * To determine preview mechanism (e.g. embedded / iframe) - * - * @return string - */ - public function getMimeType() - { - return 'text/html'; - } - - public function CMSEditLink() - { - return null; - } -} diff --git a/tests/php/Controllers/SilverStripeNavigatorTest/UnversionedRecord.php b/tests/php/Controllers/SilverStripeNavigatorTest/UnversionedRecord.php deleted file mode 100644 index 9198b89c..00000000 --- a/tests/php/Controllers/SilverStripeNavigatorTest/UnversionedRecord.php +++ /dev/null @@ -1,36 +0,0 @@ -previewLinkTestProperty; - } - - public function getMimeType() - { - return 'text/html'; - } - - public function CMSEditLink() - { - return null; - } -} diff --git a/tests/php/Controllers/SilverStripeNavigatorTest/VersionedRecord.php b/tests/php/Controllers/SilverStripeNavigatorTest/VersionedRecord.php deleted file mode 100644 index 18dbc6ba..00000000 --- a/tests/php/Controllers/SilverStripeNavigatorTest/VersionedRecord.php +++ /dev/null @@ -1,42 +0,0 @@ - 'Text', - ]; - - private static $extensions = [ - Versioned::class, - ]; - - public function PreviewLink($action = null) - { - return $this->PreviewLinkTestProperty; - } - - public function getMimeType() - { - return 'text/html'; - } - - public function CMSEditLink() - { - return null; - } -} diff --git a/tests/php/Controllers/SilverStripeNavigatorTest_TestItem.php b/tests/php/Controllers/SilverStripeNavigatorTest_TestItem.php deleted file mode 100644 index bb473cea..00000000 --- a/tests/php/Controllers/SilverStripeNavigatorTest_TestItem.php +++ /dev/null @@ -1,19 +0,0 @@ -