|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
class DNProjectTest extends DeploynautTest { |
|
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
protected static $fixture_file = 'DNProjectTest.yml'; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @var DNProject |
|
10
|
|
|
*/ |
|
11
|
|
|
protected $project = null; |
|
12
|
|
|
|
|
13
|
|
|
public function setUp() { |
|
14
|
|
|
parent::setUp(); |
|
15
|
|
|
|
|
16
|
|
|
$this->project = DNProject::create(); |
|
17
|
|
|
$this->project->Name = 'testproject'; |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* |
|
22
|
|
|
*/ |
|
23
|
|
View Code Duplication |
public function testOnBeforeWriteShouldNotCreateCapFolder() { |
|
|
|
|
|
|
24
|
|
|
$this->assertTrue(file_exists($this->envPath)); |
|
|
|
|
|
|
25
|
|
|
$this->assertFalse(file_exists($this->envPath.'/testproject')); |
|
|
|
|
|
|
26
|
|
|
$this->project->onBeforeWrite(); |
|
27
|
|
|
$this->assertFalse(file_exists($this->envPath.'/testproject'), 'Folder should not have been created'); |
|
|
|
|
|
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
View Code Duplication |
public function testOnBeforeWriteShouldCreateCapFolder() { |
|
|
|
|
|
|
31
|
|
|
$this->assertTrue(file_exists($this->envPath)); |
|
|
|
|
|
|
32
|
|
|
$this->assertFalse(file_exists($this->envPath.'/testproject')); |
|
|
|
|
|
|
33
|
|
|
$this->project->CreateEnvFolder = true; |
|
|
|
|
|
|
34
|
|
|
$this->project->onBeforeWrite(); |
|
35
|
|
|
$this->assertTrue(file_exists($this->envPath.'/testproject'), 'Folder should have been created'); |
|
|
|
|
|
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testSetCreateProjectFolderFieldNoFolderExists() { |
|
39
|
|
|
$fields = new FieldList(); |
|
40
|
|
|
$fields->push(new TextField('Name')); |
|
41
|
|
|
$this->project->setCreateProjectFolderField($fields); |
|
42
|
|
|
$this->assertInstanceOf('LabelField', $fields->fieldByName('CreateEnvFolderNotice')); |
|
|
|
|
|
|
43
|
|
|
$this->assertInstanceOf('CheckboxField', $fields->fieldByName('CreateEnvFolder')); |
|
|
|
|
|
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function testSetCreateProjectFolderFieldFolderExists() { |
|
47
|
|
|
$this->assertFalse( |
|
|
|
|
|
|
48
|
|
|
file_exists($this->envPath.'/'.$this->project->Name), |
|
49
|
|
|
'project folder shouldnt exist prior to save' |
|
50
|
|
|
); |
|
51
|
|
|
$this->project->CreateEnvFolder = true; |
|
|
|
|
|
|
52
|
|
|
$this->project->onBeforeWrite(); |
|
53
|
|
|
$fields = new FieldList(); |
|
54
|
|
|
$fields->push(new TextField('Name')); |
|
55
|
|
|
$this->project->setCreateProjectFolderField($fields); |
|
56
|
|
|
$this->assertNull($fields->fieldByName('CreateEnvFolderNotice')); |
|
|
|
|
|
|
57
|
|
|
$this->assertNull($fields->fieldByName('CreateEnvFolder')); |
|
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function testExceededDiskQuota() { |
|
61
|
|
|
$project = $this->getMock('DNProject', array('getUsedQuotaMB')); |
|
|
|
|
|
|
62
|
|
|
$project->expects($this->any())->method('getUsedQuotaMB')->will($this->returnValue(5)); |
|
|
|
|
|
|
63
|
|
|
$project->DiskQuotaMB = 1; |
|
64
|
|
|
$this->assertTrue($project->HasExceededDiskQuota()); |
|
|
|
|
|
|
65
|
|
|
$project->DiskQuotaMB = 100; |
|
66
|
|
|
$this->assertFalse($project->HasExceededDiskQuota()); |
|
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function testHasDiskQuota() { |
|
70
|
|
|
Config::inst()->update('DNProject', 'defaults', array('DiskQuotaMB' => 0)); |
|
71
|
|
|
$this->assertFalse($this->project->HasDiskQuota()); |
|
|
|
|
|
|
72
|
|
|
|
|
73
|
|
|
Config::inst()->update('DNProject', 'defaults', array('DiskQuotaMB' => 2048)); |
|
74
|
|
|
$this->assertTrue($this->project->HasDiskQuota()); |
|
|
|
|
|
|
75
|
|
|
|
|
76
|
|
|
$this->project->DiskQuotaMB = 2; |
|
77
|
|
|
$this->assertTrue($this->project->HasDiskQuota()); |
|
|
|
|
|
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function testAllowed() { |
|
81
|
|
|
$project = $this->objFromFixture('DNProject', 'firstProject'); |
|
82
|
|
|
$viewer = $this->objFromFixture('Member', 'viewer'); |
|
83
|
|
|
|
|
84
|
|
|
$this->assertTrue( |
|
|
|
|
|
|
85
|
|
|
$project->allowed('FOO_PERMISSION', $viewer), |
|
86
|
|
|
'Member that is in the group that has the code, and is in project\'s Viewers, is allowed' |
|
87
|
|
|
); |
|
88
|
|
|
$this->assertTrue( |
|
|
|
|
|
|
89
|
|
|
$project->allowed('BAR_PERMISSION', $viewer), |
|
90
|
|
|
'Member that has a role that has the code, and is in project\'s Viewers, is allowed' |
|
91
|
|
|
); |
|
92
|
|
|
|
|
93
|
|
|
$other = $this->objFromFixture('DNProject', 'otherproject'); |
|
94
|
|
|
$this->assertFalse( |
|
|
|
|
|
|
95
|
|
|
$other->allowed('FOO_PERMISSION', $viewer), |
|
96
|
|
|
'Member that is in the group that has a code, but that is not in project\'s Viewers, is disallowed' |
|
97
|
|
|
); |
|
98
|
|
|
$this->assertFalse( |
|
|
|
|
|
|
99
|
|
|
$other->allowed('BAR_PERMISSION', $viewer), |
|
100
|
|
|
'Member that has a role that has the code, but that is not in project\'s Viewers, is disallowed' |
|
101
|
|
|
); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function testAllowedAny() { |
|
105
|
|
|
$project = $this->objFromFixture('DNProject', 'firstProject'); |
|
106
|
|
|
$viewer = $this->objFromFixture('Member', 'viewer'); |
|
107
|
|
|
|
|
108
|
|
|
$this->assertTrue( |
|
|
|
|
|
|
109
|
|
|
$project->allowedAny(array('FOO_PERMISSION', 'NONEXISTENT_PERMISSION'), $viewer), |
|
110
|
|
|
'Member that is in the group that has the code, and is in project\'s Viewers, is allowed' |
|
111
|
|
|
); |
|
112
|
|
|
$this->assertTrue( |
|
|
|
|
|
|
113
|
|
|
$project->allowedAny(array('BAR_PERMISSION', 'NONEXISTENT_PERMISSION'), $viewer), |
|
114
|
|
|
'Member that has a role that has the code, and is in project\'s Viewers, is allowed' |
|
115
|
|
|
); |
|
116
|
|
|
|
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
public function testWhoIsAllowed() { |
|
120
|
|
|
$project = $this->objFromFixture('DNProject', 'firstProject'); |
|
121
|
|
|
$this->assertCount(0, $project->whoIsAllowed('NONEXISTENT_PERMISSION')); |
|
|
|
|
|
|
122
|
|
|
$this->assertDOSEquals(array( |
|
123
|
|
|
array('Email' =>'[email protected]') |
|
124
|
|
|
), $project->whoIsAllowed('FOO_PERMISSION')); |
|
125
|
|
|
$this->assertDOSEquals(array( |
|
126
|
|
|
array('Email' =>'[email protected]') |
|
127
|
|
|
), $project->whoIsAllowed('BAR_PERMISSION')); |
|
128
|
|
|
|
|
129
|
|
|
$other = $this->objFromFixture('DNProject', 'otherproject'); |
|
130
|
|
|
$this->assertCount(0, $other->whoIsAllowed('FOO_PERMISSION')); |
|
|
|
|
|
|
131
|
|
|
$this->assertCount(0, $other->whoIsAllowed('BAR_PERMISSION')); |
|
|
|
|
|
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
public function testWhoIsAllowedAny() { |
|
135
|
|
|
$project = $this->objFromFixture('DNProject', 'firstProject'); |
|
136
|
|
|
$this->assertCount(0, $project->whoIsAllowedAny(array('NONEXISTENT_PERMISSION', 'NONEXISTENT_PERMISSION_2'))); |
|
|
|
|
|
|
137
|
|
|
$this->assertDOSEquals(array( |
|
138
|
|
|
array('Email' =>'[email protected]') |
|
139
|
|
|
), $project->whoIsAllowedAny(array('FOO_PERMISSION', 'NONEXISTENT_PERMISSION'))); |
|
140
|
|
|
$this->assertDOSEquals(array( |
|
141
|
|
|
array('Email' =>'[email protected]') |
|
142
|
|
|
), $project->whoIsAllowedAny(array('BAR_PERMISSION', 'NONEXISTENT_PERMISSION'))); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* |
|
147
|
|
|
*/ |
|
148
|
|
View Code Duplication |
public function testFooGroupIsAllowedToFooPermission() { |
|
|
|
|
|
|
149
|
|
|
$firstProject = $this->objFromFixture('DNProject', 'firstProject'); |
|
150
|
|
|
$firstGroup = $this->objFromFixture('Group', 'firstWithCodeFoo'); |
|
151
|
|
|
$isAllowed = $firstProject->groupAllowed('FOO_PERMISSION', $firstGroup); |
|
152
|
|
|
$this->assertTrue($isAllowed, 'Expected that foo group is allowed to foo perm'); |
|
|
|
|
|
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
View Code Duplication |
public function testFooGroupIsNotAllowedToBarPermission() { |
|
|
|
|
|
|
156
|
|
|
$project = $this->objFromFixture('DNProject', 'firstProject'); |
|
157
|
|
|
$fooGroup = $this->objFromFixture('Group', 'firstWithCodeFoo'); |
|
158
|
|
|
$isAllowed = $project->groupAllowed('BAR_PERMISSION', $fooGroup); |
|
159
|
|
|
$this->assertFalse($isAllowed, 'Expected that foo group should not have access to bar perm'); |
|
|
|
|
|
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
View Code Duplication |
public function testBarGroupIsAllowedToBarPermission() { |
|
|
|
|
|
|
163
|
|
|
$firstProject = $this->objFromFixture('DNProject', 'firstProject'); |
|
164
|
|
|
$secondGroup = $this->objFromFixture('Group', 'secondWithRoleBar'); |
|
165
|
|
|
$isAllowed = $firstProject->groupAllowed('BAR_PERMISSION', $secondGroup); |
|
166
|
|
|
$this->assertTrue($isAllowed, 'Group should have "bar" PermissionRoleCode'); |
|
|
|
|
|
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
View Code Duplication |
public function testSecondGroupIsNotAllowedToFirstProject() { |
|
|
|
|
|
|
170
|
|
|
$firstProject = $this->objFromFixture('DNProject', 'firstProject'); |
|
171
|
|
|
$thirdGroup = $this->objFromFixture('Group', 'thirdWithCodeFoo'); |
|
172
|
|
|
$isAllowed = $firstProject->groupAllowed('FOO_PERMISSION', $thirdGroup); |
|
173
|
|
|
$this->assertFalse($isAllowed, 'Expected that non project group should be denied'); |
|
|
|
|
|
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
View Code Duplication |
public function testNonViewerGroupAllowedIsFalse() { |
|
|
|
|
|
|
177
|
|
|
$otherProject = $this->objFromFixture('DNProject', 'otherproject'); |
|
178
|
|
|
$firstGroup = $this->objFromFixture('Group', 'firstWithCodeFoo'); |
|
179
|
|
|
$isAllowed = $otherProject->groupAllowed('FOO_PERMISSION', $firstGroup); |
|
180
|
|
|
$this->assertFalse($isAllowed, 'Expected that non project group should be denied'); |
|
|
|
|
|
|
181
|
|
|
} |
|
182
|
|
|
} |
|
183
|
|
|
|
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.