/** * @test * @group library */ public function copyMediaShouldKeepSourceMediaIds() { $sourceWebsiteId = 'SITE-mc10e89c-2rtf-46cd-a651-fc42dc7812so-SITE'; $newWebsiteId = 'SITE-mc1fe89c-2rtf-46cd-a651-fc42dc7f75de-SITE'; $this->service->copyMediaToNewWebsite($sourceWebsiteId, $newWebsiteId); $sourceMedia = $this->service->getByWebsiteIdAndFilter($sourceWebsiteId); $sourceMediaIds = array(); $assertionMessage = 'No expected source media available'; $this->assertTrue(count($sourceMedia) > 0, $assertionMessage); foreach ($sourceMedia as $media) { $sourceMediaIds[] = $media->getId(); } $copyMedia = $this->service->getByWebsiteIdAndFilter($newWebsiteId); $copyMediaIds = array(); $assertionMessage = 'No expected copy media available'; $this->assertTrue(count($copyMedia) > 0, $assertionMessage); foreach ($copyMedia as $media) { $copyMediaIds[] = $media->getId(); } sort($sourceMediaIds); sort($copyMediaIds); $assertionMessage = 'Media ids of source and copied media are not identical'; $this->assertSame($sourceMediaIds, $copyMediaIds, $assertionMessage); $config = Registry::getConfig(); $copiedMediaDirectory = $config->media->files->directory . DIRECTORY_SEPARATOR . $newWebsiteId; DirectoryHelper::removeRecursiv($copiedMediaDirectory, $config->media->files->directory); }
protected function tearDown() { $creatorTempDirectory = Registry::getConfig()->creator->directory; $workingDirectory = $this->getWorkingDirectory(); DirectoryHelper::removeRecursiv($workingDirectory, $creatorTempDirectory); parent::tearDown(); }
/** * @test * @group integration */ public function cancelShouldRemoveImportFileFormFilesystemAndLatchStorageAsExpected() { DirectoryHelper::clearLatchDirectory(); $fakeImportId = str_repeat('e', LatchBusiness::LATCH_IMPORT_ID_LENGTH); $fakeImportId1 = str_repeat('f', LatchBusiness::LATCH_IMPORT_ID_LENGTH); $fakeImportId2 = str_repeat('g', LatchBusiness::LATCH_IMPORT_ID_LENGTH); $fakeLatches[$fakeImportId] = 'fake_import_4.zip'; $fakeLatches[$fakeImportId1] = 'fake_import_5.zip'; $fakeLatches[$fakeImportId2] = 'fake_import_6.zip'; $this->buildFakeLatchStorage($fakeLatches); $request = sprintf('/import/cancel/params/{"importid":"%s"}', $fakeImportId1); $this->dispatch($request); $response = new Response($this->getResponseBody()); $this->assertInternalType('string', $this->getResponseBody()); $this->assertNotNull($this->getResponseBody()); $this->assertTrue($response->getSuccess()); $config = Registry::getConfig(); $importLatchDirectory = $config->import->latch->directory; $this->assertFileExists($importLatchDirectory); $fakeImportFile = $importLatchDirectory . DIRECTORY_SEPARATOR . $fakeLatches[$fakeImportId1]; $fakeImportLatchStorageFile = $importLatchDirectory . DIRECTORY_SEPARATOR . LatchBusiness::IMPORT_LATCH_STORAGE_FILE; $this->assertFileNotExists($fakeImportFile); $this->assertFileExists($fakeImportLatchStorageFile); $fakeImportLatchStorageFileContent = json_decode(file_get_contents($fakeImportLatchStorageFile), true); $this->assertNotContains($fakeImportId1, array_keys($fakeImportLatchStorageFileContent)); }
protected function removeCreatedWebsite($websiteId, $creatorType = null) { $config = Registry::getConfig(); if (empty($creatorType)) { $creatorType = $config->creator->defaultCreator; } $creatorDirectory = $config->creator->directory; $websiteCreatorDir = $creatorDirectory . DIRECTORY_SEPARATOR . $websiteId . '-' . $creatorType; DirectoryHelper::removeRecursiv($websiteCreatorDir, $creatorDirectory); }
/** * @test * @group library */ public function indexWebsiteShouldCreateIndex() { $websiteId = 'SITE-20b2394c-b41c-490f-acec-70bb15968c52-SITE'; $this->service->indexWebsite($websiteId); $indexDirectory = Registry::getConfig()->get('indexing')->basedir; $createdIndexDirectory = $indexDirectory . DIRECTORY_SEPARATOR . $websiteId; $this->assertFileExists($createdIndexDirectory); $this->assertTrue(is_dir($createdIndexDirectory)); $this->assertGreaterThan(1, $this->getFilesCountOfWebsiteIndex($websiteId)); DirectoryHelper::removeRecursiv($createdIndexDirectory, $indexDirectory); }
/** * @param string $websiteId * @return boolean */ protected function removeImportMediaDirectoryAndFiles($websiteId) { $config = Registry::getConfig(); $testFilesDirectory = $config->test->files->directory; $testMediaDirectory = $testFilesDirectory . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . $websiteId; if (is_dir($testFilesDirectory) && is_dir($testMediaDirectory)) { DirectoryHelper::removeRecursiv($testMediaDirectory, $testFilesDirectory); return true; } return false; }
protected function tearDown() { if ($this->fakedImportFileToDelete !== null) { DirectoryHelper::removeFile($this->fakedImportFileToDelete); } if ($this->importUnzipDirectoryToDelete !== null) { $config = Registry::getConfig(); $testImportDirectory = $config->import->directory; DirectoryHelper::removeRecursiv($this->importUnzipDirectoryToDelete, $testImportDirectory); } parent::tearDown(); }
public function tearDown() { // remove test files foreach ($this->filesToDeleteAtTearDown as $filePath) { DirectoryHelper::removeFile($filePath); } // remove test directories foreach ($this->directoriesToDeleteAtTearDown as $directory) { DirectoryHelper::removeRecursiv($directory); } parent::tearDown(); }
/** * @test * @group library */ public function copyShouldCopyAsExpected() { $sourceWebsiteId = 'SITE-mf12copy-20da-4ea8-a477-4ee793source-SITE'; $destinationWebsiteId = 'SITE-mf12copy-20da-4ea8-a477-4ee7j3f5dest-SITE'; $this->service->copyMediaFileToNewWebsite($sourceWebsiteId, $destinationWebsiteId); $expectedDestinationDirectory = $this->testMediaFilesDirectory . DIRECTORY_SEPARATOR . $destinationWebsiteId; $assertionMessage = sprintf("Destination directory '%s' has not been created", $expectedDestinationDirectory); $this->assertTrue(is_dir($expectedDestinationDirectory), $assertionMessage); $testFilesDirectory = $this->config->test->files->directory; $expectedCopyTreeFile = $testFilesDirectory . DIRECTORY_SEPARATOR . 'expected_media_copy.tree'; $expectedCopyTree = file_get_contents($expectedCopyTreeFile); $this->assertSame($expectedCopyTree, DirectoryHelper::getRecursiveAsJson($expectedDestinationDirectory, true), "Tree mismatch between copied directory tree and expected directory tree"); DirectoryHelper::removeRecursiv($expectedDestinationDirectory, $this->testMediaFilesDirectory); }
public static function resetDataDirectory() { // create item data structure $itemDataDir = Registry::getConfig()->item->data->directory; $itemDataRestoreFilepath = Registry::getConfig()->test->item->data->restore->file; if (!file_exists($itemDataRestoreFilepath)) { throw new \Exception('data restore file not found: ' . $itemDataRestoreFilepath); } DirectoryHelper::removeRecursiv($itemDataDir); mkdir($itemDataDir, 0777, true); $cmd = sprintf('tar xf %s -C %s', $itemDataRestoreFilepath, $itemDataDir); list($error, $output, $exitCode) = SystemHelper::user_proc_exec($cmd); if ($exitCode != 0) { die("couldn't restore item data (" . $itemDataRestoreFilepath . ") into folder " . $itemDataDir . " (exit code: " . $exitCode . ")"); } }
/** * @test * @group integration */ public function importAgainstNonExistingAlbumsCreatesThemImportsIntoThem() { DirectoryHelper::clearLatchDirectory(); $websiteId = 'SITE-im12maec-imal-4ea8-a477-t4e79e8e62m1-SITE'; $this->dispatch(sprintf('/album/getall/params/{"websiteid":"%s"}', $websiteId)); $response = new Response($this->getResponseBody()); $responseData = $response->getData(); $this->assertTrue(count($responseData->albums) === 0); $media = array('MDB-exp0d0ec-cb0f-4961-imal-765d4aa581n0-MDB', 'MDB-exp0d0ec-cb0f-4961-imal-765d4aa581n1-MDB', 'MDB-exp0d0ec-cb0f-4961-imal-765d4aa581n2-MDB'); $templates = $templateSnippet = $modules = array(); $config = Registry::getConfig(); $importLatchFilesDirectory = $config->import->latch->files->directory; $importFileToLatch = $importLatchFilesDirectory . DIRECTORY_SEPARATOR . 'import_templatesnippet_conflict_media_non_existing_album.zip'; $this->assertFileExists($importFileToLatch); $latchBusiness = new LatchBusiness('Latch'); $importId = $latchBusiness->latchImportFile($websiteId, $importFileToLatch); $data = array('templates' => $templates, 'templatesnippets' => $templateSnippet, 'modules' => $modules, 'media' => $media, 'importId' => $importId); $request = sprintf('/import/overwrite/params/%s', json_encode($data)); $this->dispatch($request); $response = $this->getValidatedSuccessResponse(); $expectedAlbumIdsAndMediaCount = array('ALBUM-ex0wcf0d-acc4-4fdb-imal-72ebb08780ne-ALBUM' => 2, 'ALBUM-ex0wcf0d-acc4-4fdb-imal-72ebb08781ne-ALBUM' => 1); $expectedAlbumIds = array_keys($expectedAlbumIdsAndMediaCount); $this->dispatch(sprintf('/album/getall/params/{"websiteid":"%s"}', $websiteId)); $response = new Response($this->getResponseBody()); $responseData = $response->getData(); $this->assertTrue(count($responseData->albums) === count($expectedAlbumIds)); $createdAlbumIds = array(); array_filter($responseData->albums, function ($album) use(&$createdAlbumIds) { return $createdAlbumIds[] = $album->id; }); sort($expectedAlbumIds); sort($createdAlbumIds); $this->assertEquals($expectedAlbumIds, $createdAlbumIds); $this->dispatch(sprintf('/media/getall/params/{"websiteid":"%s","albumid":"%s"}', $websiteId, $createdAlbumIds[0])); $response = new Response($this->getResponseBody()); $responseData = $response->getData(); $this->assertNotEmpty($responseData->media); $this->assertEquals($expectedAlbumIdsAndMediaCount[$createdAlbumIds[0]], $responseData->total); $this->dispatch(sprintf('/media/getall/params/{"websiteid":"%s","albumid":"%s"}', $websiteId, $createdAlbumIds[1])); $response = new Response($this->getResponseBody()); $responseData = $response->getData(); $this->assertNotEmpty($responseData->media); $this->assertEquals($expectedAlbumIdsAndMediaCount[$createdAlbumIds[1]], $responseData->total); $this->removeImportMediaDirectoryAndFiles($websiteId); }
/** * @test * @group library */ public function test_buildTheme_removedThemeFilesIfNoValuesGiven() { // ARRANGE $cliBusiness = $this->getCliBusiness(); // ACT // 1. check if theme folder is empty $themeFolderEmpty = DirectoryHelper::getRecursive($this->getTestTargetPath()); $this->assertArrayNotHasKey('children', $themeFolderEmpty); // 2. create theme files $cliBusiness->buildTheme(array('color' => '#091929', 'logo' => 'http://localhost/this/is/the/url/of/the/logo.svg')); $themeFolder = DirectoryHelper::getRecursive($this->getTestTargetPath()); $this->assertArrayHasKey('children', $themeFolder); $this->assertGreaterThan(0, $themeFolder['children']); // 3. reset theme $cliBusiness->buildTheme(array()); $resetThemeFolder = DirectoryHelper::getRecursive($this->getTestTargetPath()); // ASSERT $this->assertArrayNotHasKey('children', $resetThemeFolder); }
/** * @test * @group integration */ public function exportModulesShouldExportAsExpectedWithSpecifiedName() { $config = Registry::getConfig(); $exportDirectoryName = 'test_export_0_modules'; $exportBaseDirectory = $config->export->directory; $exportDirectory = $exportBaseDirectory . DIRECTORY_SEPARATOR . md5($exportDirectoryName); $exportZipFile = $exportBaseDirectory . DIRECTORY_SEPARATOR . md5($exportDirectoryName) . DIRECTORY_SEPARATOR . md5($exportDirectoryName) . '.' . self::EXPORT_FILE_EXTENSION; $websiteId = 'SITE-ae6e702f-10ac-4e1e-exmo-307e4b8765db-SITE'; $moduleIds = array('"MODUL-0rap5eb8-0df3-47e9-exmo-90ae9d96d3c0-MODUL"', '"MODUL-0rap5eb8-0df3-47e9-exmo-90ae9d96d3c1-MODUL"', '"MODUL-0rap5eb8-0df3-47e9-exmo-90ae9d96d3c2-MODUL"', '"MODUL-0rap5eb8-0df3-47e9-exmo-90ae9d96d3c3-MODUL"'); $requestUri = sprintf('export/modules/params/{"websiteid":"%s","ids":[%s],"name":"%s"}', $websiteId, implode(',', $moduleIds), $exportDirectoryName); $this->dispatch($requestUri); $response = $this->getValidatedSuccessResponse(); $responseData = $response->getData(); $this->assertObjectHasAttribute('url', $responseData); $nameDataPart = sprintf('{"name":"%s"}', $exportDirectoryName); $this->assertStringEndsWith($nameDataPart, $responseData->url); $this->assertTrue(is_dir($exportDirectory)); $this->assertFileExists($exportZipFile); $unzipCommand = sprintf("unzip %s -d %s", $exportZipFile, $exportDirectory); if (strstr($unzipCommand, $exportBaseDirectory)) { SystemHelper::user_proc_exec($unzipCommand); DirectoryHelper::removeRecursiv($exportZipFile, $exportBaseDirectory); } $testFilesDirectory = $config->test->files->directory; $expectedExportTreeFile = $testFilesDirectory . DIRECTORY_SEPARATOR . 'trees' . DIRECTORY_SEPARATOR . 'export' . DIRECTORY_SEPARATOR . 'expected_modules_export.tree'; $expectedExportTree = file_get_contents($expectedExportTreeFile); $exportDirectoryTree = DirectoryHelper::getRecursiveAsJson($exportDirectory, true); $this->assertSame($expectedExportTree, $exportDirectoryTree, "Tree mismatch between export directory tree and expected directory tree"); DirectoryHelper::removeRecursiv($exportDirectory, $exportBaseDirectory); }
/** * @test * @group integration */ public function uploadShouldOverwriteExistingFileAsExpected() { $config = Registry::getConfig(); $testFilesDirectory = $config->test->files->directory; $testMediaFilesDirectory = $config->media->files->directory; $websiteId = 'SITE-ra10e8ul-11af-46cd-a651-fc42dc78fe50-SITE'; $albumId = 'ALBUM-existing-0000-0000-0000-album0000001-ALBUM'; $uploadFileName = 'test_1.jpg'; $uploadFile = FS::joinPath($testMediaFilesDirectory, $uploadFileName); $newMediaId = $this->assertCreateNewMediaItem($websiteId, $albumId, FS::joinPath($testFilesDirectory, 'backbone.js')); $requestParrams = array('websiteid' => $websiteId, 'id' => $newMediaId, 'name' => $uploadFileName, 'fileinputname' => 'upload_overwrite'); $this->assertFakeUpload($requestParrams['fileinputname'], $uploadFile); $this->dispatchWithParams('/media/upload', $requestParrams); $this->getValidatedSuccessResponse(); $this->dispatchWithParams('/media/getbyid', array('websiteid' => $websiteId, 'id' => $newMediaId)); $media = $this->getValidatedSuccessResponse()->getData(); $this->assertEquals($newMediaId, $media->id); $this->assertEquals($requestParrams['name'], $media->name); $this->assertEquals(filesize($uploadFile), $media->filesize); DirectoryHelper::removeRecursiv(FS::joinPath($testMediaFilesDirectory, $websiteId), $testMediaFilesDirectory); }
public function tearDown() { DirectoryHelper::clearLatchDirectory(); parent::tearDown(); }
/** * @test * @group integration */ public function exportWebsiteShouldCreateExpectedFiles() { // ARRANGE $websiteId = 'SITE-controll-er0e-xpor-t0we-bsite0000001-SITE'; $config = Registry::getConfig(); $expectedJsonFilesDirectory = $config->test->json->storage->directory; $testFilesDirectory = $config->test->files->directory; $expectedExportedPackagesTree = FS::readContentFromFile(FS::joinPath($testFilesDirectory, 'trees', 'export', $websiteId, 'packages.tree')); $exportDirectoryName = 'test_export_0_website_with_album'; $exportBaseDirectory = $config->export->directory; $exportDirectory = FS::joinPath($exportBaseDirectory, md5($exportDirectoryName)); $exportZipFileName = md5($exportDirectoryName) . '.' . self::EXPORT_FILE_EXTENSION; $exportZipFile = FS::joinPath($exportDirectory, $exportZipFileName); $expectedTemplates = array('TPL-controll-er0e-xpor-t0we-bsite0000001-TPL' => (object) array('id' => 'TPL-controll-er0e-xpor-t0we-bsite0000001-TPL', 'name' => 'template export 1', 'content' => json_encode(array((object) array('abc' => 'def'))), 'pageType' => 'the_page_type_id'), 'TPL-controll-er0e-xpor-t0we-bsite0000002-TPL' => (object) array('id' => 'TPL-controll-er0e-xpor-t0we-bsite0000002-TPL', 'name' => 'template export 2', 'content' => json_encode(array()), 'pageType' => null)); // ACT $this->dispatchWithParams('export/website', array('websiteid' => $websiteId, 'name' => $exportDirectoryName)); // ASSERT $this->getValidatedSuccessResponse(); $this->assertTrue(is_dir($exportDirectory)); $this->assertFileExists($exportZipFile); $unzipCommand = sprintf("unzip %s -d %s", $exportZipFile, $exportDirectory); if (strstr($unzipCommand, $exportBaseDirectory)) { SystemHelper::user_proc_exec($unzipCommand); DirectoryHelper::removeRecursiv($exportZipFile, $exportBaseDirectory); } $expectedWebsiteJsonFile = FS::joinPath($expectedJsonFilesDirectory, 'expected_website.json'); $this->assertFileExists($expectedWebsiteJsonFile); $this->assertWebsiteJsonCreatedAsExpected($exportDirectory, $expectedWebsiteJsonFile); $expectedWebsiteSettingsJsonFile = FS::joinPath($expectedJsonFilesDirectory, 'expected_export_websitesettings.json'); $this->assertFileExists($expectedWebsiteSettingsJsonFile); $this->assertWebsiteSettingsJsonCreatedAsExpected($exportDirectory, $expectedWebsiteSettingsJsonFile); $this->assertTemplateJsonCreatedAsExpected($exportDirectory, $expectedTemplates); $exportedPackagesDirectory = FS::joinPath($exportDirectory, 'packages'); $actualExportedPackagesTree = DirectoryHelper::getRecursiveAsJson($exportedPackagesDirectory, true); $this->assertSame($actualExportedPackagesTree, $expectedExportedPackagesTree, "Tree mismatch between export package directory tree and expected package directory tree"); DirectoryHelper::removeRecursiv($exportDirectory, $exportBaseDirectory); }
protected function removeWebsiteBuilds() { $config = Registry::getConfig(); $buildsDirectory = $config->builds->directory; DirectoryHelper::removeRecursiv($buildsDirectory); }
/** * @test * @group integration */ public function overwriteShouldOverwriteStatedModules() { $config = Registry::getConfig(); DirectoryHelper::clearLatchDirectory(); $websiteId = 'SITE-im12maec-ovwr-4ea8-a477-t4e79e8e62m3-SITE'; $this->dispatch(sprintf('/modul/getAll/params/{"websiteid":"%s"}', $websiteId)); $response = new Response($this->getResponseBody()); $responseData = $response->getData(); $this->assertTrue(count($responseData->modules) === 4); $modules = array('MODUL-0rap5eb8-0df3-47e9-exti-71ae9d96d3m0-MODUL', 'MODUL-0rap5eb8-0df3-47e9-exti-71ae9d96d3m1-MODUL'); $templates = $media = array(); $importLatchFilesDirectory = $config->import->latch->files->directory; $importFileToLatch = $importLatchFilesDirectory . DIRECTORY_SEPARATOR . 'import_modules_conflict_modules.zip'; $this->assertFileExists($importFileToLatch); $latchBusiness = new LatchBusiness('Latch'); $importId = $latchBusiness->latchImportFile($websiteId, $importFileToLatch); $data = array('templates' => $templates, 'modules' => $modules, 'media' => $media, 'importId' => $importId); $request = sprintf('/import/overwrite/params/%s', json_encode($data)); $this->dispatch($request); $response = $this->getValidatedSuccessResponse(); $responseData = $response->getData(); $this->assertObjectHasAttribute('modules', $responseData); $this->assertObjectHasAttribute('templates', $responseData); $this->assertObjectHasAttribute('media', $responseData); $this->assertObjectHasAttribute('pages', $responseData); $this->assertObjectHasAttribute('website', $responseData); $this->assertEmpty($responseData->website); $this->assertEmpty($responseData->pages); $this->assertEmpty($responseData->templates); $this->assertEmpty($responseData->media); $this->assertNotEmpty($responseData->modules); $importedModules = $responseData->modules; $this->assertTrue(count($importedModules) === 3); $this->dispatch(sprintf('/modul/getAll/params/{"websiteid":"%s"}', $websiteId)); $response = new Response($this->getResponseBody()); $responseData = $response->getData(); $this->assertTrue(count($responseData->modules) === 5); $this->removeImportMediaDirectoryAndFiles($websiteId); }
/** * @test * @group integration */ public function exportTemplateSnippetsShouldExportAsExpectedWithSpecifiedName() { $config = Registry::getConfig(); $exportDirectoryName = 'test_export_0_templatesnippet'; $exportBaseDirectory = $config->export->directory; $exportDirectory = $exportBaseDirectory . DIRECTORY_SEPARATOR . md5($exportDirectoryName); $exportZipFile = $exportBaseDirectory . DIRECTORY_SEPARATOR . md5($exportDirectoryName) . DIRECTORY_SEPARATOR . md5($exportDirectoryName) . '.' . self::EXPORT_FILE_EXTENSION; $websiteId = 'SITE-ae6e702f-10ac-4e1e-exmo-307e4b8765db-SITE'; $templateSnippetIds = array('TPLS-template-snip-pet0-test-000000000021-TPLS', 'TPLS-template-snip-pet0-test-000000000022-TPLS', 'TPLS-template-snip-pet0-test-000000000023-TPLS'); $requestUri = sprintf('export/templatesnippets/params/%s', \Zend_Json::encode(array('websiteid' => $websiteId, 'ids' => $templateSnippetIds, 'name' => $exportDirectoryName))); $this->dispatch($requestUri); $response = $this->getValidatedSuccessResponse(); $responseData = $response->getData(); $this->assertObjectHasAttribute('url', $responseData); $nameDataPart = sprintf('{"name":"%s"}', $exportDirectoryName); $this->assertStringEndsWith($nameDataPart, $responseData->url); $this->assertTrue(is_dir($exportDirectory)); $this->assertFileExists($exportZipFile); $unzipCommand = sprintf("unzip %s -d %s", $exportZipFile, $exportDirectory); if (strstr($unzipCommand, $exportBaseDirectory)) { SystemHelper::user_proc_exec($unzipCommand); DirectoryHelper::removeRecursiv($exportZipFile, $exportBaseDirectory); } $testFilesDirectory = $config->test->files->directory; $expectedExportTreeFile = $testFilesDirectory . DIRECTORY_SEPARATOR . 'trees' . DIRECTORY_SEPARATOR . 'export' . DIRECTORY_SEPARATOR . 'expected_templatesnippets_export.tree'; $expectedExportTree = file_get_contents($expectedExportTreeFile); $exportDirectoryTree = DirectoryHelper::getRecursiveAsJson($exportDirectory, true); $this->assertSame($expectedExportTree, $exportDirectoryTree, "Tree mismatch between export directory tree and expected directory tree"); DirectoryHelper::removeRecursiv($exportDirectory, $exportBaseDirectory); }
protected function tearDown() { DirectoryHelper::clearLatchDirectory(); LatchBusiness::clearTestLatchDateAndTime(); parent::tearDown(); }
/** * @test * @integration */ public function moduleImportShouldRespondWithConflictingModules() { $websiteId = 'SITE-im12maec-20dr-4ea8-a477-m4e79e8e62c0-SITE'; $config = Registry::getConfig(); $testImportDirectory = $config->import->directory; $testFilesDirectory = $config->test->files->directory; $testImportFilename = 'test_export_0_modules_conflict.zip'; $testImportFile = $testFilesDirectory . DIRECTORY_SEPARATOR . 'test_exports' . DIRECTORY_SEPARATOR . $testImportFilename; $expectedImportFile = $testImportDirectory . DIRECTORY_SEPARATOR . $testImportFilename; $importUnzipDirectory = str_replace('.zip', '', $expectedImportFile); $assertionMessage = sprintf("Import file '%s' existiert nicht", $testImportFile); $this->assertFileExists($testImportFile, $assertionMessage); $testImportTmpFile = DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'phpe7f3im'; $fileInputname = 'import'; $requestUri = sprintf('/import/file/params/{"websiteid":"%s","fileinputname":"%s"}', $websiteId, $fileInputname); $this->assertFakeUpload($fileInputname, $testImportFile, $testImportTmpFile); $this->dispatch($requestUri); $this->assertHeaderContains('Content-Type', 'text/plain'); $responseBody = $this->getResponseBody(); $response = new Response($responseBody); $this->assertFalse($response->getSuccess(), $responseBody); $error = $response->getError(); $this->assertEquals(11, $error[0]->code); $responseData = $response->getData(); $this->assertObjectHasAttribute('importId', $responseData); $this->assertObjectHasAttribute('conflict', $responseData); $conflictData = $responseData->conflict; $this->assertObjectHasAttribute('templates', $conflictData); $this->assertObjectHasAttribute('modules', $conflictData); $this->assertObjectHasAttribute('media', $conflictData); $expectedConflictingModules = array(); for ($i = 0; $i < 3; ++$i) { $conflictingModule = new \StdClass(); $conflictingModule->id = 'MODUL-0rap5eb8-0df3-47e9-conf-90ae9d96d3c' . $i . '-MODUL'; $conflictingModule->oldName = 'module ' . $i; $conflictingModule->newName = 'Page_Export_' . $i; $expectedConflictingModules[] = $conflictingModule; } $actualConflictingModules = $conflictData->modules; usort($actualConflictingModules, function ($a, $b) { return strcmp($a->id, $b->id); }); $this->assertTrue(count($actualConflictingModules) === count($expectedConflictingModules)); $this->assertEquals($expectedConflictingModules, $actualConflictingModules); $errorData = $response->getError(); $this->assertEquals(11, $errorData[0]->code); $errorMessage = \Cms\Error::getMessageByCode(11); $this->assertEquals($errorMessage, $errorData[0]->text); if (file_exists($testImportTmpFile)) { unlink($testImportTmpFile); } if (strstr($importUnzipDirectory, $testImportDirectory)) { DirectoryHelper::removeRecursiv($importUnzipDirectory, $testImportDirectory); if (is_dir($importUnzipDirectory)) { rmdir($importUnzipDirectory); } if (file_exists($expectedImportFile)) { unlink($expectedImportFile); } } DirectoryHelper::clearLatchDirectory(); }
/** * @test * @group integration */ public function templateSnippetImportShouldImportAsExpectedForOnlyNewTemplateSnippetIds() { $config = Registry::getConfig(); $testImportDirectory = $config->import->directory; $testFilesDirectory = $config->test->files->directory; $testImportFilename = 'test_templatesnippets_export_non_existing_templatesnippets.zip'; $testImportFile = $testFilesDirectory . DIRECTORY_SEPARATOR . 'test_exports' . DIRECTORY_SEPARATOR . $testImportFilename; $expectedImportFile = $testImportDirectory . DIRECTORY_SEPARATOR . $testImportFilename; $importUnzipDirectory = str_replace('.zip', '', $expectedImportFile); $assertionMessage = sprintf("Import file '%s' existiert nicht", $testImportFile); $this->assertFileExists($testImportFile, $assertionMessage); $testImportTmpFile = DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'phpI2f3im'; $fileInputname = 'import'; $alreadyExistingWebsiteId = 'SITE-im13up2c-20da-4ea8-a477-4ee79e8e62mo-SITE'; $this->assertHasNoMedias($alreadyExistingWebsiteId); $requestUri = sprintf('/import/file/params/{"websiteid":"%s","fileinputname":"%s"}', $alreadyExistingWebsiteId, $fileInputname); $this->assertFakeUpload($fileInputname, $testImportFile, $testImportTmpFile); $this->dispatch($requestUri); $this->getValidatedSuccessResponse(); $this->assertHeaderContains('Content-Type', 'text/plain'); $expectedNewTemplateSnippets = array('TPLS-template-snip-pet0-test-import000001-TPLS' => (object) array('id' => 'TPLS-template-snip-pet0-test-import000001-TPLS', 'websiteId' => $alreadyExistingWebsiteId, 'name' => 'Imported_Test_TemplateSnippet_1', 'description' => '', 'category' => '', 'content' => json_decode('[{"id":"MUNIT-00000000-0000-0000-0000-000000000001-MUNIT","moduleId":"MODUL-0rap5eb8-0df3-47e9-exmo-90ae9d96d3c0-MODUL","name":"SnippetUnit_01","description":"","formValues":{},"children":[],"deletable":false,"ghostContainer":false,"visibleFormGroups":[]}]'), 'readonly' => false, 'sourceType' => 'local', 'overwritten' => false, 'baseLayout' => false, 'pageTypes' => array(), 'previewImageUrl' => null), 'TPLS-template-snip-pet0-test-import000002-TPLS' => (object) array('id' => 'TPLS-template-snip-pet0-test-import000002-TPLS', 'websiteId' => $alreadyExistingWebsiteId, 'name' => 'Imported_Test_TemplateSnippet_2', 'description' => '', 'category' => '', 'content' => json_decode('[{"id":"MUNIT-00000000-0000-0000-0000-000000000002-MUNIT","moduleId":"MODUL-0rap5eb8-0df3-47e9-exmo-90ae9d96d3c0-MODUL","name":"SnippetUnit_02","description":"","formValues":{},"children":[],"deletable":false,"ghostContainer":false,"visibleFormGroups":[]}]'), 'readonly' => false, 'sourceType' => 'local', 'overwritten' => false, 'baseLayout' => false, 'pageTypes' => array(), 'previewImageUrl' => null), 'TPLS-template-snip-pet0-test-import000003-TPLS' => (object) array('id' => 'TPLS-template-snip-pet0-test-import000003-TPLS', 'websiteId' => $alreadyExistingWebsiteId, 'name' => 'Imported_Test_TemplateSnippet_3', 'description' => '', 'category' => '', 'content' => json_decode('[]'), 'readonly' => false, 'sourceType' => 'local', 'overwritten' => false, 'baseLayout' => false, 'pageTypes' => array(), 'previewImageUrl' => null)); $requestUri = sprintf('/templatesnippet/getall/params/{"websiteId":"%s"}', $alreadyExistingWebsiteId); $this->dispatch($requestUri); $response = $this->getValidatedSuccessResponse(); $responseData = $response->getData(); $this->assertObjectHasAttribute('templatesnippets', $responseData); $this->assertInternalType('array', $responseData->templatesnippets); $templateSnippets = $responseData->templatesnippets; $actualNewTemplateSnippets = array(); foreach ($templateSnippets as $templateSnippet) { $this->assertInstanceOf('stdClass', $templateSnippet); $this->assertObjectHasAttribute('id', $templateSnippet); $assertionMessage = sprintf('Actual TemplateSnippet and expected TemplateSnippet not equal (%s).', $templateSnippet->id); $this->assertEquals($expectedNewTemplateSnippets[$templateSnippet->id], $templateSnippet, $assertionMessage); } $this->assertEquals(count($expectedNewTemplateSnippets), count($templateSnippets)); $this->assertHasNoMedias($alreadyExistingWebsiteId); if (strstr($importUnzipDirectory, $testImportDirectory)) { DirectoryHelper::removeRecursiv($importUnzipDirectory, $testImportDirectory); if (is_dir($importUnzipDirectory)) { rmdir($importUnzipDirectory); } if (file_exists($expectedImportFile)) { unlink($expectedImportFile); } } }
/** * @test * @group integration */ public function deleteAlbumShouldAlsoDeleteIncludedMedia() { $albumId = 'ALBUM-ce1ecf0d-acc4-4fdb-dem4-72ebb0878008-ALBUM'; $websiteId = 'SITE-ce6e702f-10ac-4e1e-dem7-307d4b8760al-SITE'; $expectedAlbumCountBeforeDelete = 2; $expectedAlbumCountAfterDelete = 1; $mediaFiles = array('samy-v1.js', 'backbone.js', 'samy-v2.js', 'samy-v3.js', 'samy-v4.js'); $this->assertTrue($this->createTestMedias($websiteId, $mediaFiles)); $getAllRequest = sprintf('/album/getall/params/{"websiteId":"%s"}', $websiteId); $this->dispatch($getAllRequest); $response = new Response($this->getResponseBody()); $this->assertTrue($response->getSuccess()); $responseData = $response->getData(); $this->assertObjectHasAttribute('albums', $responseData); $this->assertInternalType('array', $responseData->albums); $this->assertSame($expectedAlbumCountBeforeDelete, count($responseData->albums)); $request = sprintf('/album/delete/params/{"websiteId":"%s","id":"%s"}', $websiteId, $albumId); $this->dispatch($request); $response = $this->getResponseBody(); $this->dispatch($getAllRequest); $response = new Response($this->getResponseBody()); $this->assertTrue($response->getSuccess()); $responseData = $response->getData(); $this->assertObjectHasAttribute('albums', $responseData); $this->assertInternalType('array', $responseData->albums); $this->assertSame($expectedAlbumCountAfterDelete, count($responseData->albums)); $config = Registry::getConfig(); $testFilesDirectory = $config->test->files->directory; $testFilesMediaDirectory = $config->media->files->directory; $testMediaDirectory = $testFilesDirectory . DIRECTORY_SEPARATOR . $websiteId; $expectedAfterDeleteMediasTreeFile = $testFilesDirectory . DIRECTORY_SEPARATOR . 'trees' . DIRECTORY_SEPARATOR . 'album_delete.tree'; $expectedAfterDeleteMediasTree = file_get_contents($expectedAfterDeleteMediasTreeFile); $testMediaDirectory = $testFilesDirectory . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . $websiteId; $assertionMessage = "Tree mismatch between medias directory tree and " . "expected medias directory tree after album deletion"; $this->assertSame($expectedAfterDeleteMediasTree, \Test\Seitenbau\Directory\Helper::getRecursiveAsJson($testMediaDirectory, true), $assertionMessage); DirectoryHelper::removeRecursiv($testMediaDirectory, $testFilesMediaDirectory); }
/** * @param string $directory */ protected function assertDirectoryIsEmpty($directory) { $actualDirectoryTree = DirectoryHelper::getRecursive($directory); $this->assertEquals(array(), $actualDirectoryTree); }
/** * @test * @group library */ public function cancelAgainstNonExistingImportIdShouldThrowExpectedException() { DirectoryHelper::clearLatchDirectory(); $business = $this->business; $fakeImportId = str_repeat('a', LatchBusiness::LATCH_IMPORT_ID_LENGTH); $fakeImportId1 = str_repeat('b', LatchBusiness::LATCH_IMPORT_ID_LENGTH); $fakeImportId2 = str_repeat('c', LatchBusiness::LATCH_IMPORT_ID_LENGTH); $fakeLatches[$fakeImportId] = 'fake_import_1.zip'; $fakeLatches[$fakeImportId1] = 'fake_import_2.zip'; $fakeLatches[$fakeImportId2] = 'fake_import_3.zip'; $this->buildFakeLatchStorage($fakeLatches); $nonExistingImportId = str_repeat('m', LatchBusiness::LATCH_IMPORT_ID_LENGTH); $this->assertException(function () use(&$business, $nonExistingImportId) { $business->cancelImport($nonExistingImportId); }, array(), 'Cms\\Exception', function ($actualException, &$message) use($nonExistingImportId) { $expected = 15; if ($actualException->getCode() != $expected) { $message = 'Failed asserting that exception code contains ' . $actualException->getCode() . '. Expected code ' . $expected . '.'; return false; } $actualMessage = $actualException->getMessage(); $exceptedMessage = \Cms\Error::getMessageByCode($expected, array('value' => $nonExistingImportId)); if ($exceptedMessage != $actualMessage) { $message = 'Failed asserting that exception message "' . $actualMessage . '" contains "' . $exceptedMessage . '".'; return false; } return true; }); }
/** * @test * @group integration */ public function importShouldCreateUsergroupsAsExpected() { $expectedGroupCountAfterImport = 3; $expectedGroupNamesAfterImport = array('group_export_test_0', 'group_export_test_1', 'group_export_test_2'); $expectedGroupRightsAfterImport[] = array(0 => array('area' => 'pages', 'privilege' => 'subEdit', 'units' => array('PAGE-163b62or-b045-40ce-8b4e-c795a87a03ex-PAGE', 'PAGE-163b62or-b046-40ce-8b4e-c795a87a03ex-PAGE')), 1 => array('area' => 'modules', 'privilege' => 'all', 'units' => null), 2 => array('area' => 'templates', 'privilege' => 'none', 'units' => null)); $expectedGroupRightsAfterImport[] = array(0 => array('area' => 'pages', 'privilege' => 'subAll', 'units' => array('PAGE-163b62or-b045-40ce-8b4e-c795a87a03ex-PAGE', 'PAGE-163b62or-b046-40ce-8b4e-c795a87a03ex-PAGE')), 1 => array('area' => 'modules', 'privilege' => 'none', 'units' => null), 2 => array('area' => 'templates', 'privilege' => 'all', 'units' => null)); $expectedGroupRightsAfterImport[] = array(0 => array('area' => 'website', 'privilege' => 'publish', 'units' => null), 1 => array('area' => 'templates', 'privilege' => 'all', 'units' => null), 2 => array('area' => 'modules', 'privilege' => 'all', 'units' => null)); $config = Registry::getConfig(); $testImportDirectory = $config->import->directory; $testFilesDirectory = $config->test->files->directory; $testImportFilename = 'test_export_0_website_usergroups.zip'; $testImportFile = $testFilesDirectory . DIRECTORY_SEPARATOR . 'test_exports' . DIRECTORY_SEPARATOR . $testImportFilename; $expectedImportFile = $testImportDirectory . DIRECTORY_SEPARATOR . $testImportFilename; $importUnzipDirectory = str_replace('.zip', '', $expectedImportFile); $assertionMessage = sprintf("Import file '%s' existiert nicht", $testImportFile); $this->assertFileExists($testImportFile, $assertionMessage); $testImportTmpFile = DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'phpe9f3iu'; $fileInputname = 'import'; $requestUri = sprintf('/import/file/params/{"websiteid":"%s","fileinputname":"%s"}', \Cms\Request\Import\File::DEFAULT_EMPTY_WEBSITE_ID, $fileInputname); $this->assertFakeUpload($fileInputname, $testImportFile, $testImportTmpFile); $this->dispatch($requestUri); $response = $this->getValidatedSuccessResponse(); $this->assertHeaderContains('Content-Type', 'text/plain'); $responseDataImportedWebsite = $response->getData(); $this->assertTrue(isset($responseDataImportedWebsite->website[0])); $this->assertObjectHasAttribute('id', $responseDataImportedWebsite->website[0]); $importedWebsiteId = $responseDataImportedWebsite->website[0]->id; $getAllRequest = sprintf('/group/getall/params/{"websiteId":"%s"}', $importedWebsiteId); $this->dispatch($getAllRequest); $response = $this->getValidatedSuccessResponse(); $responseData = $response->getData(); $this->assertObjectHasAttribute('groups', $responseData); $this->assertInternalType('array', $responseData->groups); $actualGroups = $responseData->groups; $this->assertSame($expectedGroupCountAfterImport, count($actualGroups)); $expectedGroupFields = array('id', 'websiteId', 'name', 'rights', 'users'); sort($expectedGroupFields); $actualGroupNames = $actualGroupRights = array(); foreach ($actualGroups as $actualGroup) { $this->assertInstanceOf('stdClass', $actualGroup); $actualGroupFields = array_keys(get_object_vars($actualGroup)); sort($actualGroupFields); $this->assertSame($expectedGroupFields, $actualGroupFields); $this->assertObjectHasAttribute('websiteId', $actualGroup); $this->assertSame($importedWebsiteId, $actualGroup->websiteId); $this->assertObjectHasAttribute('users', $actualGroup); $this->assertInternalType('array', $actualGroup->users); $this->assertObjectHasAttribute('name', $actualGroup); $actualGroupNames[] = $actualGroup->name; $this->assertObjectHasAttribute('rights', $actualGroup); $actualGroupRights[] = $actualGroup->rights; } sort($expectedGroupNamesAfterImport); sort($actualGroupNames); $this->assertSame($expectedGroupNamesAfterImport, $actualGroupNames); sort($expectedGroupRightsAfterImport); sort($actualGroupRights); $this->assertSame(json_encode($expectedGroupRightsAfterImport), json_encode($actualGroupRights)); $this->assertTrue($this->removeImportMediaDirectoryAndFiles($importedWebsiteId)); if (strstr($importUnzipDirectory, $testImportDirectory)) { DirectoryHelper::removeRecursiv($importUnzipDirectory, $testImportDirectory); if (is_dir($importUnzipDirectory)) { rmdir($importUnzipDirectory); } if (file_exists($expectedImportFile)) { unlink($expectedImportFile); } } }
/** * @test * @group integration */ public function copyCopiesAssociatedAlbums() { $sourceWebsiteId = 'SITE-1964e89c-0001-cows-a651-fc42dc78fe50-SITE'; $sourceAlbumIds = array('ALBUM-wc0ecf03-moe9-4adb-ed3f-72ebb087800c-ALBUM', 'ALBUM-wc1ecf03-moe9-4adb-ed3f-72ebb087800c-ALBUM', 'ALBUM-wc2ecf03-moe9-4adb-ed3f-72ebb087800c-ALBUM'); $sourceMediaNames = array('Website_Copy_Album_0_0', 'Website_Copy_Album_0_1', 'Website_Copy_Album_0_2', 'Website_Copy_Album_1_0', 'Website_Copy_Album_1_1', 'Website_Copy_Album_1_2', 'Website_Copy_Album_2_0', 'Website_Copy_Album_2_1', 'Website_Copy_Album_2_2'); $testMediaFiles = array('report_2009.pdf', 'backbone.js', 'footer.jpg', 'header_0.png', 'report_2010.pdf', 'pdf.js', 'report_2011.pdf', 'grumble.js', 'header_0.gif'); $this->createTestMedias($sourceWebsiteId, $testMediaFiles); $copyRequest = sprintf('website/copy/params/{"id":"%s","name":"%s"}', $sourceWebsiteId, 'copied_website_with_copied_albums'); $this->dispatch($copyRequest); $response = $this->getResponseBody(); $response = new Response($response); $this->assertTrue($response->getSuccess()); $responseData = $response->getData(); $this->assertObjectHasAttribute('id', $responseData); $copiedWebsiteId = $responseData->id; $uniqueidValidator = new UniqueIdValidator(DataWebsite::ID_PREFIX, DataWebsite::ID_SUFFIX); $this->assertTrue($uniqueidValidator->isValid($copiedWebsiteId)); $config = Registry::getConfig(); $mediaBaseDirectory = realpath($config->media->files->directory); $sourceMediaDirectory = $mediaBaseDirectory . DIRECTORY_SEPARATOR . $sourceWebsiteId; $copiedMediaDirectory = $mediaBaseDirectory . DIRECTORY_SEPARATOR . $copiedWebsiteId; $this->assertTrue(is_dir($copiedMediaDirectory)); $testFilesDirectory = $config->test->files->directory; $expectedCopyTreeFile = $testFilesDirectory . DIRECTORY_SEPARATOR . 'trees' . DIRECTORY_SEPARATOR . 'website_copy.tree'; $expectedCopyTree = file_get_contents($expectedCopyTreeFile); $this->assertSame($expectedCopyTree, DirectoryHelper::getRecursiveAsJson($copiedMediaDirectory, true), "Tree mismatch between copied directory tree and expected directory tree"); $getAllMediaRequest = sprintf('media/getall/params/{"websiteid":"%s"}', $copiedWebsiteId); $this->dispatch($getAllMediaRequest); $response = $this->getResponseBody(); $response = new Response($response); $this->assertTrue($response->getSuccess()); $responseData = $response->getData(); $this->assertObjectHasAttribute('media', $responseData); $this->assertInternalType('array', $responseData->media); $this->assertObjectHasAttribute('total', $responseData); $expectedCopiedMediaTotal = 9; $this->assertSame($expectedCopiedMediaTotal, $responseData->total); $actualCopiedAlbumIds = array(); $actualMediaNames = array(); foreach ($responseData->media as $media) { $this->assertInstanceOf('stdClass', $media); $this->assertObjectHasAttribute('websiteId', $media); $this->assertObjectHasAttribute('albumId', $media); $this->assertObjectHasAttribute('name', $media); $this->assertSame($copiedWebsiteId, $media->websiteId); $this->assertContains($media->albumId, $sourceAlbumIds); $actualMediaNames[] = $media->name; if (!in_array($media->albumId, $actualCopiedAlbumIds)) { $actualCopiedAlbumIds[] = $media->albumId; } } sort($sourceMediaNames); sort($actualMediaNames); $this->assertSame($sourceMediaNames, $actualMediaNames); $expectedAlbumCount = 3; $this->assertSame($expectedAlbumCount, count($actualCopiedAlbumIds)); $getAllAlbumRequest = sprintf('album/getall/params/{"websiteid":"%s"}', $copiedWebsiteId); $this->dispatch($getAllAlbumRequest); $response = $this->getResponseBody(); $response = new Response($response); $this->assertTrue($response->getSuccess()); $responseData = $response->getData(); $this->assertObjectHasAttribute('albums', $responseData); $this->assertInternalType('array', $responseData->albums); $copiedAlbums = $responseData->albums; $this->assertSame($expectedAlbumCount, count($copiedAlbums)); $copiedAlbumIds = array(); foreach ($copiedAlbums as $album) { $this->assertInstanceOf('stdClass', $album); $this->assertObjectHasAttribute('id', $album); $copiedAlbumIds[] = $album->id; } sort($actualCopiedAlbumIds); sort($copiedAlbumIds); $this->assertSame($actualCopiedAlbumIds, $copiedAlbumIds); $getAllMediaRequest = sprintf('media/getall/params/{"websiteid":"%s"}', $sourceWebsiteId); $this->dispatch($getAllMediaRequest); $response = $this->getResponseBody(); $response = new Response($response); $this->assertTrue($response->getSuccess()); $responseData = $response->getData(); $this->assertObjectHasAttribute('media', $responseData); $this->assertInternalType('array', $responseData->media); $this->assertObjectHasAttribute('total', $responseData); $expectedSourceMediaTotal = 9; $this->assertSame($expectedSourceMediaTotal, $responseData->total); foreach ($responseData->media as $media) { $this->assertInstanceOf('stdClass', $media); $this->assertObjectHasAttribute('websiteId', $media); $this->assertObjectHasAttribute('albumId', $media); $this->assertSame($sourceWebsiteId, $media->websiteId); $this->assertContains($media->albumId, $actualCopiedAlbumIds); } DirectoryHelper::removeRecursiv($sourceMediaDirectory, $mediaBaseDirectory); DirectoryHelper::removeRecursiv($copiedMediaDirectory, $mediaBaseDirectory); }