/** * @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)); }
/** * @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 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); }
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(); }
protected function tearDown() { $this->clearFakeUpload(); DirectoryHelper::clearLatchDirectory(); parent::tearDown(); }
/** * @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; }); }
public function tearDown() { DirectoryHelper::clearLatchDirectory(); parent::tearDown(); }