public function testEncode_FullQuestionWithAnswersAndComments_DtoReturnsExpectedData()
 {
     $project = $this->environ->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE);
     $text = new TextModel($project);
     $text->title = "Text 1";
     $usx = MongoTestEnvironment::usxSample();
     $text->content = $usx;
     $textId = $text->write();
     $user1Id = $this->environ->createUser("user1", "user1", "*****@*****.**");
     $user2Id = $this->environ->createUser("user2", "user2", "*****@*****.**");
     $user3Id = $this->environ->createUser("user3", "user3", "*****@*****.**");
     // Workflow is first to create a question
     $question = new QuestionModel($project);
     $question->title = "the question";
     $question->description = "question description";
     $question->textRef->id = $textId;
     $questionId = $question->write();
     // Then to add an answer to a question
     $answer = new AnswerModel();
     $answer->content = "first answer";
     $answer->score = 10;
     $answer->userRef->id = $user3Id;
     $answer->textHightlight = "text highlight";
     $answerId = $question->writeAnswer($answer);
     // Followed by comments
     $comment1 = new CommentModel();
     $comment1->content = "first comment";
     $comment1->userRef->id = $user1Id;
     $comment1Id = QuestionModel::writeComment($project->databaseName(), $questionId, $answerId, $comment1);
     $comment2 = new CommentModel();
     $comment2->content = "second comment";
     $comment2->userRef->id = $user2Id;
     $comment2Id = QuestionModel::writeComment($project->databaseName(), $questionId, $answerId, $comment2);
     $dto = QuestionCommentDto::encode($project->id->asString(), $questionId, $user1Id);
     //var_dump($dto);
     $aid = $answerId;
     $cid1 = $comment1Id;
     $cid2 = $comment2Id;
     $this->assertEqual($dto['project']['id'], $project->id);
     //$this->assertEqual($dto['text']['content'], $text->content);
     $this->assertEqual($dto['question']['id'], $questionId);
     $this->assertEqual($dto['question']['title'], 'the question');
     $this->assertEqual($dto['question']['description'], 'question description');
     $this->assertEqual($dto['question']['answers'][$aid]['content'], 'first answer');
     $this->assertEqual($dto['question']['answers'][$aid]['score'], 10);
     $this->assertEqual($dto['question']['answers'][$aid]['userRef']['avatar_ref'], 'user3.png');
     $this->assertEqual($dto['question']['answers'][$aid]['userRef']['username'], 'user3');
     $this->assertEqual($dto['question']['answers'][$aid]['comments'][$cid1]['content'], 'first comment');
     $this->assertEqual($dto['question']['answers'][$aid]['comments'][$cid1]['userRef']['username'], 'user1');
     $this->assertEqual($dto['question']['answers'][$aid]['comments'][$cid1]['userRef']['avatar_ref'], 'user1.png');
     $this->assertEqual($dto['question']['answers'][$aid]['comments'][$cid2]['content'], 'second comment');
     $this->assertEqual($dto['question']['answers'][$aid]['comments'][$cid2]['userRef']['username'], 'user2');
     $this->assertEqual($dto['question']['answers'][$aid]['comments'][$cid2]['userRef']['avatar_ref'], 'user2.png');
 }
Ejemplo n.º 2
0
 public function testGetMetadata_Ok()
 {
     $usx = MongoTestEnvironment::usxSample();
     $usxHelper = new UsxHelper($usx);
     $info = $usxHelper->getMetadata();
     $this->assertEqual($info['bookCode'], 'JHN');
     $this->assertEqual($info['startChapter'], 1);
     $this->assertEqual($info['endChapter'], 21);
     $this->assertEqual($info['startVerse'], 1);
     $this->assertEqual($info['endVerse'], 25);
 }
 public function testUserEngagementReport_simpleProjectWithQuestionsAndAnswers_AsExpected()
 {
     $e = new MongoTestEnvironment();
     $e->clean();
     $project = $e->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE);
     $text = new TextModel($project);
     $text->title = "Text 1";
     $usx = MongoTestEnvironment::usxSample();
     $text->content = $usx;
     $textId = $text->write();
     $user1Id = $e->createUser("user1", "user1", "*****@*****.**");
     $user2Id = $e->createUser("user2", "user2", "*****@*****.**");
     $user3Id = $e->createUser("user3", "user3", "*****@*****.**");
     ProjectCommands::updateUserRole($project->id->asString(), $user1Id);
     ProjectCommands::updateUserRole($project->id->asString(), $user2Id);
     ProjectCommands::updateUserRole($project->id->asString(), $user3Id);
     // Workflow is first to create a question
     $question = new QuestionModel($project);
     $question->title = "the question";
     $question->description = "question description";
     $question->textRef->id = $textId;
     $questionId = $question->write();
     // Then to add an answer to a question
     $answer = new AnswerModel();
     $answer->content = "first answer";
     $answer->score = 10;
     $answer->userRef->id = $user3Id;
     $answer->textHightlight = "text highlight";
     $answerId = $question->writeAnswer($answer);
     // Followed by comments
     $comment1 = new CommentModel();
     $comment1->content = "first comment";
     $comment1->userRef->id = $user1Id;
     $comment1Id = QuestionModel::writeComment($project->databaseName(), $questionId, $answerId, $comment1);
     $comment2 = new CommentModel();
     $comment2->content = "second comment";
     $comment2->userRef->id = $user2Id;
     $comment2Id = QuestionModel::writeComment($project->databaseName(), $questionId, $answerId, $comment2);
     $data = SfchecksReports::UserEngagementReport($project->id->asString());
     $this->assertTrue($data['output']);
 }
Ejemplo n.º 4
0
 public function testCRUD_Works()
 {
     $e = new MongoTestEnvironment();
     $e->clean();
     $project = $e->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE);
     // List
     $list = new TextListModel($project);
     $list->read();
     $this->assertEqual(0, $list->count);
     // Create
     $text = new TextModel($project);
     $text->title = "Some Text";
     $usx = MongoTestEnvironment::usxSample();
     $text->content = $usx;
     $id = $text->write();
     $this->assertNotNull($id);
     $this->assertIsA($id, 'string');
     $this->assertEqual($id, $text->id->asString());
     // Read back
     $otherText = new TextModel($project, $id);
     $this->assertEqual($id, $otherText->id->asString());
     $this->assertEqual('Some Text', $otherText->title);
     $this->assertEqual($usx, $otherText->content);
     // Update
     $otherText->title = 'Other Text';
     $otherText->write();
     // Read back
     $otherText = new TextModel($project, $id);
     $this->assertEqual('Other Text', $otherText->title);
     // List
     $list->read();
     $this->assertEqual(1, $list->count);
     // Delete
     TextModel::remove($project->databaseName(), $id);
     // List
     $list->read();
     $this->assertEqual(0, $list->count);
 }
 public function testUpdateComment_ExistingComment_OriginalAuthorIsPreserved()
 {
     $e = new MongoTestEnvironment();
     $e->clean();
     $project = $e->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE);
     $text = new TextModel($project);
     $text->title = "Text 1";
     $usx = MongoTestEnvironment::usxSample();
     $text->content = $usx;
     $textId = $text->write();
     $question = new QuestionModel($project);
     $question->textRef->id = $textId;
     $questionId = $question->write();
     $user1Id = $e->createUser("user1", "user1", "user1");
     $user2Id = $e->createUser("user2", "user2", "user2");
     $answer = new AnswerModel();
     $answer->content = "the answer";
     $answer->userRef->id = $user2Id;
     $answerId = $question->writeAnswer($answer);
     $comment = new CommentModel();
     $comment->userRef->id = $user1Id;
     $comment->content = "the comment";
     $commentId = $question->writeComment($project->databaseName(), $questionId, $answerId, $comment);
     $commentArray = array("id" => $commentId, "content" => "updated comment");
     QuestionCommands::updateComment($project->id->asString(), $questionId, $answerId, $commentArray, $user2Id);
     $question->read($questionId);
     $newComment = $question->readComment($answerId, $commentId);
     $this->assertEqual($user1Id, $newComment->userRef->asString());
 }
 public function testExportCommentsForText_QuestionArchived_NoneExported()
 {
     $project = self::$environ->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE);
     $text = new TextModel($project);
     $text->title = 'Text 1';
     $usx = MongoTestEnvironment::usxSample();
     $text->content = $usx;
     $textId = $text->write();
     $user1Id = self::$environ->createUser('user1', 'user1', '*****@*****.**');
     $user2Id = self::$environ->createUser('user2', 'user2', '*****@*****.**');
     $user3Id = self::$environ->createUser('user3', 'user3', '*****@*****.**');
     // Workflow is first to create a question
     $question = new QuestionModel($project);
     $question->title = 'the question';
     $question->description = 'question description';
     $question->textRef->id = $textId;
     $question->isArchived = true;
     $question->write();
     // Then to add an answer to a question
     $answer = new AnswerModel();
     $answer->content = 'first answer';
     $answer->score = 10;
     $answer->userRef->id = $user1Id;
     $answer->tags->exchangeArray(array('export', 'to review'));
     $answer->isToBeExported = true;
     $question->writeAnswer($answer);
     // Then to add an answer to a question
     $answer = new AnswerModel();
     $answer->content = 'second answer - very long';
     $answer->score = 2;
     $answer->userRef->id = $user2Id;
     $answer->tags->exchangeArray(array('to review'));
     $answer->isToBeExported = false;
     $question->writeAnswer($answer);
     // Then to add an answer to a question
     $answer = new AnswerModel();
     $answer->content = 'third answer - very very very very long';
     $answer->userRef->id = $user3Id;
     $answer->tags->exchangeArray(array('export'));
     $answer->isToBeExported = true;
     $question->writeAnswer($answer);
     $params = array('textId' => $textId, 'exportComments' => true, 'exportFlagged' => true, 'tags' => array());
     $download = ParatextExport::exportCommentsForText($project->id->asString(), $textId, $params);
     //        echo '<pre>' . print_r($download) . '</pre>';
     $this->assertNotRegExp('/<Contents>third answer - very very very very long \\(by user3/', $download['xml']);
     $this->assertNotRegExp('/<Contents>second answer/', $download['xml']);
     $this->assertNotRegExp('/<Contents>first answer/', $download['xml']);
 }
 public function testTrim_zeroStartChapter()
 {
     // Start chapter of 0 means "from start of book"
     $usx = MongoTestEnvironment::usxSample();
     $usxHelper = new UsxTrimHelper($usx, 0, 0, 3, 16);
     $result = $usxHelper->trimUsx();
     $simple = new SimpleXMLElement($result);
     $this->assertTrue($this->hasChapter($simple, 1));
     $this->assertTrue($this->hasChapter($simple, 2));
     $this->assertTrue($this->hasChapter($simple, 3));
     $this->assertFalse($this->hasChapter($simple, 4));
     // John 1 has 51 verses; John 2 has 25 verses
     $this->assertTrue($this->hasVerse($simple, 1, 1));
     $this->assertTrue($this->hasVerse($simple, 1, 51));
     $this->assertTrue($this->hasVerse($simple, 2, 1));
     $this->assertTrue($this->hasVerse($simple, 2, 25));
     $this->assertTrue($this->hasVerse($simple, 3, 1));
     $this->assertTrue($this->hasVerse($simple, 3, 16));
     $this->assertFalse($this->hasVerse($simple, 3, 17));
     $this->assertFalse($this->hasVerse($simple, 4, 1));
 }
 public function testMultipleUnreadModels_multipleUsers_multipleUpdates_multipleVisitsToQuestionPage_usersHaveDifferentUnreadStates()
 {
     $project = self::$environ->createProject("unread_test", "unreadCode");
     $projectId = $project->id->asString();
     $userId1 = self::$environ->createUser('user1', 'user1', 'user1');
     $user1 = new UserModel($userId1);
     $user1->addProject($project->id->asString());
     $user1->write();
     $userId2 = self::$environ->createUser('user2', 'user2', 'user2');
     $user2 = new UserModel($userId2);
     $user2->addProject($project->id->asString());
     $user2->write();
     $userId3 = self::$environ->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();
     QuestionCommands::updateAnswer($projectId, $questionId, $answer1, $userId1);
     QuestionCommands::updateAnswer($projectId, $questionId, $answer2, $userId2);
     // the answer author does NOT get their answer marked as unread
     $unreadModel = new UnreadAnswerModel($userId1, $projectId, $questionId);
     $this->assertCount(1, $unreadModel->unreadItems());
     // the answer author does NOT get their answer marked as unread
     $unreadModel = new UnreadAnswerModel($userId2, $projectId, $questionId);
     $this->assertCount(1, $unreadModel->unreadItems());
     $unreadModel = new UnreadAnswerModel($userId3, $projectId, $questionId);
     $this->assertCount(2, $unreadModel->unreadItems());
     // user1 visits question page
     QuestionCommentDto::encode($projectId, $questionId, $userId1);
     $unreadModel = new UnreadAnswerModel($userId1, $projectId, $questionId);
     $this->assertCount(0, $unreadModel->unreadItems());
     $unreadModel = new UnreadAnswerModel($userId2, $projectId, $questionId);
     $this->assertCount(1, $unreadModel->unreadItems());
     $unreadModel = new UnreadAnswerModel($userId3, $projectId, $questionId);
     $this->assertCount(2, $unreadModel->unreadItems());
     // user2 visits question page
     QuestionCommentDto::encode($projectId, $questionId, $userId2);
     $unreadModel = new UnreadAnswerModel($userId1, $projectId, $questionId);
     $this->assertCount(0, $unreadModel->unreadItems());
     $unreadModel = new UnreadAnswerModel($userId2, $projectId, $questionId);
     $this->assertCount(0, $unreadModel->unreadItems());
     $unreadModel = new UnreadAnswerModel($userId3, $projectId, $questionId);
     $this->assertCount(2, $unreadModel->unreadItems());
     // user2 visits question page
     QuestionCommentDto::encode($projectId, $questionId, $userId3);
     $unreadModel = new UnreadAnswerModel($userId1, $projectId, $questionId);
     $this->assertCount(0, $unreadModel->unreadItems());
     $unreadModel = new UnreadAnswerModel($userId2, $projectId, $questionId);
     $this->assertCount(0, $unreadModel->unreadItems());
     $unreadModel = new UnreadAnswerModel($userId3, $projectId, $questionId);
     $this->assertCount(0, $unreadModel->unreadItems());
 }