1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class CommentsGridFieldTest extends SapphireTest { |
|
|
|
|
4
|
|
|
public function testNewRow() { |
5
|
|
|
$gridfield = new CommentsGridField('testfield', 'testfield'); |
6
|
|
|
// protected function newRow($total, $index, $record, $attributes, $content) { |
|
|
|
|
7
|
|
|
$comment = new Comment(); |
8
|
|
|
$comment->Name = 'Fred Bloggs'; |
9
|
|
|
$comment->Comment = 'This is a comment'; |
10
|
|
|
$attr = array(); |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
try { |
14
|
|
|
$class = new ReflectionClass($gridfield); |
15
|
|
|
$method = $class->getMethod('newRow'); |
16
|
|
|
$method->setAccessible(true); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
catch (ReflectionException $e) { |
20
|
|
|
$this->fail($e->getMessage()); |
|
|
|
|
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
$params = array(1, 1, $comment, $attr, $comment->Comment); |
24
|
|
|
$newRow = $method->invokeArgs($gridfield, $params); |
|
|
|
|
25
|
|
|
$this->assertEquals('<tr>This is a comment</tr>', $newRow); |
|
|
|
|
26
|
|
|
|
27
|
|
|
$attr = array('class' => 'cssClass'); |
28
|
|
|
$params = array(1, 1, $comment, $attr, $comment->Comment); |
29
|
|
|
$newRow = $method->invokeArgs($gridfield, $params); |
30
|
|
|
$this->assertEquals('<tr class="cssClass">This is a comment</tr>', $newRow); |
|
|
|
|
31
|
|
|
|
32
|
|
|
$comment->markSpam(); |
33
|
|
|
$params = array(1, 1, $comment, $attr, $comment->Comment); |
34
|
|
|
$newRow = $method->invokeArgs($gridfield, $params); |
35
|
|
|
$this->assertEquals('<tr class="cssClass spam">This is a comment</tr>', $newRow); |
|
|
|
|
36
|
|
|
|
37
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
} |
41
|
|
|
|
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.