1
1
<?php
2
2
$ container = require_once __DIR__ . "/../bootstrap.php " ;
3
3
4
+ use App \Helpers \Notifications \SolutionCommentsEmailsSender ;
4
5
use App \V1Module \Presenters \CommentsPresenter ;
5
6
use Tester \Assert ;
6
7
@@ -36,20 +37,21 @@ class TestCommentsPresenter extends Tester\TestCase
36
37
protected function setUp ()
37
38
{
38
39
PresenterTestHelper::fillDatabase ($ this ->container );
39
-
40
40
$ this ->presenter = PresenterTestHelper::createPresenter ($ this ->container , CommentsPresenter::class);
41
41
}
42
42
43
43
protected function tearDown ()
44
44
{
45
+ Mockery::close ();
46
+
45
47
if ($ this ->user ->isLoggedIn ()) {
46
48
$ this ->user ->logout (true );
47
49
}
48
50
}
49
51
50
52
public function testGetCommentsInNormalThread ()
51
53
{
52
- $ token = PresenterTestHelper::login ($ this ->container , $ this ->userLogin , $ this -> userPassword );
54
+ $ token = PresenterTestHelper::login ($ this ->container , $ this ->userLogin );
53
55
54
56
$ request = new Nette \Application \Request ('V1:Comments ' , 'GET ' , ['action ' => 'default ' , 'id ' => 'mainThread ' ]);
55
57
$ response = $ this ->presenter ->run ($ request );
@@ -68,7 +70,7 @@ class TestCommentsPresenter extends Tester\TestCase
68
70
69
71
public function testGetCommentsInEmptyThread ()
70
72
{
71
- $ token = PresenterTestHelper::login ($ this ->container , $ this ->userLogin , $ this -> userPassword );
73
+ $ token = PresenterTestHelper::login ($ this ->container , $ this ->userLogin );
72
74
73
75
$ request = new Nette \Application \Request ('V1:Comments ' , 'GET ' , ['action ' => 'default ' , 'id ' => 'emptyThread ' ]);
74
76
$ response = $ this ->presenter ->run ($ request );
@@ -82,7 +84,7 @@ class TestCommentsPresenter extends Tester\TestCase
82
84
83
85
public function testAddCommentIntoExistingThread ()
84
86
{
85
- $ token = PresenterTestHelper::login ($ this ->container , $ this ->userLogin , $ this -> userPassword );
87
+ $ token = PresenterTestHelper::login ($ this ->container , $ this ->userLogin );
86
88
87
89
$ request = new Nette \Application \Request (
88
90
'V1:Comments ' ,
@@ -104,9 +106,69 @@ class TestCommentsPresenter extends Tester\TestCase
104
106
Assert::same ($ this ->presenter ->comments ->findOneBy (['id ' => $ comment ->id ]), $ result ['payload ' ]);
105
107
}
106
108
109
+ public function testAddCommentIntoExistingAssignmentSolutionThread ()
110
+ {
111
+ PresenterTestHelper::login ($ this ->container , $ this ->userLogin );
112
+ $ assignmentSolution = current ($ this ->presenter ->assignmentSolutions ->findAll ());
113
+
114
+ // mock emails sender
115
+ $ mockSolutionCommentsEmailsSender = Mockery::mock (SolutionCommentsEmailsSender::class);
116
+ $ mockSolutionCommentsEmailsSender ->shouldReceive ("assignmentSolutionComment " )->once ();
117
+ $ this ->presenter ->solutionCommentsEmailsSender = $ mockSolutionCommentsEmailsSender ;
118
+
119
+ $ request = new Nette \Application \Request (
120
+ 'V1:Comments ' ,
121
+ 'POST ' ,
122
+ ['action ' => 'addComment ' , 'id ' => $ assignmentSolution ->getId ()],
123
+ ['text ' => 'some comment text ' , 'isPrivate ' => 'false ' ]
124
+ );
125
+ $ response = $ this ->presenter ->run ($ request );
126
+ Assert::type (Nette \Application \Responses \JsonResponse::class, $ response );
127
+
128
+ $ result = $ response ->getPayload ();
129
+ Assert::equal (200 , $ result ['code ' ]);
130
+ $ comment = $ result ['payload ' ];
131
+ Assert::false ($ comment ->isPrivate );
132
+ Assert::equal ("some comment text " , $ comment ->text );
133
+ Assert::equal ($ assignmentSolution ->getId (), $ comment ->commentThread ->id );
134
+
135
+ // Make sure the assignment was persisted
136
+ Assert::same ($ this ->presenter ->comments ->findOneBy (['id ' => $ comment ->id ]), $ result ['payload ' ]);
137
+ }
138
+
139
+ public function testAddCommentIntoExistingReferenceSolutionThread ()
140
+ {
141
+ PresenterTestHelper::login ($ this ->container , $ this ->userLogin );
142
+ $ referenceSolution = current ($ this ->presenter ->referenceExerciseSolutions ->findAll ());
143
+
144
+ // mock emails sender
145
+ $ mockSolutionCommentsEmailsSender = Mockery::mock (SolutionCommentsEmailsSender::class);
146
+ $ mockSolutionCommentsEmailsSender ->shouldReceive ("referenceSolutionComment " )->once ();
147
+ $ this ->presenter ->solutionCommentsEmailsSender = $ mockSolutionCommentsEmailsSender ;
148
+
149
+ $ request = new Nette \Application \Request (
150
+ 'V1:Comments ' ,
151
+ 'POST ' ,
152
+ ['action ' => 'addComment ' , 'id ' => $ referenceSolution ->getId ()],
153
+ ['text ' => 'some comment text ' , 'isPrivate ' => 'false ' ]
154
+ );
155
+ $ response = $ this ->presenter ->run ($ request );
156
+ Assert::type (Nette \Application \Responses \JsonResponse::class, $ response );
157
+
158
+ $ result = $ response ->getPayload ();
159
+ Assert::equal (200 , $ result ['code ' ]);
160
+ $ comment = $ result ['payload ' ];
161
+ Assert::false ($ comment ->isPrivate );
162
+ Assert::equal ("some comment text " , $ comment ->text );
163
+ Assert::equal ($ referenceSolution ->getId (), $ comment ->commentThread ->id );
164
+
165
+ // Make sure the assignment was persisted
166
+ Assert::same ($ this ->presenter ->comments ->findOneBy (['id ' => $ comment ->id ]), $ result ['payload ' ]);
167
+ }
168
+
107
169
public function testAddCommentIntoNonexistingThread ()
108
170
{
109
- $ token = PresenterTestHelper::login ($ this ->container , $ this ->userLogin , $ this -> userPassword );
171
+ $ token = PresenterTestHelper::login ($ this ->container , $ this ->userLogin );
110
172
111
173
$ request = new Nette \Application \Request (
112
174
'V1:Comments ' ,
0 commit comments