1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\CMS\Tests\Controllers; |
4
|
|
|
|
5
|
|
|
use SilverStripe\CMS\Controllers\SilverStripeNavigator; |
6
|
|
|
use SilverStripe\CMS\Controllers\SilverStripeNavigatorItem_ArchiveLink; |
7
|
|
|
use SilverStripe\CMS\Controllers\SilverStripeNavigatorItem_LiveLink; |
8
|
|
|
use SilverStripe\CMS\Controllers\SilverStripeNavigatorItem_StageLink; |
9
|
|
|
use SilverStripe\Dev\SapphireTest; |
10
|
|
|
use SilverStripe\Security\Member; |
11
|
|
|
|
12
|
|
|
class SilverStripeNavigatorTest extends SapphireTest |
13
|
|
|
{ |
14
|
|
|
protected static $fixture_file = 'CMSMainTest.yml'; |
15
|
|
|
|
16
|
|
|
protected static $extra_dataobjects = [ |
17
|
|
|
SilverStripeNavigatorTest\UnstagedRecord::class, |
18
|
|
|
]; |
19
|
|
|
|
20
|
|
|
public function testGetItems() |
21
|
|
|
{ |
22
|
|
|
$page = $this->objFromFixture('Page', 'page1'); |
23
|
|
|
$navigator = new SilverStripeNavigator($page); |
|
|
|
|
24
|
|
|
|
25
|
|
|
$items = $navigator->getItems(); |
26
|
|
|
$classes = array_map('get_class', $items->toArray()); |
27
|
|
|
$this->assertContains( |
28
|
|
|
SilverStripeNavigatorItem_StageLink::class, |
29
|
|
|
$classes, |
30
|
|
|
'Adds default classes' |
31
|
|
|
); |
32
|
|
|
|
33
|
|
|
$this->assertContains( |
34
|
|
|
SilverStripeNavigatorTest_TestItem::class, |
35
|
|
|
$classes, |
36
|
|
|
'Autodiscovers new classes' |
37
|
|
|
); |
38
|
|
|
|
39
|
|
|
// Non-versioned items don't have stage / live |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testCanView() |
43
|
|
|
{ |
44
|
|
|
$page = $this->objFromFixture('Page', 'page1'); |
45
|
|
|
$admin = $this->objFromFixture(Member::class, 'admin'); |
|
|
|
|
46
|
|
|
$navigator = new SilverStripeNavigator($page); |
|
|
|
|
47
|
|
|
|
48
|
|
|
// TODO Shouldn't be necessary but SapphireTest logs in as ADMIN by default |
49
|
|
|
$this->logInWithPermission('CMS_ACCESS_CMSMain'); |
50
|
|
|
$items = $navigator->getItems(); |
51
|
|
|
$classes = array_map('get_class', $items->toArray()); |
52
|
|
|
$this->assertNotContains(SilverStripeNavigatorTest_ProtectedTestItem::class, $classes); |
53
|
|
|
|
54
|
|
|
$this->logInWithPermission('ADMIN'); |
55
|
|
|
$items = $navigator->getItems(); |
56
|
|
|
$classes = array_map('get_class', $items->toArray()); |
57
|
|
|
$this->assertContains(SilverStripeNavigatorTest_ProtectedTestItem::class, $classes); |
58
|
|
|
|
59
|
|
|
// Unversioned record shouldn't be viewable in stage / live specific views |
60
|
|
|
$unversioned = new SilverStripeNavigatorTest\UnstagedRecord(); |
61
|
|
|
$navigator2 = new SilverStripeNavigator($unversioned); |
62
|
|
|
$classes = array_map('get_class', $navigator2->getItems()->toArray()); |
63
|
|
|
$this->assertNotContains(SilverStripeNavigatorItem_LiveLink::class, $classes); |
64
|
|
|
$this->assertNotContains(SilverStripeNavigatorItem_StageLink::class, $classes); |
65
|
|
|
$this->assertNotContains(SilverStripeNavigatorItem_ArchiveLink::class, $classes); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|