1 | <?php |
||
2 | |||
3 | namespace SilverStripe\Comments\Tests; |
||
4 | |||
5 | use ReflectionClass; |
||
6 | use ReflectionException; |
||
7 | use SilverStripe\Comments\Model\Comment; |
||
8 | use SilverStripe\Comments\Admin\CommentsGridField; |
||
9 | use SilverStripe\Dev\SapphireTest; |
||
10 | |||
11 | class CommentsGridFieldTest extends SapphireTest |
||
12 | { |
||
13 | public function testNewRow() |
||
14 | { |
||
15 | $gridfield = new CommentsGridField('testfield', 'testfield'); |
||
16 | // protected function newRow($total, $index, $record, $attributes, $content) { |
||
17 | $comment = new Comment(); |
||
18 | $comment->Name = 'Fred Bloggs'; |
||
19 | $comment->Comment = 'This is a comment'; |
||
20 | $attr = array(); |
||
21 | |||
22 | try { |
||
23 | $class = new ReflectionClass($gridfield); |
||
24 | $method = $class->getMethod('newRow'); |
||
25 | $method->setAccessible(true); |
||
26 | } catch (ReflectionException $e) { |
||
27 | $this->fail($e->getMessage()); |
||
28 | } |
||
29 | |||
30 | $params = array(1, 1, $comment, $attr, $comment->Comment); |
||
31 | $newRow = $method->invokeArgs($gridfield, $params); |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
![]() |
|||
32 | $this->assertEquals('<tr>This is a comment</tr>', $newRow); |
||
33 | |||
34 | $attr = array('class' => 'cssClass'); |
||
35 | $params = array(1, 1, $comment, $attr, $comment->Comment); |
||
36 | $newRow = $method->invokeArgs($gridfield, $params); |
||
37 | $this->assertEquals('<tr class="cssClass">This is a comment</tr>', $newRow); |
||
38 | |||
39 | $comment->markSpam(); |
||
40 | $params = array(1, 1, $comment, $attr, $comment->Comment); |
||
41 | $newRow = $method->invokeArgs($gridfield, $params); |
||
42 | $this->assertEquals('<tr class="cssClass spam">This is a comment</tr>', $newRow); |
||
43 | } |
||
44 | } |
||
45 |