1
|
|
|
<?php |
2
|
|
|
|
3
|
|
View Code Duplication |
class WarrantyTest extends SapphireTest |
|
|
|
|
4
|
|
|
{ |
5
|
|
|
/** |
6
|
|
|
* @var string |
7
|
|
|
*/ |
8
|
|
|
protected static $fixture_file = 'product-catalog/tests/fixtures.yml'; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* |
12
|
|
|
*/ |
13
|
|
|
public function testGetCMSFields() |
14
|
|
|
{ |
15
|
|
|
$object = new Warranty(); |
16
|
|
|
$fields = $object->getCMSFields(); |
17
|
|
|
$this->assertInstanceOf('FieldList', $fields); |
18
|
|
|
$this->assertNull($fields->dataFieldByName('Products')); |
|
|
|
|
19
|
|
|
|
20
|
|
|
$object = $this->objFromFixture('Warranty', 'one'); |
21
|
|
|
$fields = $object->getCMSFields(); |
22
|
|
|
$this->assertInstanceOf('FieldList', $fields); |
23
|
|
|
$this->assertNotNull($fields->dataFieldByName('Products')); |
|
|
|
|
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function testCanView() |
27
|
|
|
{ |
28
|
|
|
$object = $this->objFromFixture('Warranty', 'one'); |
29
|
|
|
|
30
|
|
|
$admin = $this->objFromFixture('Member', 'admin'); |
31
|
|
|
$this->assertTrue($object->canView($admin)); |
|
|
|
|
32
|
|
|
|
33
|
|
|
$member = $this->objFromFixture('Member', 'default'); |
34
|
|
|
$this->assertTrue($object->canView($member)); |
|
|
|
|
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function testCanEdit() |
38
|
|
|
{ |
39
|
|
|
$object = $this->objFromFixture('Warranty', 'one'); |
40
|
|
|
|
41
|
|
|
$admin = $this->objFromFixture('Member', 'admin'); |
42
|
|
|
$this->assertTrue($object->canEdit($admin)); |
|
|
|
|
43
|
|
|
|
44
|
|
|
$member = $this->objFromFixture('Member', 'default'); |
45
|
|
|
$this->assertFalse($object->canEdit($member)); |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testCanDelete() |
49
|
|
|
{ |
50
|
|
|
$object = $this->objFromFixture('Warranty', 'one'); |
51
|
|
|
|
52
|
|
|
$admin = $this->objFromFixture('Member', 'admin'); |
53
|
|
|
$this->assertTrue($object->canDelete($admin)); |
|
|
|
|
54
|
|
|
|
55
|
|
|
$member = $this->objFromFixture('Member', 'default'); |
56
|
|
|
$this->assertFalse($object->canDelete($member)); |
|
|
|
|
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testCanCreate() |
60
|
|
|
{ |
61
|
|
|
$object = $this->objFromFixture('Warranty', 'one'); |
62
|
|
|
|
63
|
|
|
$admin = $this->objFromFixture('Member', 'admin'); |
64
|
|
|
$this->assertTrue($object->canCreate($admin)); |
|
|
|
|
65
|
|
|
|
66
|
|
|
$member = $this->objFromFixture('Member', 'default'); |
67
|
|
|
$this->assertFalse($object->canCreate($member)); |
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function testProvidePermissions() |
71
|
|
|
{ |
72
|
|
|
$object = $this->objFromFixture('Warranty', 'one'); |
73
|
|
|
$expected = array( |
74
|
|
|
'Warranty_EDIT' => 'Edit Warranty Docs', |
75
|
|
|
'Warranty_DELETE' => 'Delete Warranty Docs', |
76
|
|
|
'Warranty_CREATE' => 'Create Warranty Docs', |
77
|
|
|
); |
78
|
|
|
$this->assertEquals($expected, $object->providePermissions()); |
|
|
|
|
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
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.