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 CommentListTest extends FunctionalTest { |
||
4 | |||
5 | public static $fixture_file = 'comments/tests/CommentsTest.yml'; |
||
6 | |||
7 | protected $extraDataObjects = array( |
||
8 | 'CommentableItem', |
||
9 | 'CommentableItemEnabled', |
||
10 | 'CommentableItemDisabled' |
||
11 | ); |
||
12 | |||
13 | View Code Duplication | public function setUp() { |
|
14 | parent::setUp(); |
||
15 | Config::nest(); |
||
16 | |||
17 | // Set good default values |
||
18 | Config::inst()->update('CommentsExtension', 'comments', array( |
||
19 | 'enabled' => true, |
||
20 | 'enabled_cms' => false, |
||
21 | 'require_login' => false, |
||
22 | 'require_login_cms' => false, |
||
23 | 'required_permission' => false, |
||
24 | 'require_moderation_nonmembers' => false, |
||
25 | 'require_moderation' => false, |
||
26 | 'require_moderation_cms' => false, |
||
27 | 'frontend_moderation' => false, |
||
28 | 'frontend_spam' => false, |
||
29 | )); |
||
30 | |||
31 | // Configure this dataobject |
||
32 | Config::inst()->update('CommentableItem', 'comments', array( |
||
33 | 'enabled_cms' => true |
||
34 | )); |
||
35 | } |
||
36 | |||
37 | public function tearDown() { |
||
38 | Config::unnest(); |
||
39 | parent::tearDown(); |
||
40 | } |
||
41 | |||
42 | public function testGetForeignClass() { |
||
43 | $item = $this->objFromFixture('CommentableItem', 'first'); |
||
44 | |||
45 | // This is the class the Comments are related to |
||
46 | $this->assertEquals('CommentableItem', |
||
47 | $item->Comments()->getForeignClass()); |
||
48 | } |
||
49 | |||
50 | View Code Duplication | public function testAddNonComment() { |
|
51 | $item = $this->objFromFixture('CommentableItem', 'first'); |
||
52 | $comments = $item->Comments(); |
||
53 | $this->assertEquals(4, $comments->count()); |
||
0 ignored issues
–
show
|
|||
54 | $member = Member::get()->first(); |
||
55 | try { |
||
56 | $comments->add($member); |
||
57 | $this->fail('Should not have been able to add member to comments'); |
||
58 | } catch (InvalidArgumentException $e) { |
||
59 | $this->assertEquals( |
||
0 ignored issues
–
show
The method
assertEquals() does not seem to exist on object<CommentListTest> .
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...
|
|||
60 | 'CommentList::add() expecting a Comment object, or ID value', |
||
61 | $e->getMessage() |
||
62 | ); |
||
63 | } |
||
64 | } |
||
65 | |||
66 | public function testAddComment() { |
||
67 | $item = $this->objFromFixture('CommentableItem', 'first'); |
||
68 | $firstComment = $this->objFromFixture('Comment', 'firstComA'); |
||
69 | $comments = $item->Comments();//->sort('Created'); |
||
70 | |||
71 | foreach ($comments as $comment) { |
||
72 | error_log($comment->ID . ' ' . $comment->Created .' ' . $comment->Comment); |
||
73 | } |
||
74 | |||
75 | $this->assertEquals(4, $comments->count()); |
||
0 ignored issues
–
show
The method
assertEquals() does not seem to exist on object<CommentListTest> .
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...
|
|||
76 | $newComment = new Comment(); |
||
77 | $newComment->Name = 'Fred Bloggs'; |
||
78 | $newComment->Comment = 'This is a test comment'; |
||
79 | $newComment->write(); |
||
80 | |||
81 | $comments->add($newComment); |
||
82 | // As a comment has been added, there should be 5 comments now |
||
83 | $this->assertEquals(5, $item->Comments()->count()); |
||
84 | |||
85 | $newComment2 = new Comment(); |
||
86 | $newComment2->Name = 'John Smith'; |
||
87 | $newComment2->Comment = 'This is another test comment'; |
||
88 | $newComment2->write(); |
||
89 | |||
90 | // test adding the same comment by ID |
||
91 | $comments->add($newComment2->ID); |
||
92 | $this->assertEquals(6, $item->Comments()->count()); |
||
93 | |||
94 | $this->setExpectedException( |
||
95 | 'InvalidArgumentException', |
||
96 | "CommentList::add() can't be called until a single foreign ID is set" |
||
97 | ); |
||
98 | $list = new CommentList('CommentableItem'); |
||
99 | $list->add($newComment); |
||
100 | } |
||
101 | |||
102 | public function testRemoveComment() { |
||
103 | // remove by comment |
||
104 | $item = $this->objFromFixture('CommentableItem', 'first'); |
||
105 | $this->assertEquals(4, $item->Comments()->count()); |
||
0 ignored issues
–
show
The method
assertEquals() does not seem to exist on object<CommentListTest> .
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...
|
|||
106 | $comments = $item->Comments(); |
||
107 | $comment = $comments->first(); |
||
108 | $comments->remove($comment); |
||
109 | |||
110 | // now remove by ID |
||
111 | $comments = $item->Comments(); |
||
112 | $comment = $comments->first(); |
||
113 | $comments->remove($comment->ID); |
||
114 | $this->assertEquals(2, $item->Comments()->count()); |
||
115 | } |
||
116 | |||
117 | View Code Duplication | public function testRemoveNonComment() { |
|
118 | $item = $this->objFromFixture('CommentableItem', 'first'); |
||
119 | $this->assertEquals(4, $item->Comments()->count()); |
||
0 ignored issues
–
show
The method
assertEquals() does not seem to exist on object<CommentListTest> .
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 | $comments = $item->Comments(); |
||
121 | |||
122 | // try and remove a non comment |
||
123 | $member = Member::get()->first(); |
||
124 | |||
125 | |||
126 | |||
127 | try { |
||
128 | $comments->remove($member); |
||
129 | $this->fail('Should not have been able to remove member from comments'); |
||
130 | } catch (InvalidArgumentException $e) { |
||
131 | $this->assertEquals( |
||
0 ignored issues
–
show
The method
assertEquals() does not seem to exist on object<CommentListTest> .
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...
|
|||
132 | 'CommentList::remove() expecting a Comment object, or ID', |
||
133 | $e->getMessage() |
||
134 | ); |
||
135 | } |
||
136 | } |
||
137 | |||
138 | } |
||
139 |
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.