public function testPublishTexts_2ArchivedTexts_1Published() { $project = self::$environ->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->assertTrue($text1->isArchived); $this->assertTrue($text2->isArchived); $count = TextCommands::publishTexts($project->id->asString(), array($text1->id->asString())); $text1->read($text1->id->asString()); $text2->read($text2->id->asString()); $this->assertEquals(1, $count); $this->assertNotTrue($text1->isArchived); $this->assertTrue($text2->isArchived); }
function testUploadAudio_mp3File_uploadAllowed() { $project = self::$environ->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); $projectId = $project->id->asString(); $text = new TextModel($project); $textId = $text->write(); $fileName = 'TestAudio.mp3'; $tmpFilePath = self::$environ->uploadTextAudioFile(TestPhpPath . "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->assertRegExp("/sfchecks\\/{$projectSlug}/", $response->data->path, 'Imported audio file path should be in the right location'); $this->assertEquals($fileName, $response->data->fileName, 'Imported audio fileName should have the original fileName'); $this->assertEquals($fileName, $text->audioFileName, 'Imported audio fileName should be stored in the Text'); $this->assertTrue(file_exists($filePath), 'Imported audio file should exist'); self::$environ->cleanupTestFiles($assetsFolderPath); }
/** * @param string $projectId * @param array $object (json encoded) * @return string Id of text updated/added */ public static function updateText($projectId, $object) { $projectModel = new ProjectModel($projectId); ProjectCommands::checkIfArchivedAndThrow($projectModel); $textModel = new 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; }