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;
|
2016-08-23 04:36:06 +02:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
2017-08-09 04:53:38 +02:00
|
|
|
use SilverStripe\Security\Member;
|
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,
|
|
|
|
];
|
|
|
|
|
2017-01-25 21:59:25 +01:00
|
|
|
public function testGetItems()
|
|
|
|
{
|
|
|
|
$page = $this->objFromFixture('Page', 'page1');
|
|
|
|
$navigator = new SilverStripeNavigator($page);
|
|
|
|
|
|
|
|
$items = $navigator->getItems();
|
|
|
|
$classes = array_map('get_class', $items->toArray());
|
|
|
|
$this->assertContains(
|
2017-03-21 05:26:46 +01:00
|
|
|
SilverStripeNavigatorItem_StageLink::class,
|
2017-01-25 21:59:25 +01:00
|
|
|
$classes,
|
|
|
|
'Adds default classes'
|
|
|
|
);
|
|
|
|
|
|
|
|
$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'
|
|
|
|
);
|
2018-02-19 23:03:23 +01:00
|
|
|
|
|
|
|
// Non-versioned items don't have stage / live
|
2017-01-25 21:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testCanView()
|
|
|
|
{
|
|
|
|
$page = $this->objFromFixture('Page', 'page1');
|
2017-03-21 05:26:46 +01:00
|
|
|
$admin = $this->objFromFixture(Member::class, 'admin');
|
2017-01-25 21:59:25 +01:00
|
|
|
$navigator = new SilverStripeNavigator($page);
|
|
|
|
|
|
|
|
// TODO Shouldn't be necessary but SapphireTest logs in as ADMIN by default
|
|
|
|
$this->logInWithPermission('CMS_ACCESS_CMSMain');
|
|
|
|
$items = $navigator->getItems();
|
|
|
|
$classes = array_map('get_class', $items->toArray());
|
2017-08-09 04:53:38 +02:00
|
|
|
$this->assertNotContains(SilverStripeNavigatorTest_ProtectedTestItem::class, $classes);
|
2017-01-25 21:59:25 +01:00
|
|
|
|
|
|
|
$this->logInWithPermission('ADMIN');
|
|
|
|
$items = $navigator->getItems();
|
|
|
|
$classes = array_map('get_class', $items->toArray());
|
2017-08-09 04:53:38 +02:00
|
|
|
$this->assertContains(SilverStripeNavigatorTest_ProtectedTestItem::class, $classes);
|
2018-02-19 23:03:23 +01:00
|
|
|
|
|
|
|
// Unversioned record shouldn't be viewable in stage / live specific views
|
|
|
|
$unversioned = new SilverStripeNavigatorTest\UnstagedRecord();
|
|
|
|
$navigator2 = new SilverStripeNavigator($unversioned);
|
|
|
|
$classes = array_map('get_class', $navigator2->getItems()->toArray());
|
|
|
|
$this->assertNotContains(SilverStripeNavigatorItem_LiveLink::class, $classes);
|
|
|
|
$this->assertNotContains(SilverStripeNavigatorItem_StageLink::class, $classes);
|
|
|
|
$this->assertNotContains(SilverStripeNavigatorItem_ArchiveLink::class, $classes);
|
2017-01-25 21:59:25 +01:00
|
|
|
}
|
2011-07-15 16:05:58 +02:00
|
|
|
}
|