public function testInitializeNewProject_SendReceiveProjectAndExistingTargetFile_SourceFileMovedAndSymlinksCreated() { $project = self::$environ->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); $project->sendReceiveProjectIdentifier = 'sr_id'; $project->sendReceiveProject = new SendReceiveProjectModel('sr_name', '', 'manager'); $project->write(); $this->assertTrue($project->hasSendReceive()); $projectWorkPath = $project->getSendReceiveWorkFolder(); $srImagePath = $projectWorkPath . DIRECTORY_SEPARATOR . 'LinkedFiles' . DIRECTORY_SEPARATOR . 'Pictures'; FileUtilities::createAllFolders($srImagePath); $srTestImageFilePath = $srImagePath . DIRECTORY_SEPARATOR . 'existingTargetImage.jpg'; touch($srTestImageFilePath); $this->assertTrue(file_exists($srTestImageFilePath)); $assetImagePath = $project->getImageFolderPath(); $filenameToMove = 'existingSourceImage.jpg'; $filePathToMove = $assetImagePath . DIRECTORY_SEPARATOR . $filenameToMove; touch($filePathToMove); $this->assertTrue(file_exists($filePathToMove)); $project->initializeNewProject(); $this->assertTrue(is_link($assetImagePath)); $this->assertTrue(file_exists($srTestImageFilePath)); $this->assertTrue(file_exists($filePathToMove)); $this->assertTrue(file_exists($srImagePath . DIRECTORY_SEPARATOR . $filenameToMove)); $assetAudioPath = $project->getAudioFolderPath(); $this->assertTrue(is_link($assetAudioPath)); $project->initializeNewProject(); $this->assertTrue(is_link($assetImagePath)); $this->assertTrue(file_exists($srTestImageFilePath)); $this->assertTrue(file_exists($filePathToMove)); $this->assertTrue(file_exists($srImagePath . DIRECTORY_SEPARATOR . $filenameToMove)); $this->assertTrue(is_link($assetAudioPath)); FileUtilities::removeFolderAndAllContents($project->getAssetsFolderPath()); FileUtilities::removeFolderAndAllContents($projectWorkPath); }
/** * Cleanup associated project files */ protected function cleanup() { parent::cleanup(); if (!is_null($this->projectCode)) { $projectFilename = strtolower($this->projectCode); $stateFilename = strtolower($this->projectCode) . '.state'; $lfmergePaths = SendReceiveCommands::getLFMergePaths(); foreach ($lfmergePaths as $key => $path) { if (!is_null($path)) { if ($key == "workPath") { FileUtilities::removeFolderAndAllContents($lfmergePaths->workPath . DIRECTORY_SEPARATOR . $projectFilename); } if (file_exists($path . DIRECTORY_SEPARATOR . $projectFilename)) { unlink($path . DIRECTORY_SEPARATOR . $projectFilename); } if (file_exists($path . DIRECTORY_SEPARATOR . $stateFilename)) { unlink($path . DIRECTORY_SEPARATOR . $stateFilename); } } } } }
/** * Cleanup test files and folders * * @param string $assetsFolderPath */ public function cleanupTestFiles($assetsFolderPath) { $this->cleanupTestUploadFiles(); FileUtilities::removeFolderAndAllContents($assetsFolderPath); }
unlink($filePath); } } FileUtilities::removeFolderAndAllContents($otherAssetsFolderPath); } // cleanup LfMerge 'syncqueue', 'webwork' and 'state' folders if ($testProject->appName == LexProjectModel::LEXICON_APP) { $syncQueuePath = SendReceiveCommands::getLFMergePaths()->syncQueuePath; foreach (glob("{$syncQueuePath}/*") as $file) { if (is_file($file)) { unlink($file); } } $workPath = SendReceiveCommands::getLFMergePaths()->workPath; FileUtilities::removeFolderAndAllContents($workPath . DIRECTORY_SEPARATOR . $constants['srProjectCode']); FileUtilities::removeFolderAndAllContents($workPath . DIRECTORY_SEPARATOR . 'mock-id4'); $stateFilePath = SendReceiveCommands::getLFMergePaths()->statePath . DIRECTORY_SEPARATOR . 'mock-id4.state'; if (is_file($stateFilePath)) { unlink($stateFilePath); } } // cleanup mocked uploaded zip import (jpg file) $tmpFilePath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $constants['testMockJpgImportFile']['name']; @unlink($tmpFilePath); // cleanup mocked uploaded zip import (zip file) $tmpFilePath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $constants['testMockZipImportFile']['name']; @unlink($tmpFilePath); // cleanup mock uploaded audio (png file) $tmpFilePath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $constants['testMockPngUploadFile']['name']; @unlink($tmpFilePath); // cleanup mock uploaded audio (mp3 file)
public function testCreateProject_NewSRProject_SRProjectWithLinks() { self::$environ = new LexiconMongoTestEnvironment(); self::$environ->clean(); $user1Id = self::$environ->createUser("user1name", "User1 Name", "*****@*****.**"); $user1 = new UserModel($user1Id); $srProject = array('identifier' => 'srIdentifier', 'name' => 'srName', 'repository' => 'http://public.languagedepot.org', 'role' => 'manager'); $projectId = ProjectCommands::createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE, LexProjectModel::LEXICON_APP, $user1->id->asString(), self::$environ->website, $srProject); $project = new LexProjectModel($projectId); $assetImagePath = $project->getImageFolderPath(); $assetAudioPath = $project->getAudioFolderPath(); $this->assertTrue($project->hasSendReceive()); $this->assertTrue(is_link($assetImagePath)); $this->assertTrue(is_link($assetAudioPath)); $projectWorkPath = $project->getSendReceiveWorkFolder(); FileUtilities::removeFolderAndAllContents($project->getAssetsFolderPath()); FileUtilities::removeFolderAndAllContents($projectWorkPath); }
public function testNotificationSendRequest_HasSendReceiveAndHasUncommittedEntry_Notified() { self::$environ->clean(); $project = self::$environ->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); $project->sendReceiveProjectIdentifier = 'sr_id'; $project->sendReceiveProject = new SendReceiveProjectModel('sr_name', '', 'manager'); $project->write(); $tmpTestPath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'notifiedTest'; $lfmergePaths = SendReceiveCommands::getLFMergePaths(true, $tmpTestPath); $projectStatePath = $lfmergePaths->statePath . DIRECTORY_SEPARATOR . strtolower($project->projectCode) . '.state'; FileUtilities::createAllFolders($tmpTestPath); FileUtilities::createAllFolders($lfmergePaths->sendQueuePath); FileUtilities::createAllFolders($lfmergePaths->statePath); file_put_contents($projectStatePath, '{"state": "SENDING", "uncommittedEditCount": 1}'); $mockPidFilePath = sys_get_temp_dir() . '/mockLFMerge.pid'; $mockCommand = 'php ' . __DIR__ . '/mockLFMergeExe.php'; $isNotified = SendReceiveCommands::notificationSendRequest($project->projectCode, $lfmergePaths->statePath, $lfmergePaths->sendQueuePath, $mockPidFilePath, $mockCommand); $queueFileNames = scandir($lfmergePaths->sendQueuePath); $this->assertTrue($isNotified); $this->assertCount(3, $queueFileNames); FileUtilities::removeFolderAndAllContents($tmpTestPath); }
<?php require_once 'e2eTestConfig.php'; use Api\Model\Languageforge\Lexicon\LexiconProjectModel; use Api\Model\Languageforge\Lexicon\Command\LexUploadCommands; use Api\Model\ProjectModel; use Palaso\Utilities\FileUtilities; $constants = json_decode(file_get_contents(TestPath . '/testConstants.json'), true); // cleanup test assets folder $project = new ProjectModel(); $project->readByProperties(array('projectCode' => $constants['testProjectCode'])); $testProject = $project->getById($project->id->asString()); $assetsFolderPath = $testProject->getAssetsFolderPath(); FileUtilities::removeFolderAndAllContents($assetsFolderPath); // cleanup mocked uploaded zip import (jpg file) $tmpFilePath = sys_get_temp_dir() . '/' . $constants['testMockJpgImportFile']['name']; @unlink($tmpFilePath); // cleanup mocked uploaded zip import (zip file) $tmpFilePath = sys_get_temp_dir() . '/' . $constants['testMockZipImportFile']['name']; @unlink($tmpFilePath);
/** * Cleanup assets folder upon project deletion */ protected function cleanup() { FileUtilities::removeFolderAndAllContents($this->getAssetsFolderPath()); }