/**
  * @expectedException Api\Library\Shared\Palaso\Exception\ResourceNotAvailableException
  */
 public function testEncode_ArchivedText_ManagerCanViewContributorCannot()
 {
     $project = self::$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 = self::$environ->createUser('jcarter', 'John Carter', '*****@*****.**');
     $contributorId = self::$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->assertEquals('Chapter 3', $dto['text']['title']);
     // Contributor cannot view archived Text, throw Exception
     self::$environ->inhibitErrorDisplay();
     QuestionListDto::encode($projectId, $textId, $contributorId);
     // nothing runs in the current test function after an exception. IJH 2014-11
 }
 public function question_list_dto($textId)
 {
     return QuestionListDto::encode($this->projectId, $textId, $this->userId);
 }
 public function testQuestionCRUD_CRUDOK()
 {
     // create project
     $projectId = self::$environ->makeProject();
     $project = new ProjectModel($projectId);
     // create an user and add to the project
     $userId = self::$environ->getProjectMember($projectId, 'user1');
     // create text
     $textId = self::$environ->makeText($projectId, "test text 1");
     // List
     $dto = self::$environ->fixJson(QuestionListDto::encode($projectId, $textId, $userId));
     $this->assertEquals(0, $dto['count']);
     // Create
     $model = array('id' => '', 'title' => 'SomeQuestion', 'description' => 'SomeDescription', 'textRef' => $textId);
     $questionId = QuestionCommands::updateQuestion($projectId, $model);
     $this->assertNotNull($questionId);
     $this->assertEquals(24, strlen($questionId));
     // Read
     $result = self::$environ->fixJson(QuestionCommands::readQuestion($projectId, $questionId));
     $this->assertNotNull($result['id']);
     $this->assertEquals('SomeQuestion', $result['title']);
     // Update
     $result['title'] = 'OtherQuestion';
     $id = QuestionCommands::updateQuestion($projectId, $result);
     $this->assertNotNull($id);
     $this->assertEquals($result['id'], $id);
     // Read back
     $result = self::$environ->fixJson(QuestionCommands::readQuestion($projectId, $questionId));
     $this->assertEquals('OtherQuestion', $result['title']);
     // List
     $dto = self::$environ->fixJson(QuestionListDto::encode($projectId, $textId, $userId));
     $this->assertEquals(1, $dto['count']);
     // Delete
     $result = QuestionCommands::deleteQuestions($projectId, array($questionId));
     $this->assertTrue($result > 0);
     // List to confirm delete
     $dto = self::$environ->fixJson(QuestionListDto::encode($projectId, $textId, $userId));
     $this->assertEquals(0, $dto['count']);
     // Clean up after ourselves
     ProjectCommands::deleteProjects(array($projectId), $project->ownerRef->asString());
 }