public function testUpdateAnswer_ExistingAnswer_CantUpdateTagsOrExportFlag()
 {
     $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();
     $answer = new AnswerModel();
     $answer->content = "the answer";
     $user1Id = $e->createUser("user1", "user1", "user1");
     $answer->userRef->id = $user1Id;
     $answer->tags[] = 'originalTag';
     $answer->isToBeExported = true;
     $answerId = $question->writeAnswer($answer);
     $answerArray = array("id" => $answerId, "content" => "updated answer", "tags" => array('updatedTag'), "isToBeExported" => false);
     QuestionCommands::updateAnswer($project->id->asString(), $questionId, $answerArray, $user1Id);
     $question->read($questionId);
     $newAnswer = $question->readAnswer($answerId);
     $this->assertEqual($newAnswer->content, "updated answer");
     $this->assertEqual(count($newAnswer->tags), 1);
     $this->assertEqual($newAnswer->tags[0], 'originalTag');
     $this->assertEqual($newAnswer->isToBeExported, true);
 }
Пример #2
0
 public function question_update_answer($questionId, $answer)
 {
     return QuestionCommands::updateAnswer($this->_projectId, $questionId, $answer, $this->_userId);
 }
 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);
 }
$otherProjectModel->allowInviteAFriend = $constants['otherProjectAllowInvites'];
$otherProjectModel->write();
ProjectCommands::updateUserRole($testProject, $managerUserId, ProjectRoles::MANAGER);
ProjectCommands::updateUserRole($testProject, $memberUserId, ProjectRoles::CONTRIBUTOR);
ProjectCommands::updateUserRole($testProject, $resetUserId, ProjectRoles::CONTRIBUTOR);
ProjectCommands::updateUserRole($otherProject, $adminUserId, ProjectRoles::MANAGER);
if ($site == 'scriptureforge') {
    $text1 = TextCommands::updateText($testProject, array('id' => '', 'title' => $constants['testText1Title'], 'content' => $constants['testText1Content']));
    $text2 = TextCommands::updateText($testProject, array('id' => '', 'title' => $constants['testText2Title'], 'content' => $constants['testText2Content']));
    $question1 = QuestionCommands::updateQuestion($testProject, array('id' => '', 'textRef' => $text1, 'title' => $constants['testText1Question1Title'], 'description' => $constants['testText1Question1Content']));
    $question2 = QuestionCommands::updateQuestion($testProject, array('id' => '', 'textRef' => $text1, 'title' => $constants['testText1Question2Title'], 'description' => $constants['testText1Question2Content']));
    $template1 = QuestionTemplateCommands::updateTemplate($testProject, array('id' => '', 'title' => 'first template', 'description' => 'not particularly interesting'));
    $template2 = QuestionTemplateCommands::updateTemplate($testProject, array('id' => '', 'title' => 'second template', 'description' => 'not entirely interesting'));
    $answer1 = QuestionCommands::updateAnswer($testProject, $question1, array('id' => '', 'content' => $constants['testText1Question1Answer']), $managerUserId);
    $answer1Id = array_keys($answer1)[0];
    $answer2 = QuestionCommands::updateAnswer($testProject, $question2, array('id' => '', 'content' => $constants['testText1Question2Answer']), $managerUserId);
    $answer2Id = array_keys($answer2)[0];
    $comment1 = QuestionCommands::updateComment($testProject, $question1, $answer1Id, array('id' => '', 'content' => $constants['testText1Question1Answer1Comment']), $managerUserId);
    $comment2 = QuestionCommands::updateComment($testProject, $question2, $answer2Id, array('id' => '', 'content' => $constants['testText1Question2Answer2Comment']), $managerUserId);
} elseif ($site == 'languageforge') {
    // Set up LanguageForge E2E test envrionment here
    $testProjectModel = new LexiconProjectModel($testProject);
    $testProjectModel->addInputSystem("th-fonipa", "tipa", "Thai");
    $testProjectModel->config->entry->fields[LexiconConfigObj::LEXEME]->inputSystems[] = 'th-fonipa';
    $testProjectId = $testProjectModel->write();
    // setup to mimic file upload
    $fileName = $constants['testEntry1']['senses'][0]['pictures'][0]['fileName'];
    $file = array();
    $file['name'] = $fileName;
    $_FILES['file'] = $file;
    // put a copy of the test file in tmp