public function testCRUD_Works()
 {
     $e = new MongoTestEnvironment();
     $e->clean();
     $textRef = MongoTestEnvironment::mockId();
     $project = $e->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE);
     // List
     $list = new QuestionListModel($project, $textRef);
     $list->read();
     $this->assertEqual(0, $list->count);
     // Create
     $question = new QuestionModel($project);
     $question->title = "SomeQuestion";
     $question->description = "SomeQuestion";
     $question->textRef->id = $textRef;
     $id = $question->write();
     $this->assertNotNull($id);
     $this->assertIsA($id, 'string');
     $this->assertEqual($id, $question->id->asString());
     // Read back
     $otherQuestion = new QuestionModel($project, $id);
     $this->assertEqual($id, $otherQuestion->id->asString());
     $this->assertEqual('SomeQuestion', $otherQuestion->title);
     $this->assertEqual($textRef, $otherQuestion->textRef->id);
     // Update
     $otherQuestion->description = 'OtherQuestion';
     $otherQuestion->write();
     // Read back
     $otherQuestion = new QuestionModel($project, $id);
     $this->assertEqual('OtherQuestion', $otherQuestion->description);
     // List
     $list->read();
     $this->assertEqual(1, $list->count);
     // Delete
     QuestionModel::remove($project->databaseName(), $id);
     // List
     $list->read();
     $this->assertEqual(0, $list->count);
 }
 public function run($mode = 'test')
 {
     $testMode = $mode == 'test';
     $message = "";
     $userlist = new UserListModel();
     $userlist->read();
     $userIds = array_map(function ($e) {
         return $e['id'];
     }, $userlist->entries);
     $projectlist = new ProjectListModel();
     $projectlist->read();
     $projectIds = array_map(function ($e) {
         return $e['id'];
     }, $projectlist->entries);
     $deadCommentUserRefs = 0;
     $deadAnswerUserRefs = 0;
     foreach ($projectIds as $projectId) {
         $project = new ProjectModel($projectId);
         $textlist = new TextListModel($project);
         $textlist->read();
         $textIds = array_map(function ($e) {
             return $e['id'];
         }, $textlist->entries);
         foreach ($textIds as $textId) {
             $questionlist = new QuestionListModel($project, $textId);
             $questionlist->read();
             $questionIds = array_map(function ($e) {
                 return $e['id'];
             }, $questionlist->entries);
             foreach ($questionIds as $questionId) {
                 $question = new QuestionModel($project, $questionId);
                 foreach ($question->answers as $answerId => $answer) {
                     foreach ($answer->comments as $commentId => $comment) {
                         $ref = $comment->userRef;
                         if (!empty($ref->id) && !in_array($ref->asString(), $userIds)) {
                             $comment->userRef->id = '';
                             if (!$testMode) {
                                 $question->writeComment($project->databaseName(), $questionId, $answerId, $comment);
                             }
                             $deadCommentUserRefs++;
                             $message .= "Removed dead user-comment ref {$ref} from question {$questionId}, answer {$answerId}, comment {$commentId}\n";
                         }
                     }
                     $ref = $answer->userRef;
                     if (!empty($ref->id) && !in_array($ref->asString(), $userIds)) {
                         $answer->userRef->id = '';
                         if (!$testMode) {
                             $question->writeAnswer($answer);
                         }
                         $deadAnswerUserRefs++;
                         $message .= "Removed dead user-answer ref {$ref} from question {$questionId}, answer {$answerId}\n";
                     }
                 }
             }
         }
     }
     if ($deadAnswerUserRefs > 0) {
         $message .= "\n\nRemoved dead user references from {$deadAnswerUserRefs} answers\n\n";
     } else {
         $message .= "\n\nNo dead user references were found in answers\n\n";
     }
     if ($deadCommentUserRefs > 0) {
         $message .= "\n\nRemoved dead user references from {$deadCommentUserRefs} comments\n\n";
     } else {
         $message .= "\n\nNo dead user references were found in comments\n\n";
     }
     return $message;
 }
예제 #3
0
 public function listQuestions()
 {
     $questionList = new QuestionListModel($this->_projectModel, $this->id->asString());
     $questionList->read();
     return $questionList;
 }