1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Class CatalogProductInquiryTest |
5
|
|
|
*/ |
6
|
|
|
class CatalogProductInquiryTest extends SapphireTest |
7
|
|
|
{ |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @var string |
11
|
|
|
*/ |
12
|
|
|
protected static $fixture_file = 'product-catalog/tests/fixtures.yml'; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Ensure any current member is logged out |
16
|
|
|
*/ |
17
|
|
|
public function logOut() |
18
|
|
|
{ |
19
|
|
|
if ($member = Member::currentUser()) { |
20
|
|
|
$member->logOut(); |
21
|
|
|
} |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* |
26
|
|
|
*/ |
27
|
|
|
public function testGetCMSFields() |
28
|
|
|
{ |
29
|
|
|
$this->assertInstanceOf('FieldList', Injector::inst()->get('CatalogProductInquiry')->getCMSFields()); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* |
34
|
|
|
*/ |
35
|
|
|
public function testGetFrontEndFields() |
36
|
|
|
{ |
37
|
|
|
$fields = Injector::inst()->get('CatalogProductInquiry')->getFrontEndFields(); |
38
|
|
|
$this->assertInstanceOf('FieldList', $fields); |
39
|
|
|
if ($fields->dataFieldByName('ProductID')) { |
40
|
|
|
$fields->dataFieldByName('ProductID')->setValue(2); |
41
|
|
|
} |
42
|
|
|
$this->assertInstanceOf('HiddenField', $fields->dataFieldByName('ProductID')); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* |
47
|
|
|
*/ |
48
|
|
|
public function testGetFrontEndActions() |
49
|
|
|
{ |
50
|
|
|
$actions = Injector::inst()->get('CatalogProductInquiry')->getFrontEndActions(); |
51
|
|
|
$this->assertInstanceOf('FieldList', $actions); |
52
|
|
|
$this->assertInstanceOf('FormAction', $actions->fieldByName('action_doProductInquiry')); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* |
57
|
|
|
*/ |
58
|
|
|
public function testGetFrontEndRequiredFields() |
59
|
|
|
{ |
60
|
|
|
$requiredFields = Injector::inst()->get('CatalogProductInquiry')->getFrontEndRequiredFields(); |
61
|
|
|
$this->assertInstanceOf('RequiredFields', $requiredFields); |
62
|
|
|
$this->assertTrue($requiredFields->fieldIsRequired('Name')); |
|
|
|
|
63
|
|
|
$this->assertTrue($requiredFields->fieldIsRequired('Email')); |
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* |
68
|
|
|
*/ |
69
|
|
|
public function testProvidePermissions() |
70
|
|
|
{ |
71
|
|
|
$expected = [ |
72
|
|
|
'CatalogProductInquiry_delete' => [ |
73
|
|
|
'name' => 'Delete a Product Inquiry', |
74
|
|
|
'category' => 'Product InquiryPermissions', |
75
|
|
|
], |
76
|
|
|
'CatalogProductInquiry_view' => [ |
77
|
|
|
'name' => 'View a Product Inquiry', |
78
|
|
|
'category' => 'Product InquiryPermissions', |
79
|
|
|
], |
80
|
|
|
]; |
81
|
|
|
|
82
|
|
|
$this->assertEquals($expected, Injector::inst()->get('CatalogProductInquiry')->providePermissions()); |
|
|
|
|
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* |
87
|
|
|
*/ |
88
|
|
|
public function testCanCreate() |
89
|
|
|
{ |
90
|
|
|
$this->assertTrue(Injector::inst()->get('CatalogProductInquiry')->canCreate()); |
|
|
|
|
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* |
95
|
|
|
*/ |
96
|
|
|
public function testCanEdit() |
97
|
|
|
{ |
98
|
|
|
$this->assertFalse(Injector::inst()->get('CatalogProductInquiry')->canEdit()); |
|
|
|
|
99
|
|
|
} |
100
|
|
|
|
101
|
|
View Code Duplication |
public function testCanView() |
|
|
|
|
102
|
|
|
{ |
103
|
|
|
if ($member = Member::currentUser()) { |
|
|
|
|
104
|
|
|
$this->logOut(); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
$inquiry = Injector::inst()->get('CatalogProductInquiry'); |
108
|
|
|
$this->assertFalse($inquiry->canView()); |
|
|
|
|
109
|
|
|
|
110
|
|
|
$this->logInWithPermission('CatalogProductInquiry_view'); |
111
|
|
|
$this->assertTrue($inquiry->canView()); |
|
|
|
|
112
|
|
|
|
113
|
|
|
$this->logOut(); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
View Code Duplication |
public function testCanDelete() |
|
|
|
|
117
|
|
|
{ |
118
|
|
|
if ($member = Member::currentUser()) { |
|
|
|
|
119
|
|
|
$this->logOut(); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
$inquiry = Injector::inst()->get('CatalogProductInquiry'); |
123
|
|
|
$this->assertFalse($inquiry->canDelete()); |
|
|
|
|
124
|
|
|
|
125
|
|
|
$this->logInWithPermission('CatalogProductInquiry_delete'); |
126
|
|
|
$this->assertTrue($inquiry->canDelete()); |
|
|
|
|
127
|
|
|
|
128
|
|
|
$this->logOut(); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
} |
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.