2011-07-15 16:05:58 +02:00
|
|
|
<?php
|
2016-06-23 01:51:20 +02:00
|
|
|
|
2017-08-09 04:53:38 +02:00
|
|
|
namespace SilverStripe\CMS\Tests\Controllers;
|
2017-08-09 03:25:12 +02:00
|
|
|
|
2016-07-22 01:32:32 +02:00
|
|
|
use SilverStripe\CMS\Controllers\SilverStripeNavigator;
|
2018-02-19 23:03:23 +01:00
|
|
|
use SilverStripe\CMS\Controllers\SilverStripeNavigatorItem_ArchiveLink;
|
|
|
|
use SilverStripe\CMS\Controllers\SilverStripeNavigatorItem_LiveLink;
|
2017-08-09 04:53:38 +02:00
|
|
|
use SilverStripe\CMS\Controllers\SilverStripeNavigatorItem_StageLink;
|
2022-05-06 04:29:22 +02:00
|
|
|
use SilverStripe\CMS\Controllers\SilverStripeNavigatorItem_Unversioned;
|
2016-08-23 04:36:06 +02:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
2011-07-15 16:05:58 +02:00
|
|
|
|
2017-01-25 21:59:25 +01:00
|
|
|
class SilverStripeNavigatorTest extends SapphireTest
|
|
|
|
{
|
|
|
|
protected static $fixture_file = 'CMSMainTest.yml';
|
|
|
|
|
2018-02-19 23:03:23 +01:00
|
|
|
protected static $extra_dataobjects = [
|
|
|
|
SilverStripeNavigatorTest\UnstagedRecord::class,
|
2022-05-06 04:29:22 +02:00
|
|
|
SilverStripeNavigatorTest\UnversionedRecord::class,
|
|
|
|
SilverStripeNavigatorTest\VersionedRecord::class,
|
2018-02-19 23:03:23 +01:00
|
|
|
];
|
|
|
|
|
2022-05-06 04:29:22 +02:00
|
|
|
public function testGetItemsAutoDiscovery(): void
|
2017-01-25 21:59:25 +01:00
|
|
|
{
|
2022-05-06 04:29:22 +02:00
|
|
|
$record = new SilverStripeNavigatorTest\VersionedRecord();
|
|
|
|
$record->PreviewLinkTestProperty = 'some-value';
|
|
|
|
$record->write();
|
|
|
|
$navigator = new SilverStripeNavigator($record);
|
|
|
|
$classes = array_map('get_class', $navigator->getItems()->toArray());
|
2017-01-25 21:59:25 +01:00
|
|
|
|
|
|
|
$this->assertContains(
|
2017-08-09 04:53:38 +02:00
|
|
|
SilverStripeNavigatorTest_TestItem::class,
|
2017-01-25 21:59:25 +01:00
|
|
|
$classes,
|
|
|
|
'Autodiscovers new classes'
|
|
|
|
);
|
2022-05-06 04:29:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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());
|
2018-02-19 23:03:23 +01:00
|
|
|
|
2022-05-06 04:29:22 +02:00
|
|
|
// 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);
|
2017-01-25 21:59:25 +01:00
|
|
|
}
|
|
|
|
|
2022-05-06 04:29:22 +02:00
|
|
|
public function testGetItemsUnstaged(): void
|
2017-01-25 21:59:25 +01:00
|
|
|
{
|
2022-05-06 04:29:22 +02:00
|
|
|
$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);
|
2018-02-19 23:03:23 +01:00
|
|
|
$this->assertNotContains(SilverStripeNavigatorItem_LiveLink::class, $classes);
|
|
|
|
$this->assertNotContains(SilverStripeNavigatorItem_StageLink::class, $classes);
|
2022-05-06 04:29:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2018-02-19 23:03:23 +01:00
|
|
|
$this->assertNotContains(SilverStripeNavigatorItem_ArchiveLink::class, $classes);
|
2022-05-06 04:29:22 +02:00
|
|
|
$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());
|
2017-01-25 21:59:25 +01:00
|
|
|
}
|
2011-07-15 16:05:58 +02:00
|
|
|
}
|