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));
 }
Exemple #2
0
 public function question_list_dto($textId)
 {
     return \Api\Model\Scriptureforge\Dto\QuestionListDto::encode($this->_projectId, $textId, $this->_userId);
 }
 public function testEncode_ArchivedText_ManagerCanViewContributorCannot()
 {
     $project = $this->environ->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE);
     $projectId = $project->id->asString();
     // archived Text
     $text = new TextModel($project);
     $text->title = "Chapter 3";
     $text->isArchived = true;
     $textId = $text->write();
     // Answers are tied to specific users, so let's create some sample users
     $managerId = $this->environ->createUser("jcarter", "John Carter", "*****@*****.**");
     $contributorId = $this->environ->createUser("dthoris", "Dejah Thoris", "*****@*****.**");
     $project->addUser($managerId, ProjectRoles::MANAGER);
     $project->addUser($contributorId, ProjectRoles::CONTRIBUTOR);
     $project->write();
     $dto = QuestionListDto::encode($projectId, $textId, $managerId);
     // Manager can view archived Text
     $this->assertEqual($dto['text']['title'], "Chapter 3");
     // Contributor cannot view archived Text, throw Exception
     $this->environ->inhibitErrorDisplay();
     $this->expectException();
     $dto = QuestionListDto::encode($projectId, $textId, $contributorId);
     // nothing runs in the current test function after an exception. IJH 2014-11
 }