|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* EditableFieldAdminTest contains test cases for testing the LeftAndMain subclass |
|
5
|
|
|
* |
|
6
|
|
|
* @author Mohamed Alsharaf <[email protected]> |
|
7
|
|
|
* @package editablefield |
|
8
|
|
|
*/ |
|
9
|
|
|
class EditableFieldAdminTest extends FunctionalTest |
|
|
|
|
|
|
10
|
|
|
{ |
|
11
|
|
|
protected static $fixture_file = 'EditableFieldTest.yml'; |
|
12
|
|
|
|
|
13
|
|
|
public function testPermission() |
|
14
|
|
|
{ |
|
15
|
|
|
$this->logInWithPermission('EDITOR'); |
|
16
|
|
|
|
|
17
|
|
|
$this->assertEquals('403', $this->get('/admin/editablefield')->getStatusCode()); |
|
|
|
|
|
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
View Code Duplication |
public function testFilterRequest() |
|
|
|
|
|
|
21
|
|
|
{ |
|
22
|
|
|
$this->logInWithPermission('ADMIN'); |
|
23
|
|
|
|
|
24
|
|
|
$request = new SS_HTTPRequest(null, 'admin/editablefield/filter', [ |
|
25
|
|
|
'q' => [ |
|
26
|
|
|
'Term' => 'email-field', |
|
27
|
|
|
], |
|
28
|
|
|
'action_doSearch' => 'Apply Filter' |
|
29
|
|
|
]); |
|
30
|
|
|
$admin = new EditableFieldAdmin(); |
|
31
|
|
|
$admin->setRequest($request); |
|
32
|
|
|
$response = $admin->filter(); |
|
33
|
|
|
|
|
34
|
|
|
$this->assertEquals('200', $response->getStatusCode()); |
|
|
|
|
|
|
35
|
|
|
$this->assertContains('email-field', $response->getBody()); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
View Code Duplication |
public function testAddRequest() |
|
|
|
|
|
|
39
|
|
|
{ |
|
40
|
|
|
$this->logInWithPermission('ADMIN'); |
|
41
|
|
|
|
|
42
|
|
|
$request = new SS_HTTPRequest('post', 'admin/editablefield/doAdd', null, [ |
|
|
|
|
|
|
43
|
|
|
'Type' => 'EditableFieldText', |
|
44
|
|
|
'action_doAddField' => 'Add' |
|
45
|
|
|
]); |
|
46
|
|
|
$admin = new EditableFieldAdmin(); |
|
47
|
|
|
$admin->setRequest($request); |
|
48
|
|
|
$response = $admin->doAdd($request); |
|
49
|
|
|
|
|
50
|
|
|
$this->assertInstanceOf('HTMLText', $response); |
|
|
|
|
|
|
51
|
|
|
$this->assertContains('EditableFieldText', $response->getValue()); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function testSaveRequest() |
|
55
|
|
|
{ |
|
56
|
|
|
$this->logInWithPermission('ADMIN'); |
|
57
|
|
|
|
|
58
|
|
|
$text = $this->objFromFixture('EditableFieldText', 'basic-text'); |
|
59
|
|
|
$email = $this->objFromFixture('EditableFieldEmail', 'email-field'); |
|
60
|
|
|
$textName = $text->Name . '_update'; |
|
61
|
|
|
$emailTitle = 'Email address 2'; |
|
62
|
|
|
|
|
63
|
|
|
$response = $this->post('admin/editablefield/EditForm', [ |
|
64
|
|
|
'Fields' => [ |
|
65
|
|
|
$text->ID => [ |
|
66
|
|
|
'Name' => $textName, |
|
67
|
|
|
], |
|
68
|
|
|
$email->ID => [ |
|
69
|
|
|
'Title' => $emailTitle, |
|
70
|
|
|
] |
|
71
|
|
|
], |
|
72
|
|
|
'action_save' => 'Save' |
|
73
|
|
|
]); |
|
74
|
|
|
|
|
75
|
|
|
$this->assertEquals('200', $response->getStatusCode()); |
|
|
|
|
|
|
76
|
|
|
|
|
77
|
|
|
$newText = $this->objFromFixture('EditableFieldText', 'basic-text'); |
|
78
|
|
|
$newEmail = $this->objFromFixture('EditableFieldEmail', 'email-field'); |
|
79
|
|
|
|
|
80
|
|
|
$this->assertEquals($newText->Name, $textName); |
|
|
|
|
|
|
81
|
|
|
$this->assertEquals($newEmail->Title, $emailTitle); |
|
|
|
|
|
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function testDeleteRequest() |
|
85
|
|
|
{ |
|
86
|
|
|
$this->logInWithPermission('ADMIN'); |
|
87
|
|
|
|
|
88
|
|
|
$text = $this->objFromFixture('EditableFieldText', 'basic-text'); |
|
89
|
|
|
|
|
90
|
|
|
$response = $this->post('admin/editablefield/EditForm', [ |
|
91
|
|
|
'Fields' => [ |
|
92
|
|
|
$text->ID => [], |
|
93
|
|
|
], |
|
94
|
|
|
'action_delete' => 1, |
|
95
|
|
|
'delete_row' => 1 |
|
96
|
|
|
]); |
|
97
|
|
|
|
|
98
|
|
|
$this->assertEquals('200', $response->getStatusCode()); |
|
|
|
|
|
|
99
|
|
|
$this->assertFalse($this->getFixtureFactory()->get('EditableFieldText', 'basic-text')); |
|
|
|
|
|
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function testAddOptionRequest() |
|
103
|
|
|
{ |
|
104
|
|
|
$this->logInWithPermission('ADMIN'); |
|
105
|
|
|
|
|
106
|
|
|
$dropdown = $this->objFromFixture('EditableFieldDropdown', 'basic-dropdown'); |
|
107
|
|
|
$optionsCount = $dropdown->Options()->count(); |
|
108
|
|
|
|
|
109
|
|
|
$this->post('admin/editablefield/EditForm', [ |
|
110
|
|
|
'action_addoptionfield' => 1, |
|
111
|
|
|
'Parent' => $dropdown->ID |
|
112
|
|
|
]); |
|
113
|
|
|
|
|
114
|
|
|
$optionsCount2 = $dropdown->Options()->count() - 1; |
|
115
|
|
|
|
|
116
|
|
|
$this->assertEquals($optionsCount, $optionsCount2); |
|
|
|
|
|
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.