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;
|
|
|
|
|
2016-07-22 01:32:32 +02:00
|
|
|
|
2011-07-15 16:05:58 +02:00
|
|
|
/**
|
|
|
|
* @package cms
|
|
|
|
* @subpackage tests
|
|
|
|
*/
|
|
|
|
|
|
|
|
class SilverStripeNavigatorTest extends SapphireTest {
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2016-10-28 06:45:01 +02:00
|
|
|
protected static $fixture_file = 'CMSMainTest.yml';
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testGetItems() {
|
2011-07-15 16:05:58 +02:00
|
|
|
$page = $this->objFromFixture('Page', 'page1');
|
|
|
|
$navigator = new SilverStripeNavigator($page);
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-07-15 16:05:58 +02:00
|
|
|
$items = $navigator->getItems();
|
|
|
|
$classes = array_map('get_class', $items->toArray());
|
2016-07-22 01:32:32 +02:00
|
|
|
$this->assertContains('SilverStripe\\CMS\\Controllers\\SilverStripeNavigatorItem_StageLink', $classes,
|
2011-07-15 16:05:58 +02:00
|
|
|
'Adds default classes'
|
|
|
|
);
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-07-15 16:05:58 +02:00
|
|
|
$this->assertContains('SilverStripeNavigatorTest_TestItem', $classes,
|
|
|
|
'Autodiscovers new classes'
|
|
|
|
);
|
|
|
|
}
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testCanView() {
|
2011-07-15 16:05:58 +02:00
|
|
|
$page = $this->objFromFixture('Page', 'page1');
|
2016-06-23 01:51:20 +02:00
|
|
|
$admin = $this->objFromFixture('SilverStripe\\Security\\Member', 'admin');
|
2011-07-15 16:05:58 +02:00
|
|
|
$navigator = new SilverStripeNavigator($page);
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-07-15 16:05:58 +02:00
|
|
|
// TODO Shouldn't be necessary but SapphireTest logs in as ADMIN by default
|
2016-08-31 13:15:12 +02:00
|
|
|
$this->logInWithPermission('CMS_ACCESS_CMSMain');
|
2011-07-15 16:05:58 +02:00
|
|
|
$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);
|
|
|
|
}
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2011-07-15 16:05:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class SilverStripeNavigatorTest_TestItem extends SilverStripeNavigatorItem implements TestOnly {
|
2016-04-27 09:47:25 +02:00
|
|
|
public function getTitle() {
|
2016-09-28 00:39:28 +02:00
|
|
|
return self::class;
|
2016-04-27 09:47:25 +02:00
|
|
|
}
|
|
|
|
public function getHTML() {
|
|
|
|
return null;
|
|
|
|
}
|
2011-07-15 16:05:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class SilverStripeNavigatorTest_ProtectedTestItem extends SilverStripeNavigatorItem implements TestOnly {
|
2016-04-27 09:47:25 +02:00
|
|
|
|
|
|
|
public function getTitle() {
|
2016-09-28 00:39:28 +02:00
|
|
|
return self::class;
|
2016-04-27 09:47:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getHTML() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function canView($member = null) {
|
2011-07-15 16:05:58 +02:00
|
|
|
if(!$member) $member = Member::currentUser();
|
|
|
|
return Permission::checkMember($member, 'ADMIN');
|
|
|
|
}
|
2012-04-12 09:23:20 +02:00
|
|
|
}
|