silverstripe-cms/tests/php/Controllers/SilverStripeNavigatorTest.php

52 lines
1.7 KiB
PHP
Raw Normal View History

<?php
2017-08-09 14:53:38 +12:00
namespace SilverStripe\CMS\Tests\Controllers;
2017-08-09 13:25:12 +12:00
2016-07-22 11:32:32 +12:00
use SilverStripe\CMS\Controllers\SilverStripeNavigator;
2017-08-09 14:53:38 +12:00
use SilverStripe\CMS\Controllers\SilverStripeNavigatorItem_StageLink;
use SilverStripe\Dev\SapphireTest;
2017-08-09 14:53:38 +12:00
use SilverStripe\Security\Member;
2017-01-26 09:59:25 +13: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(
SilverStripeNavigatorItem_StageLink::class,
2017-01-26 09:59:25 +13:00
$classes,
'Adds default classes'
);
$this->assertContains(
2017-08-09 14:53:38 +12:00
SilverStripeNavigatorTest_TestItem::class,
2017-01-26 09:59:25 +13:00
$classes,
'Autodiscovers new classes'
);
}
public function testCanView()
{
$page = $this->objFromFixture('Page', 'page1');
$admin = $this->objFromFixture(Member::class, 'admin');
2017-01-26 09:59:25 +13: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 14:53:38 +12:00
$this->assertNotContains(SilverStripeNavigatorTest_ProtectedTestItem::class, $classes);
2017-01-26 09:59:25 +13:00
$this->logInWithPermission('ADMIN');
$items = $navigator->getItems();
$classes = array_map('get_class', $items->toArray());
2017-08-09 14:53:38 +12:00
$this->assertContains(SilverStripeNavigatorTest_ProtectedTestItem::class, $classes);
2017-01-26 09:59:25 +13:00
}
}