/**
  * @param string $projectId
  * @param JSON $object
  * @return ID of text updated/added
  */
 public static function updateText($projectId, $object)
 {
     $projectModel = new \Api\Model\ProjectModel($projectId);
     $textModel = new \Api\Model\TextModel($projectModel);
     $isNewText = $object['id'] == '';
     if (!$isNewText) {
         $textModel->read($object['id']);
     }
     JsonDecoder::decode($textModel, $object);
     TextCommands::makeValidRange($object);
     if (TextCommands::hasRange($object)) {
         $usxTrimHelper = new UsxTrimHelper($textModel->content, $object['startCh'] || 0, $object['startVs'] || 0, $object['endCh'] || 0, $object['endVs'] || 0);
         $textModel->content = $usxTrimHelper->trimUsx();
     }
     $textId = $textModel->write();
     if ($isNewText) {
         ActivityCommands::addText($projectModel, $textId, $textModel);
     }
     return $textId;
 }
 public function testPublishTexts_2ArchivedTexts_1Published()
 {
     $e = new MongoTestEnvironment();
     $e->clean();
     $project = $e->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE);
     $text1 = new TextModel($project);
     $text1->title = "Some Title";
     $text1->isArchived = true;
     $text1->write();
     $text2 = new TextModel($project);
     $text2->title = "Another Title";
     $text2->isArchived = true;
     $text2->write();
     $this->assertEqual($text1->isArchived, true);
     $this->assertEqual($text2->isArchived, true);
     $count = TextCommands::publishTexts($project->id->asString(), array($text1->id->asString()));
     $text1->read($text1->id->asString());
     $text2->read($text2->id->asString());
     $this->assertEqual($count, 1);
     $this->assertEqual($text1->isArchived, false);
     $this->assertEqual($text2->isArchived, true);
 }
$testProjectModel = new ProjectModel($testProject);
$testProjectModel->projectCode = $constants['testProjectCode'];
$testProjectModel->allowInviteAFriend = $constants['testProjectAllowInvites'];
$testProjectModel->write();
$otherProject = ProjectCommands::createProject($constants['otherProjectName'], $constants['otherProjectCode'], $projectType, $managerUserId, $website);
$otherProjectModel = new ProjectModel($otherProject);
$otherProjectModel->projectCode = $constants['otherProjectCode'];
$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';
Example #4
0
 public function text_publish($textIds)
 {
     return TextCommands::publishTexts($this->_projectId, $textIds);
 }
 public function testTextCRUD_CRUDOK()
 {
     $e = new ApiCrudTestEnvironment();
     $projectId = $e->makeProject();
     $userId = $e->getProjectMember($projectId, 'user1');
     // Initial List
     $result = $e->json(ProjectPageDto::encode($projectId, $userId));
     $count = count($result['texts']);
     // Create
     $model = array('id' => '', 'title' => 'SomeText');
     $id = TextCommands::updateText($projectId, $model);
     $this->assertNotNull($id);
     $this->assertEqual(24, strlen($id));
     // Read
     $result = $e->json(TextCommands::readText($projectId, $id));
     $this->assertNotNull($result['id']);
     $this->assertEqual('SomeText', $result['title']);
     // Update
     $result['title'] = 'OtherText';
     $id = TextCommands::updateText($projectId, $result);
     $this->assertNotNull($id);
     $this->assertEqual($result['id'], $id);
     // Read back
     $result = $e->json(TextCommands::readText($projectId, $id));
     $this->assertEqual('OtherText', $result['title']);
     // List
     $result = $e->json(ProjectPageDto::encode($projectId, $userId));
     $this->assertEqual($count + 1, count($result['texts']));
     // Delete
     $result = TextCommands::deleteTexts($projectId, array($id));
     $this->assertTrue($result);
     // List to confirm delete
     $result = $e->json(ProjectPageDto::encode($projectId, $userId));
     $this->assertEqual($count, count($result['texts']));
     // Clean up after ourselves
     ProjectCommands::deleteProjects(array($projectId));
 }