public function testMultipleUnreadModels_multipleUsers_multipleUpdates_multipleVisitsToQuestionPage_usersHaveDifferentUnreadStates()
 {
     $e = new MongoTestEnvironment();
     $e->clean();
     $project = $e->createProject("unread_test", "unreadCode");
     $projectId = $project->id->asString();
     $userId1 = $e->createUser('user1', 'user1', 'user1');
     $user1 = new UserModel($userId1);
     $user1->addProject($project->id->asString());
     $user1->write();
     $userId2 = $e->createUser('user2', 'user2', 'user2');
     $user2 = new UserModel($userId2);
     $user2->addProject($project->id->asString());
     $user2->write();
     $userId3 = $e->createUser('user3', 'user3', 'user3');
     $user3 = new UserModel($userId3);
     $user3->addProject($project->id->asString());
     $user3->write();
     $answer1 = array('content' => "test answer 1", 'id' => '');
     $answer2 = array('content' => "test answer 2", 'id' => '');
     $text = new TextModel($project);
     $text->title = "Text 1";
     $usx = MongoTestEnvironment::usxSample();
     $text->content = $usx;
     $textId = $text->write();
     $question = new QuestionModel($project);
     $question->title = "test question";
     $question->textRef->id = $textId;
     $questionId = $question->write();
     $answer1Dto = QuestionCommands::updateAnswer($projectId, $questionId, $answer1, $userId1);
     $answer2Dto = QuestionCommands::updateAnswer($projectId, $questionId, $answer2, $userId2);
     $answer1 = array_pop($answer1Dto);
     $answer1Id = $answer1['id'];
     $answer2 = array_pop($answer2Dto);
     $answer2Id = $answer2['id'];
     // the answer author does NOT get their answer marked as unread
     $unreadModel = new UnreadAnswerModel($userId1, $projectId, $questionId);
     $this->assertEqual(count($unreadModel->unreadItems()), 1);
     // the answer author does NOT get their answer marked as unread
     $unreadModel = new UnreadAnswerModel($userId2, $projectId, $questionId);
     $this->assertEqual(count($unreadModel->unreadItems()), 1);
     $unreadModel = new UnreadAnswerModel($userId3, $projectId, $questionId);
     $this->assertEqual(count($unreadModel->unreadItems()), 2);
     // user1 visits question page
     $pageDto = QuestionCommentDto::encode($projectId, $questionId, $userId1);
     $unreadModel = new UnreadAnswerModel($userId1, $projectId, $questionId);
     $this->assertEqual(count($unreadModel->unreadItems()), 0);
     $unreadModel = new UnreadAnswerModel($userId2, $projectId, $questionId);
     $this->assertEqual(count($unreadModel->unreadItems()), 1);
     $unreadModel = new UnreadAnswerModel($userId3, $projectId, $questionId);
     $this->assertEqual(count($unreadModel->unreadItems()), 2);
     // user2 visits question page
     $pageDto = QuestionCommentDto::encode($projectId, $questionId, $userId2);
     $unreadModel = new UnreadAnswerModel($userId1, $projectId, $questionId);
     $this->assertEqual(count($unreadModel->unreadItems()), 0);
     $unreadModel = new UnreadAnswerModel($userId2, $projectId, $questionId);
     $this->assertEqual(count($unreadModel->unreadItems()), 0);
     $unreadModel = new UnreadAnswerModel($userId3, $projectId, $questionId);
     $this->assertEqual(count($unreadModel->unreadItems()), 2);
     // user2 visits question page
     $pageDto = QuestionCommentDto::encode($projectId, $questionId, $userId3);
     $unreadModel = new UnreadAnswerModel($userId1, $projectId, $questionId);
     $this->assertEqual(count($unreadModel->unreadItems()), 0);
     $unreadModel = new UnreadAnswerModel($userId2, $projectId, $questionId);
     $this->assertEqual(count($unreadModel->unreadItems()), 0);
     $unreadModel = new UnreadAnswerModel($userId3, $projectId, $questionId);
     $this->assertEqual(count($unreadModel->unreadItems()), 0);
 }
 /**
  * Returns the AnswerModel as an AnswerDTO, a part of the QuestionDTO.
  * @param AnswerModel $answerModel
  * @return array
  */
 private static function encodeAnswer($answerModel)
 {
     $answerDTO = QuestionCommentDto::encodeAnswer($answerModel);
     $answerId = $answerModel->id->asString();
     $dto = array();
     $dto[$answerId] = $answerDTO;
     return $dto;
 }
 public function testEncode_ArchivedText_ManagerCanViewContributorCannot()
 {
     $project = $this->environ->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE);
     $managerId = $this->environ->createUser("manager", "manager", "*****@*****.**");
     $contributorId = $this->environ->createUser("contributor1", "contributor1", "*****@*****.**");
     $project->addUser($managerId, ProjectRoles::MANAGER);
     $project->addUser($contributorId, ProjectRoles::CONTRIBUTOR);
     $project->write();
     // Question not archived but Text is archived
     $text = new TextModel($project);
     $text->title = "Text 1";
     $text->isArchived = true;
     $textId = $text->write();
     $question = new QuestionModel($project);
     $question->title = "the question";
     $question->description = "question description";
     $question->textRef->id = $textId;
     $questionId = $question->write();
     $dto = QuestionCommentDto::encode($project->id->asString(), $questionId, $managerId);
     // Manager can view Question of archived Text
     $this->assertEqual($dto['question']['title'], 'the question');
     // Contributor cannot view Question of archived Text, throw Exception
     $this->environ->inhibitErrorDisplay();
     $this->expectException();
     $dto = QuestionCommentDto::encode($project->id->asString(), $questionId, $contributorId);
     // nothing runs in the current test function after an exception. IJH 2014-11
 }
예제 #4
0
 public function question_comment_dto($questionId)
 {
     return \Api\Model\Scriptureforge\Dto\QuestionCommentDto::encode($this->_projectId, $questionId, $this->_userId);
 }