1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use SilverStripe\SiteConfig\SiteConfig; |
4
|
|
|
use SilverStripe\Dev\SapphireTest; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* @package siteconfig |
8
|
|
|
* @subpackage tests |
9
|
|
|
*/ |
10
|
|
|
class SiteConfigTest extends SapphireTest |
|
|
|
|
11
|
|
|
{ |
12
|
|
|
protected static $fixture_file = 'SiteConfigTest.yml'; |
13
|
|
|
|
14
|
|
|
protected static $illegal_extensions = array( |
15
|
|
|
'SilverStripe\\CMS\\Model\\SiteTree' => array('SiteTreeSubsites'), |
16
|
|
|
); |
17
|
|
|
|
18
|
|
View Code Duplication |
public function testCanCreateRootPages() |
|
|
|
|
19
|
|
|
{ |
20
|
|
|
$config = $this->objFromFixture('SilverStripe\\SiteConfig\\SiteConfig', 'default'); |
21
|
|
|
|
22
|
|
|
// Log in without pages admin access |
23
|
|
|
$this->logInWithPermission('CMS_ACCESS_AssetAdmin'); |
24
|
|
|
$this->assertFalse($config->canCreateTopLevel()); |
25
|
|
|
|
26
|
|
|
// Login with necessary edit permission |
27
|
|
|
$perms = SiteConfig::config()->required_permission; |
28
|
|
|
$this->logInWithPermission(reset($perms)); |
29
|
|
|
$this->assertTrue($config->canCreateTopLevel()); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testCanViewPages() |
33
|
|
|
{ |
34
|
|
|
$config = $this->objFromFixture('SilverStripe\\SiteConfig\\SiteConfig', 'default'); |
35
|
|
|
$this->assertTrue($config->canViewPages()); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testCanEdit() |
39
|
|
|
{ |
40
|
|
|
$config = $this->objFromFixture('SilverStripe\\SiteConfig\\SiteConfig', 'default'); |
41
|
|
|
|
42
|
|
|
// Unrelated permissions don't allow siteconfig |
43
|
|
|
$this->logInWithPermission('CMS_ACCESS_AssetAdmin'); |
44
|
|
|
$this->assertFalse($config->canEdit()); |
45
|
|
|
|
46
|
|
|
// Only those with edit permission can do this |
47
|
|
|
$this->logInWithPermission('EDIT_SITECONFIG'); |
48
|
|
|
$this->assertTrue($config->canEdit()); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
View Code Duplication |
public function testCanEditPages() |
|
|
|
|
52
|
|
|
{ |
53
|
|
|
$config = $this->objFromFixture('SilverStripe\\SiteConfig\\SiteConfig', 'default'); |
54
|
|
|
|
55
|
|
|
// Log in without pages admin access |
56
|
|
|
$this->logInWithPermission('CMS_ACCESS_AssetAdmin'); |
57
|
|
|
$this->assertFalse($config->canEditPages()); |
58
|
|
|
|
59
|
|
|
// Login with necessary edit permission |
60
|
|
|
$perms = SiteConfig::config()->required_permission; |
61
|
|
|
$this->logInWithPermission(reset($perms)); |
62
|
|
|
$this->assertTrue($config->canEditPages()); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.