1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class CatalogProductTest 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 testCategoryList() |
14
|
|
|
{ |
15
|
|
|
$object = $this->objFromFixture('CatalogProduct', 'one'); |
16
|
|
|
$expected = $this->objFromFixture('CatalogCategory', 'default')->Title; |
17
|
|
|
$this->assertEquals($expected, $object->CategoryList()); |
|
|
|
|
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* |
22
|
|
|
*/ |
23
|
|
|
public function testGetImage() |
24
|
|
|
{ |
25
|
|
|
$object = $this->objFromFixture('CatalogProduct', 'one'); |
26
|
|
|
$this->assertEquals($object->getImage(), $object->Slides()->first()); |
|
|
|
|
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testGetCMSFields() |
30
|
|
|
{ |
31
|
|
|
$object = new CatalogProduct(); |
32
|
|
|
$fieldset = $object->getCMSFields(); |
33
|
|
|
$this->assertTrue(is_a($fieldset, 'FieldList')); |
|
|
|
|
34
|
|
|
//$this->assertNull($fieldset->dataFieldByName('TechDocs')); |
|
|
|
|
35
|
|
|
|
36
|
|
|
$object = $this->objFromFixture('CatalogProduct', 'one'); |
37
|
|
|
$fieldset = $object->getCMSFields(); |
38
|
|
|
$this->assertTrue(is_a($fieldset, 'FieldList')); |
|
|
|
|
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testGetPrimaryCategory() |
42
|
|
|
{ |
43
|
|
|
$object = $this->objFromFixture('CatalogProduct', 'one'); |
44
|
|
|
$this->assertEquals($object->getPrimaryCategory(), $object->Categories()->sort('SortOrder')->first()); |
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testGetDefaultSearchContext() |
48
|
|
|
{ |
49
|
|
|
$object = $this->objFromFixture('CatalogProduct', 'one'); |
50
|
|
|
$this->assertInstanceOf('SearchContext', $object->getDefaultSearchContext()); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
View Code Duplication |
public function testCanView() |
|
|
|
|
54
|
|
|
{ |
55
|
|
|
$object = $this->objFromFixture('CatalogProduct', 'one'); |
56
|
|
|
|
57
|
|
|
$admin = $this->objFromFixture('Member', 'admin'); |
58
|
|
|
$this->assertTrue($object->canView($admin)); |
|
|
|
|
59
|
|
|
|
60
|
|
|
$member = $this->objFromFixture('Member', 'default'); |
61
|
|
|
$this->assertTrue($object->canView($member)); |
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
|
View Code Duplication |
public function testCanEdit() |
|
|
|
|
65
|
|
|
{ |
66
|
|
|
$object = $this->objFromFixture('CatalogProduct', 'one'); |
67
|
|
|
|
68
|
|
|
$admin = $this->objFromFixture('Member', 'admin'); |
69
|
|
|
$this->assertTrue($object->canEdit($admin)); |
|
|
|
|
70
|
|
|
|
71
|
|
|
$member = $this->objFromFixture('Member', 'default'); |
72
|
|
|
$this->assertFalse($object->canEdit($member)); |
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
75
|
|
View Code Duplication |
public function testCanDelete() |
|
|
|
|
76
|
|
|
{ |
77
|
|
|
$object = $this->objFromFixture('CatalogProduct', 'one'); |
78
|
|
|
|
79
|
|
|
$admin = $this->objFromFixture('Member', 'admin'); |
80
|
|
|
$this->assertTrue($object->canDelete($admin)); |
|
|
|
|
81
|
|
|
|
82
|
|
|
$member = $this->objFromFixture('Member', 'default'); |
83
|
|
|
$this->assertFalse($object->canDelete($member)); |
|
|
|
|
84
|
|
|
} |
85
|
|
|
|
86
|
|
View Code Duplication |
public function testCanCreate() |
|
|
|
|
87
|
|
|
{ |
88
|
|
|
$object = $this->objFromFixture('CatalogProduct', 'one'); |
89
|
|
|
|
90
|
|
|
$admin = $this->objFromFixture('Member', 'admin'); |
91
|
|
|
$this->assertTrue($object->canCreate($admin)); |
|
|
|
|
92
|
|
|
|
93
|
|
|
$member = $this->objFromFixture('Member', 'default'); |
94
|
|
|
$this->assertFalse($object->canCreate($member)); |
|
|
|
|
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function testProvidePermissions() |
98
|
|
|
{ |
99
|
|
|
$object = $this->objFromFixture('CatalogProduct', 'one'); |
100
|
|
|
$expected = array( |
101
|
|
|
'Product_EDIT' => 'Edit a Product', |
102
|
|
|
'Product_DELETE' => 'Delete a Product', |
103
|
|
|
'Product_CREATE' => 'Create a Product', |
104
|
|
|
); |
105
|
|
|
$this->assertEquals($expected, $object->providePermissions()); |
|
|
|
|
106
|
|
|
} |
107
|
|
|
} |
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.