1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class OptionGroupTest extends SapphireTest |
4
|
|
|
{ |
5
|
|
|
/** |
6
|
|
|
* @var string |
7
|
|
|
*/ |
8
|
|
|
protected static $fixture_file = 'foxystripe/tests/FoxyStripeTest.yml'; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* |
12
|
|
|
*/ |
13
|
|
|
public function testGetCMSValidator() |
14
|
|
|
{ |
15
|
|
|
$object = $this->objFromFixture('OptionGroup', 'size'); |
16
|
|
|
$this->assertInstanceOf('RequiredFields', $object->getCMSValidator()); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* |
21
|
|
|
*/ |
22
|
|
|
public function testValidateTitle() |
23
|
|
|
{ |
24
|
|
|
$object = $this->objFromFixture('OptionGroup', 'size'); |
25
|
|
|
$orig = $object->Title; |
26
|
|
|
$object->Title = '2' . $orig; |
27
|
|
|
$this->setExpectedException('ValidationException'); |
|
|
|
|
28
|
|
|
$object->write(); |
29
|
|
|
|
30
|
|
|
$object->Title = $orig . '&'; |
31
|
|
|
$this->setExpectedException('ValidationException'); |
|
|
|
|
32
|
|
|
$object->write(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* |
37
|
|
|
*/ |
38
|
|
|
public function testOnBeforeDelete() |
39
|
|
|
{ |
40
|
|
|
$group = $this->objFromFixture('OptionGroup', 'size'); |
41
|
|
|
$item = $this->objFromFixture('OptionItem', 'large'); |
42
|
|
|
$this->assertEquals($item->ProductOptionGroupID, $group->ID); |
|
|
|
|
43
|
|
|
|
44
|
|
|
$groupID = $group->ID; |
45
|
|
|
$group->delete(); |
46
|
|
|
$this->assertNull(OptionGroup::get()->byID($groupID)); |
|
|
|
|
47
|
|
|
|
48
|
|
|
// assert that the new child has been reassigned |
49
|
|
|
$item2 = OptionItem::get()->byID($item->ID); |
50
|
|
|
$this->assertEquals($item2->ProductOptionGroupID, $this->objFromFixture('OptionGroup', 'default')->ID); |
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* |
55
|
|
|
*/ |
56
|
|
|
public function testCanView() |
57
|
|
|
{ |
58
|
|
|
$object = $this->objFromFixture('OptionGroup', 'size'); |
59
|
|
|
$admin = $this->objFromFixture('Member', 'admin'); |
60
|
|
|
$this->assertTrue($object->canView($admin)); |
|
|
|
|
61
|
|
|
$member = $this->objFromFixture('Member', 'customer'); |
62
|
|
|
$this->assertTrue($object->canView($member)); |
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* |
67
|
|
|
*/ |
68
|
|
View Code Duplication |
public function testCanEdit() |
|
|
|
|
69
|
|
|
{ |
70
|
|
|
$object = $this->objFromFixture('OptionGroup', 'default'); |
71
|
|
|
$admin = $this->objFromFixture('Member', 'admin'); |
72
|
|
|
$this->assertFalse($object->canEdit($admin)); |
|
|
|
|
73
|
|
|
|
74
|
|
|
$object = $this->objFromFixture('OptionGroup', 'size'); |
75
|
|
|
$this->assertTrue($object->canEdit($admin)); |
|
|
|
|
76
|
|
|
$member = $this->objFromFixture('Member', 'customer'); |
77
|
|
|
$this->assertFalse($object->canEdit($member)); |
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* |
82
|
|
|
*/ |
83
|
|
View Code Duplication |
public function testCanDelete() |
|
|
|
|
84
|
|
|
{ |
85
|
|
|
$object = $this->objFromFixture('OptionGroup', 'default'); |
86
|
|
|
$admin = $this->objFromFixture('Member', 'admin'); |
87
|
|
|
$this->assertFalse($object->canDelete($admin)); |
|
|
|
|
88
|
|
|
|
89
|
|
|
$object = $this->objFromFixture('OptionGroup', 'size'); |
90
|
|
|
$this->assertTrue($object->canDelete($admin)); |
|
|
|
|
91
|
|
|
$member = $this->objFromFixture('Member', 'customer'); |
92
|
|
|
$this->assertFalse($object->canDelete($member)); |
|
|
|
|
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* |
97
|
|
|
*/ |
98
|
|
View Code Duplication |
public function testCanCreate() |
|
|
|
|
99
|
|
|
{ |
100
|
|
|
$object = $this->objFromFixture('OptionGroup', 'size'); |
101
|
|
|
$admin = $this->objFromFixture('Member', 'admin'); |
102
|
|
|
$this->assertTrue($object->canCreate($admin)); |
|
|
|
|
103
|
|
|
$member = $this->objFromFixture('Member', 'customer'); |
104
|
|
|
$this->assertFalse($object->canCreate($member)); |
|
|
|
|
105
|
|
|
} |
106
|
|
|
} |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.