Exemplo n.º 1
0
 /**
  * @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;
 }
 function testUploadAudio_mp3File_uploadAllowed()
 {
     $environ = new MongoTestEnvironment();
     $environ->clean();
     $project = $environ->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE);
     $projectId = $project->id->asString();
     $text = new TextModel($project);
     $textId = $text->write();
     $fileName = 'TestAudio.mp3';
     $tmpFilePath = $environ->uploadTextAudioFile(TestPath . "common/{$fileName}", $fileName, $textId);
     $response = SfchecksUploadCommands::uploadFile($projectId, 'audio', $tmpFilePath);
     $text->read($textId);
     $assetsFolderPath = $project->getAssetsFolderPath();
     $filePath = SfchecksUploadCommands::mediaFilePath($assetsFolderPath, $textId, $fileName);
     $projectSlug = $project->databaseName();
     $this->assertTrue($response->result, 'Import should succeed');
     $this->assertPattern("/sfchecks\\/{$projectSlug}/", $response->data->path, 'Imported audio file path should be in the right location');
     $this->assertEqual($fileName, $response->data->fileName, 'Imported audio fileName should have the original fileName');
     $this->assertEqual($fileName, $text->audioFileName, 'Imported audio fileName should be stored in the Text');
     $this->assertTrue(file_exists($filePath), 'Imported audio file should exist');
     $environ->cleanupTestFiles($assetsFolderPath);
 }
 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);
 }