These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | class CommentsGridFieldActionTest extends SapphireTest |
||
4 | { |
||
5 | |||
6 | /** @var ArrayList */ |
||
7 | protected $list; |
||
8 | |||
9 | /** @var GridField */ |
||
10 | protected $gridField; |
||
11 | |||
12 | /** @var Form */ |
||
13 | protected $form; |
||
14 | |||
15 | public function setUp() |
||
16 | { |
||
17 | parent::setUp(); |
||
18 | $this->list = new DataList('GridFieldAction_Delete_Team'); |
||
19 | $config = CommentsGridFieldConfig::create()->addComponent(new GridFieldDeleteAction()); |
||
20 | $this->gridField = new CommentsGridField('testfield', 'testfield', $this->list, $config); |
||
21 | $this->form = new Form(new Controller(), 'mockform', new FieldList(array($this->gridField)), new FieldList()); |
||
22 | } |
||
23 | |||
24 | public function testAugmentColumns() |
||
25 | { |
||
26 | $action = new CommentsGridFieldAction(); |
||
27 | |||
28 | // an entry called 'Actions' is added to the columns array |
||
29 | $columns = array(); |
||
30 | $action->augmentColumns($this->gridField, $columns); |
||
31 | $expected = array('Actions'); |
||
32 | $this->assertEquals($expected, $columns); |
||
0 ignored issues
–
show
|
|||
33 | |||
34 | $columns = array('Actions'); |
||
35 | $action->augmentColumns($this->gridField, $columns); |
||
36 | $expected = array('Actions'); |
||
37 | $this->assertEquals($expected, $columns); |
||
0 ignored issues
–
show
The method
assertEquals() does not seem to exist on object<CommentsGridFieldActionTest> .
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.
Loading history...
|
|||
38 | } |
||
39 | |||
40 | public function testGetColumnAttributes() |
||
41 | { |
||
42 | $action = new CommentsGridFieldAction(); |
||
43 | $record = new Comment(); |
||
44 | $attrs = $action->getColumnAttributes($this->gridField, $record, 'Comment'); |
||
45 | $this->assertEquals(array('class' => 'col-buttons'), $attrs); |
||
46 | } |
||
47 | |||
48 | public function testGetColumnMetadata() |
||
49 | { |
||
50 | $action = new CommentsGridFieldAction(); |
||
51 | $result = $action->getColumnMetadata($this->gridField, 'Actions'); |
||
52 | $this->assertEquals(array('title' => ''), $result); |
||
53 | $result = $action->getColumnMetadata($this->gridField, 'SomethingElse'); |
||
54 | $this->assertNull($result); |
||
55 | } |
||
56 | |||
57 | public function testGetColumnsHandled() |
||
58 | { |
||
59 | $action = new CommentsGridFieldAction(); |
||
60 | $result = $action->getColumnsHandled($this->gridField); |
||
61 | $this->assertEquals(array('Actions'), $result); |
||
62 | } |
||
63 | |||
64 | public function testGetColumnContent() |
||
65 | { |
||
66 | $this->logInWithPermission('CMS_ACCESS_CommentAdmin'); |
||
67 | $action = new CommentsGridFieldAction(); |
||
68 | $record = new Comment(); |
||
69 | $record->Name = 'Name of commeter'; |
||
70 | $record->Comment = 'This is a comment'; |
||
71 | $record->write(); |
||
72 | $recordID = $record->ID; |
||
73 | $html = $action->getColumnContent($this->gridField, $record, 'Comment'); |
||
74 | $this->assertContains('data-url="Controller/mockform/field/testfield', |
||
75 | $html); |
||
76 | $spamAction = 'value="Spam" class="action" id="action_CustomAction' . |
||
77 | $recordID . 'Spam"'; |
||
78 | $this->assertContains($spamAction, $html); |
||
79 | |||
80 | $approveAction = 'value="Approve" class="action" id="action_CustomAction' . |
||
81 | $recordID . 'Approve"'; |
||
82 | $this->assertContains($approveAction, $html); |
||
83 | |||
84 | // If marked as spam, only the approve button should be available |
||
85 | $record->markSpam(); |
||
86 | $record->write(); |
||
87 | $html = $action->getColumnContent($this->gridField, $record, 'Comment'); |
||
88 | $this->assertContains($approveAction, $html); |
||
89 | $this->assertNotContains($spamAction, $html); |
||
90 | |||
91 | // If marked as spam, only the approve button should be available |
||
92 | $record->markApproved(); |
||
93 | $record->write(); |
||
94 | $html = $action->getColumnContent($this->gridField, $record, 'Comment'); |
||
95 | $this->assertNotContains($approveAction, $html); |
||
96 | $this->assertContains($spamAction, $html); |
||
97 | } |
||
98 | |||
99 | public function testGetActions() |
||
100 | { |
||
101 | $action = new CommentsGridFieldAction(); |
||
102 | $result = $action->getActions($this->gridField); |
||
103 | $this->assertEquals(array('spam', 'approve'), $result); |
||
104 | } |
||
105 | |||
106 | |||
107 | public function testHandleAction() |
||
108 | { |
||
109 | $action = new CommentsGridFieldAction(); |
||
110 | $record = new Comment(); |
||
111 | $record->Name = 'Name of commeter'; |
||
112 | $record->Comment = 'This is a comment'; |
||
113 | $record->write(); |
||
114 | $recordID = $record->ID; |
||
115 | $arguments = array('RecordID' => $recordID); |
||
116 | $data = array(); |
||
117 | $result = $action->handleAction($this->gridField, 'spam', $arguments, $data); |
||
118 | $this->assertEquals(200, Controller::curr()->getResponse()->getStatusCode()); |
||
0 ignored issues
–
show
The method
assertEquals() does not seem to exist on object<CommentsGridFieldActionTest> .
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.
Loading history...
|
|||
119 | $this->assertEquals( |
||
0 ignored issues
–
show
The method
assertEquals() does not seem to exist on object<CommentsGridFieldActionTest> .
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.
Loading history...
|
|||
120 | 'Comment marked as spam.', |
||
121 | Controller::curr()->getResponse()->getStatusDescription() |
||
122 | ); |
||
123 | $record = DataObject::get_by_id('Comment', $recordID); |
||
124 | $this->assertEquals(1, $record->Moderated); |
||
0 ignored issues
–
show
The method
assertEquals() does not seem to exist on object<CommentsGridFieldActionTest> .
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.
Loading history...
|
|||
125 | $this->assertEquals(1, $record->IsSpam); |
||
126 | |||
127 | //getStatusDescription |
||
128 | $result = $action->handleAction($this->gridField, 'approve', $arguments, $data); |
||
129 | $this->assertEquals(200, Controller::curr()->getResponse()->getStatusCode()); |
||
0 ignored issues
–
show
The method
assertEquals() does not seem to exist on object<CommentsGridFieldActionTest> .
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.
Loading history...
|
|||
130 | $this->assertEquals( |
||
0 ignored issues
–
show
The method
assertEquals() does not seem to exist on object<CommentsGridFieldActionTest> .
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.
Loading history...
|
|||
131 | 'Comment approved.', |
||
132 | Controller::curr()->getResponse()->getStatusDescription() |
||
133 | ); |
||
134 | |||
135 | $record = DataObject::get_by_id('Comment', $recordID); |
||
136 | $this->assertEquals(1, $record->Moderated); |
||
0 ignored issues
–
show
The method
assertEquals() does not seem to exist on object<CommentsGridFieldActionTest> .
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.
Loading history...
|
|||
137 | $this->assertEquals(0, $record->IsSpam); |
||
138 | |||
139 | error_log(Controller::curr()->getResponse()->getStatusCode()); |
||
140 | } |
||
141 | } |
||
142 |
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.