Skip to content

Commit 32079c4

Browse files
committed
made tests run on empty presenters
1 parent 14699e7 commit 32079c4

40 files changed

Lines changed: 2256 additions & 6111 deletions

app/V1Module/presenters/AssignmentSolutionReviewsPresenter.php

Lines changed: 13 additions & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class AssignmentSolutionReviewsPresenter extends BasePresenter
7878
public $reviewsEmailSender;
7979

8080

81-
public function checkDefault(string $id)
81+
public function noncheckDefault(string $id)
8282
{
8383
$solution = $this->assignmentSolutions->findOrThrow($id);
8484
if (!$this->assignmentSolutionAcl->canViewReview($solution)) {
@@ -94,14 +94,10 @@ public function checkDefault(string $id)
9494
#[Path("id", new VUuid(), "identifier of the solution", required: true)]
9595
public function actionDefault(string $id)
9696
{
97-
$solution = $this->assignmentSolutions->findOrThrow($id);
98-
$this->sendSuccessResponse([
99-
"solution" => $this->assignmentSolutionViewFactory->getSolutionData($solution),
100-
"reviewComments" => $solution->getReviewComments()->toArray(),
101-
]);
97+
$this->sendSuccessResponse("OK");
10298
}
10399

104-
public function checkUpdate(string $id)
100+
public function noncheckUpdate(string $id)
105101
{
106102
$solution = $this->assignmentSolutions->findOrThrow($id);
107103
if (!$this->assignmentSolutionAcl->canReview($solution)) {
@@ -118,48 +114,10 @@ public function checkUpdate(string $id)
118114
#[Path("id", new VUuid(), "identifier of the solution", required: true)]
119115
public function actionUpdate(string $id)
120116
{
121-
$solution = $this->assignmentSolutions->findOrThrow($id);
122-
$close = filter_var($this->getRequest()->getPost("close"), FILTER_VALIDATE_BOOLEAN);
123-
$reviewedAt = $solution->getReviewedAt();
124-
125-
if ($solution->getReviewStartedAt() === null) {
126-
$solution->setReviewStartedAt(new DateTime()); // the review is marked as opened in any case
127-
}
128-
129-
if ($close && $reviewedAt === null) {
130-
// opened -> closed transition
131-
$solution->setReviewedAt(new DateTime());
132-
133-
$issues = 0; // issues are duly counted only when the review is closed
134-
foreach ($solution->getReviewComments() as $comment) {
135-
if ($comment->isIssue()) {
136-
++$issues;
137-
}
138-
}
139-
$solution->setIssuesCount($issues);
140-
} elseif (!$close && $reviewedAt !== null) {
141-
// closed -> opened (reverse) transition
142-
$solution->setReviewedAt(null);
143-
$solution->setIssuesCount(0);
144-
}
145-
146-
// make sure modifications are saved first
147-
$this->assignmentSolutions->persist($solution);
148-
149-
// handle mail notifications
150-
if ($close && $reviewedAt === null) {
151-
$this->reviewsEmailSender->solutionReviewClosed($solution);
152-
} elseif (!$close && $reviewedAt !== null) {
153-
$this->reviewsEmailSender->solutionReviewReopened($solution, $reviewedAt);
154-
}
155-
156-
$this->sendSuccessResponse([
157-
"solution" => $this->assignmentSolutionViewFactory->getSolutionData($solution),
158-
"reviewComments" => $solution->getReviewComments()->toArray(),
159-
]);
117+
$this->sendSuccessResponse("OK");
160118
}
161119

162-
public function checkRemove(string $id)
120+
public function noncheckRemove(string $id)
163121
{
164122
$solution = $this->assignmentSolutions->findOrThrow($id);
165123
if (!$this->assignmentSolutionAcl->canReview($solution)) {
@@ -187,27 +145,10 @@ public function checkRemove(string $id)
187145
#[Path("id", new VUuid(), "identifier of the solution", required: true)]
188146
public function actionRemove(string $id)
189147
{
190-
$solution = $this->assignmentSolutions->findOrThrow($id);
191-
$closed = $solution->getReviewedAt(); // remember that!
192-
193-
// erase all comments
194-
$this->reviewComments->deleteCommentsOfSolution($solution);
195-
196-
// reset the state in the solution entity
197-
$solution->setReviewStartedAt(null);
198-
$solution->setReviewedAt(null);
199-
$solution->setIssuesCount(0);
200-
$this->assignmentSolutions->persist($solution);
201-
202-
if ($closed !== null) {
203-
// notifications are sent only for closed reviews
204-
$this->reviewsEmailSender->solutionReviewRemoved($solution, $closed);
205-
}
206-
207148
$this->sendSuccessResponse("OK");
208149
}
209150

210-
public function checkNewComment(string $id)
151+
public function noncheckNewComment(string $id)
211152
{
212153
$solution = $this->assignmentSolutions->findOrThrow($id);
213154
if (!$this->assignmentSolutionAcl->canAddReviewComment($solution)) {
@@ -242,7 +183,7 @@ private function verifyCodeLocation(AssignmentSolution $solution, string $file,
242183
);
243184
}
244185

245-
// TODO - in the future, we might want to check the entry as well
186+
// TODO - in the future, we might want to noncheck the entry as well
246187
} elseif ($line !== 0) {
247188
throw new BadRequestException("Global comment (with no file) must have a line value set to zero.");
248189
}
@@ -276,46 +217,10 @@ private function verifyCodeLocation(AssignmentSolution $solution, string $file,
276217
#[Path("id", new VUuid(), "identifier of the solution", required: true)]
277218
public function actionNewComment(string $id)
278219
{
279-
$solution = $this->assignmentSolutions->findOrThrow($id);
280-
if ($solution->getReviewStartedAt() === null) {
281-
// first comment also opens the review
282-
$solution->setReviewStartedAt(new DateTime());
283-
$this->assignmentSolutions->persist($solution);
284-
}
285-
286-
// get and verify inputs
287-
$req = $this->getRequest();
288-
$text = trim($req->getPost("text"));
289-
if (!$text) {
290-
throw new BadRequestException("The text of the comment must not be empty.");
291-
}
292-
293-
$file = trim($req->getPost("file"));
294-
$line = $req->getPost("line");
295-
$this->verifyCodeLocation($solution, $file, $line);
296-
$issue = filter_var($req->getPost("issue"), FILTER_VALIDATE_BOOLEAN);
297-
298-
// create the review comment
299-
$comment = new ReviewComment($solution, $this->getCurrentUser(), $file, $line, $text, $issue);
300-
$this->reviewComments->persist($comment);
301-
302-
if ($solution->getReviewedAt() !== null) {
303-
// review is already closed, this needs special treatment
304-
if ($issue) {
305-
$solution->setIssuesCount($solution->getIssuesCount() + 1);
306-
$this->assignmentSolutions->persist($solution);
307-
}
308-
309-
$suppressNotification = filter_var($req->getPost("suppressNotification"), FILTER_VALIDATE_BOOLEAN);
310-
if (!$suppressNotification) {
311-
$this->reviewsEmailSender->newReviewComment($solution, $comment);
312-
}
313-
}
314-
315-
$this->sendSuccessResponse($comment);
220+
$this->sendSuccessResponse("OK");
316221
}
317222

318-
public function checkEditComment(string $id, string $commentId)
223+
public function noncheckEditComment(string $id, string $commentId)
319224
{
320225
$solution = $this->assignmentSolutions->findOrThrow($id);
321226
$comment = $this->reviewComments->findOrThrow($commentId);
@@ -350,46 +255,10 @@ public function checkEditComment(string $id, string $commentId)
350255
#[Path("commentId", new VString(), "identifier of the review comment", required: true)]
351256
public function actionEditComment(string $id, string $commentId)
352257
{
353-
$solution = $this->assignmentSolutions->findOrThrow($id);
354-
$comment = $this->reviewComments->findOrThrow($commentId);
355-
356-
// get and verify inputs
357-
$req = $this->getRequest();
358-
$text = trim($req->getPost("text"));
359-
if (!$text) {
360-
throw new BadRequestException("The text of the comment must not be empty.");
361-
}
362-
363-
$issue = $req->getPost("issue") !== null ? filter_var($req->getPost("issue"), FILTER_VALIDATE_BOOLEAN) : null;
364-
$issueChanged = $issue !== null && $comment->isIssue() !== $issue;
365-
366-
if ($text !== $comment->getText() || $issueChanged) {
367-
// modification needed
368-
$oldText = $comment->getText();
369-
$comment->setText($text);
370-
if ($issue !== null) {
371-
$comment->setIssue($issue);
372-
}
373-
$this->reviewComments->persist($comment);
374-
375-
if ($solution->getReviewedAt() !== null) {
376-
// review is already closed, this needs special treatment
377-
if ($issueChanged) {
378-
$solution->setIssuesCount($solution->getIssuesCount() + ($issue ? 1 : -1));
379-
$this->assignmentSolutions->persist($solution);
380-
}
381-
382-
$suppressNotification = filter_var($req->getPost("suppressNotification"), FILTER_VALIDATE_BOOLEAN);
383-
if (!$suppressNotification) {
384-
$this->reviewsEmailSender->changedReviewComment($solution, $comment, $oldText, $issueChanged);
385-
}
386-
}
387-
}
388-
389-
$this->sendSuccessResponse($comment);
258+
$this->sendSuccessResponse("OK");
390259
}
391260

392-
public function checkDeleteComment(string $id, string $commentId)
261+
public function noncheckDeleteComment(string $id, string $commentId)
393262
{
394263
$solution = $this->assignmentSolutions->findOrThrow($id);
395264
$comment = $this->reviewComments->findOrThrow($commentId);
@@ -410,26 +279,10 @@ public function checkDeleteComment(string $id, string $commentId)
410279
#[Path("commentId", new VString(), "identifier of the review comment", required: true)]
411280
public function actionDeleteComment(string $id, string $commentId)
412281
{
413-
$comment = $this->reviewComments->findOrThrow($commentId);
414-
$isIssue = $comment->isIssue();
415-
$this->reviewComments->remove($comment);
416-
417-
$solution = $this->assignmentSolutions->findOrThrow($id);
418-
if ($solution->getReviewedAt() !== null) {
419-
// review is already closed, this needs special treatment
420-
if ($isIssue) {
421-
$solution->setIssuesCount($solution->getIssuesCount() - 1);
422-
$this->assignmentSolutions->persist($solution);
423-
}
424-
$this->reviewComments->flush();
425-
426-
// deletions are always reported (if the review is closed)
427-
$this->reviewsEmailSender->removedReviewComment($solution, $comment);
428-
}
429282
$this->sendSuccessResponse("OK");
430283
}
431284

432-
public function checkPending(string $id)
285+
public function noncheckPending(string $id)
433286
{
434287
$user = $this->users->findOrThrow($id);
435288
if (!$this->userAcl->canListPendingReviews($user)) {
@@ -445,20 +298,6 @@ public function checkPending(string $id)
445298
#[Path("id", new VUuid(), "of the user whose pending reviews are listed", required: true)]
446299
public function actionPending(string $id)
447300
{
448-
$user = $this->users->findOrThrow($id);
449-
$solutions = $this->assignmentSolutions->findPendingReviewsOfTeacher($user);
450-
451-
$assignments = [];
452-
foreach ($solutions as $solution) {
453-
$assignment = $solution->getAssignment();
454-
if ($assignment) {
455-
$assignments[$assignment->getId()] = $assignment;
456-
}
457-
}
458-
459-
$this->sendSuccessResponse([
460-
'solutions' => $this->assignmentSolutionViewFactory->getSolutionsData($solutions),
461-
'assignments' => $this->assignmentsViewFactory->getAssignments(array_values($assignments)),
462-
]);
301+
$this->sendSuccessResponse("OK");
463302
}
464303
}

0 commit comments

Comments
 (0)