public function testDeleteQuestions_NoThrow()
 {
     $e = new MongoTestEnvironment();
     $e->clean();
     $project = $e->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE);
     $projectId = $project->id->asString();
     $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;
     $question->write();
     $questionId = $question->id->asString();
     QuestionCommands::deleteQuestions($projectId, array($questionId));
 }
Ejemplo n.º 2
0
 public function testQuestionCRUD_CRUDOK()
 {
     $e = new ApiCrudTestEnvironment();
     // create project
     $projectId = $e->makeProject();
     // create an user and add to the project
     $userId = $e->getProjectMember($projectId, 'user1');
     // create text
     $textId = $e->makeText($projectId, "test text 1");
     // List
     $dto = $e->json(QuestionListDto::encode($projectId, $textId, $userId));
     $this->assertEqual($dto['count'], 0);
     // Create
     $model = array('id' => '', 'title' => 'SomeQuestion', 'description' => 'SomeDescription', 'textRef' => $textId);
     $questionId = QuestionCommands::updateQuestion($projectId, $model);
     $this->assertNotNull($questionId);
     $this->assertEqual(24, strlen($questionId));
     // Read
     $result = $e->json(QuestionCommands::readQuestion($projectId, $questionId));
     $this->assertNotNull($result['id']);
     $this->assertEqual('SomeQuestion', $result['title']);
     // Update
     $result['title'] = 'OtherQuestion';
     $id = QuestionCommands::updateQuestion($projectId, $result);
     $this->assertNotNull($id);
     $this->assertEqual($result['id'], $id);
     // Read back
     $result = $e->json(QuestionCommands::readQuestion($projectId, $questionId));
     $this->assertEqual('OtherQuestion', $result['title']);
     // List
     $dto = $e->json(QuestionListDto::encode($projectId, $textId, $userId));
     $this->assertEqual(1, $dto['count']);
     // Delete
     $result = QuestionCommands::deleteQuestions($projectId, array($questionId));
     $this->assertTrue($result);
     // List to confirm delete
     $dto = $e->json(QuestionListDto::encode($projectId, $textId, $userId));
     $this->assertEqual(0, $dto['count']);
     // Clean up after ourselves
     ProjectCommands::deleteProjects(array($projectId));
 }