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
|
|
|
public static function setUpAfterClass() |
19
|
|
|
{ |
20
|
|
|
// Fix issue with tests failing without CMS module |
21
|
|
|
if (!class_exists('SilverStripe\\CMS\\Model\\SiteTree')) { |
22
|
|
|
unset(static::$illegal_extensions['SilverStripe\\CMS\\Model\\SiteTree']); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
static::setUpAfterClass(); // TODO: Change the autogenerated stub |
26
|
|
|
} |
27
|
|
|
|
28
|
|
View Code Duplication |
public function testCanCreateRootPages() |
|
|
|
|
29
|
|
|
{ |
30
|
|
|
$config = $this->objFromFixture('SilverStripe\\SiteConfig\\SiteConfig', 'default'); |
31
|
|
|
|
32
|
|
|
// Log in without pages admin access |
33
|
|
|
$this->logInWithPermission('CMS_ACCESS_AssetAdmin'); |
34
|
|
|
$this->assertFalse($config->canCreateTopLevel()); |
35
|
|
|
|
36
|
|
|
// Login with necessary edit permission |
37
|
|
|
$perms = SiteConfig::config()->required_permission; |
38
|
|
|
$this->logInWithPermission(reset($perms)); |
39
|
|
|
$this->assertTrue($config->canCreateTopLevel()); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testCanViewPages() |
43
|
|
|
{ |
44
|
|
|
$config = $this->objFromFixture('SilverStripe\\SiteConfig\\SiteConfig', 'default'); |
45
|
|
|
$this->assertTrue($config->canViewPages()); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testCanEdit() |
49
|
|
|
{ |
50
|
|
|
$config = $this->objFromFixture('SilverStripe\\SiteConfig\\SiteConfig', 'default'); |
51
|
|
|
|
52
|
|
|
// Unrelated permissions don't allow siteconfig |
53
|
|
|
$this->logInWithPermission('CMS_ACCESS_AssetAdmin'); |
54
|
|
|
$this->assertFalse($config->canEdit()); |
55
|
|
|
|
56
|
|
|
// Only those with edit permission can do this |
57
|
|
|
$this->logInWithPermission('EDIT_SITECONFIG'); |
58
|
|
|
$this->assertTrue($config->canEdit()); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
View Code Duplication |
public function testCanEditPages() |
|
|
|
|
62
|
|
|
{ |
63
|
|
|
$config = $this->objFromFixture('SilverStripe\\SiteConfig\\SiteConfig', 'default'); |
64
|
|
|
|
65
|
|
|
// Log in without pages admin access |
66
|
|
|
$this->logInWithPermission('CMS_ACCESS_AssetAdmin'); |
67
|
|
|
$this->assertFalse($config->canEditPages()); |
68
|
|
|
|
69
|
|
|
// Login with necessary edit permission |
70
|
|
|
$perms = SiteConfig::config()->required_permission; |
71
|
|
|
$this->logInWithPermission(reset($perms)); |
72
|
|
|
$this->assertTrue($config->canEditPages()); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
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.