2011-07-15 16:05:58 +02:00
|
|
|
<?php
|
2016-06-23 01:51:20 +02:00
|
|
|
|
|
|
|
use SilverStripe\Security\Member;
|
|
|
|
use SilverStripe\Security\Permission;
|
2016-07-22 01:32:32 +02:00
|
|
|
use SilverStripe\CMS\Controllers\SilverStripeNavigator;
|
|
|
|
use SilverStripe\CMS\Controllers\SilverStripeNavigatorItem;
|
2016-08-23 04:36:06 +02:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
use SilverStripe\Dev\TestOnly;
|
|
|
|
|
2011-07-15 16:05:58 +02:00
|
|
|
/**
|
|
|
|
* @package cms
|
|
|
|
* @subpackage tests
|
|
|
|
*/
|
|
|
|
|
2017-01-25 21:59:25 +01:00
|
|
|
class SilverStripeNavigatorTest extends SapphireTest
|
|
|
|
{
|
|
|
|
|
|
|
|
protected static $fixture_file = 'CMSMainTest.yml';
|
|
|
|
|
|
|
|
public function testGetItems()
|
|
|
|
{
|
|
|
|
$page = $this->objFromFixture('Page', 'page1');
|
|
|
|
$navigator = new SilverStripeNavigator($page);
|
|
|
|
|
|
|
|
$items = $navigator->getItems();
|
|
|
|
$classes = array_map('get_class', $items->toArray());
|
|
|
|
$this->assertContains(
|
|
|
|
'SilverStripe\\CMS\\Controllers\\SilverStripeNavigatorItem_StageLink',
|
|
|
|
$classes,
|
|
|
|
'Adds default classes'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertContains(
|
|
|
|
'SilverStripeNavigatorTest_TestItem',
|
|
|
|
$classes,
|
|
|
|
'Autodiscovers new classes'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCanView()
|
|
|
|
{
|
|
|
|
$page = $this->objFromFixture('Page', 'page1');
|
|
|
|
$admin = $this->objFromFixture('SilverStripe\\Security\\Member', 'admin');
|
|
|
|
$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());
|
|
|
|
$this->assertNotContains('SilverStripeNavigatorTest_ProtectedTestItem', $classes);
|
|
|
|
|
|
|
|
$this->logInWithPermission('ADMIN');
|
|
|
|
$items = $navigator->getItems();
|
|
|
|
$classes = array_map('get_class', $items->toArray());
|
|
|
|
$this->assertContains('SilverStripeNavigatorTest_ProtectedTestItem', $classes);
|
|
|
|
}
|
2011-07-15 16:05:58 +02:00
|
|
|
}
|
|
|
|
|
2017-01-25 21:59:25 +01:00
|
|
|
class SilverStripeNavigatorTest_TestItem extends SilverStripeNavigatorItem implements TestOnly
|
|
|
|
{
|
|
|
|
public function getTitle()
|
|
|
|
{
|
|
|
|
return self::class;
|
|
|
|
}
|
|
|
|
public function getHTML()
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
2011-07-15 16:05:58 +02:00
|
|
|
}
|
|
|
|
|
2017-01-25 21:59:25 +01:00
|
|
|
class SilverStripeNavigatorTest_ProtectedTestItem extends SilverStripeNavigatorItem implements TestOnly
|
|
|
|
{
|
|
|
|
|
|
|
|
public function getTitle()
|
|
|
|
{
|
|
|
|
return self::class;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getHTML()
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function canView($member = null)
|
|
|
|
{
|
|
|
|
if (!$member) {
|
|
|
|
$member = Member::currentUser();
|
|
|
|
}
|
|
|
|
return Permission::checkMember($member, 'ADMIN');
|
|
|
|
}
|
2012-04-12 09:23:20 +02:00
|
|
|
}
|