1
|
|
|
<?php |
2
|
|
|
|
3
|
|
View Code Duplication |
class PageSectionObjectTest extends SapphireTest |
|
|
|
|
4
|
|
|
{ |
5
|
|
|
/** |
6
|
|
|
* @var string |
7
|
|
|
*/ |
8
|
|
|
protected static $fixture_file = 'dynamic-blocks/tests/Fixtures.yml'; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* |
12
|
|
|
*/ |
13
|
|
|
public function testGetCMSFields() |
14
|
|
|
{ |
15
|
|
|
$object = $this->objFromFixture('PageSectionObject', 'one'); |
16
|
|
|
$fields = $object->getCMSFields(); |
17
|
|
|
$this->assertInstanceOf('FieldList', $fields); |
18
|
|
|
$this->assertNotNull($fields->dataFieldByName('BlockLinkID')); |
|
|
|
|
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* |
23
|
|
|
*/ |
24
|
|
|
public function testValidateName() |
25
|
|
|
{ |
26
|
|
|
$object = $this->objFromFixture('PageSectionObject', 'one'); |
27
|
|
|
$object->Name = ''; |
28
|
|
|
$this->setExpectedException('ValidationException'); |
|
|
|
|
29
|
|
|
$object->write(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* |
34
|
|
|
*/ |
35
|
|
|
public function testCanView() |
36
|
|
|
{ |
37
|
|
|
$object = $this->objFromFixture('PageSectionObject', 'one'); |
38
|
|
|
$admin = $this->objFromFixture('Member', 'admin'); |
39
|
|
|
$this->assertTrue($object->canView($admin)); |
|
|
|
|
40
|
|
|
$member = $this->objFromFixture('Member', 'default'); |
41
|
|
|
$this->assertTrue($object->canView($member)); |
|
|
|
|
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* |
46
|
|
|
*/ |
47
|
|
|
public function testCanEdit() |
48
|
|
|
{ |
49
|
|
|
$object = $this->objFromFixture('PageSectionObject', 'one'); |
50
|
|
|
$admin = $this->objFromFixture('Member', 'admin'); |
51
|
|
|
$this->assertTrue($object->canEdit($admin)); |
|
|
|
|
52
|
|
|
$member = $this->objFromFixture('Member', 'default'); |
53
|
|
|
$this->assertTrue($object->canEdit($member)); |
|
|
|
|
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* |
58
|
|
|
*/ |
59
|
|
|
public function testCanDelete() |
60
|
|
|
{ |
61
|
|
|
$object = $this->objFromFixture('PageSectionObject', 'one'); |
62
|
|
|
$admin = $this->objFromFixture('Member', 'admin'); |
63
|
|
|
$this->assertTrue($object->canDelete($admin)); |
|
|
|
|
64
|
|
|
$member = $this->objFromFixture('Member', 'default'); |
65
|
|
|
$this->assertTrue($object->canDelete($member)); |
|
|
|
|
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* |
70
|
|
|
*/ |
71
|
|
|
public function testCanCreate() |
72
|
|
|
{ |
73
|
|
|
$object = $this->objFromFixture('PageSectionObject', 'one'); |
74
|
|
|
$admin = $this->objFromFixture('Member', 'admin'); |
75
|
|
|
$this->assertTrue($object->canCreate($admin)); |
|
|
|
|
76
|
|
|
$member = $this->objFromFixture('Member', 'default'); |
77
|
|
|
$this->assertTrue($object->canCreate($member)); |
|
|
|
|
78
|
|
|
} |
79
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.