Example #1
0
 /**
  * @test
  * @group library
  */
 public function exportModule_ModuleNotExists()
 {
     $business = $this->business;
     $notExistingModuleId = 'MODUL-NONONO-MODUL';
     $this->assertException(function () use(&$business, $notExistingModuleId) {
         $business->export(TestableExportBusiness::EXPORT_MODE_MODULE, 'SITE-11890b8a-d18f-4a24-8252-63f2aaf86a13-SITE', array($notExistingModuleId), 'testcase.' . self::EXPORT_FILE_EXTENSION);
     }, array(), 'Cms\\Exception', function ($actualException, &$message) use($notExistingModuleId) {
         $expected = 102;
         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('id' => $notExistingModuleId));
         if ($exceptedMessage != $actualMessage) {
             $message = 'Failed asserting that exception message "' . $actualMessage . '" contains "' . $exceptedMessage . '".';
             return false;
         }
         return true;
     });
 }
Example #2
0
 /**
  * @test
  * @group integration
  */
 public function cancelShouldReturnErrorForNonExistingImportId()
 {
     DirectoryHelper::clearLatchDirectory();
     $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('d', LatchBusiness::LATCH_IMPORT_ID_LENGTH);
     $request = sprintf('/import/cancel/params/{"importid":"%s"}', $nonExistingImportId);
     $this->dispatch($request);
     $response = new Response($this->getResponseBody());
     $this->assertInternalType('string', $this->getResponseBody());
     $this->assertNotNull($this->getResponseBody());
     $this->assertFalse($response->getSuccess());
     $errorData = $response->getError();
     $expectedErrorText = sprintf('Import Id %s existiert nicht', $nonExistingImportId);
     $expectedErrorText = \Cms\Error::getMessageByCode(15, array('value' => $nonExistingImportId));
     $this->assertEquals($expectedErrorText, $errorData[0]->text);
 }
Example #3
0
 protected function getPriorityByCode($code)
 {
     return CmsError::getPriorityByCode($code);
 }
Example #4
0
 /**
  * @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();
 }
Example #5
0
 /**
  * @test
  * @integration
  */
 public function templateSnippetImportShouldRespondWithConflictingTemplateSnippet()
 {
     $websiteId = 'SITE-ae6e702f-10ac-4e1e-exmo-307e4b8765db-SITE';
     $config = Registry::getConfig();
     $testImportDirectory = $config->import->directory;
     $testFilesDirectory = $config->test->files->directory;
     $testImportFilename = 'test_export_0_templatesnippets_conflict_only_templatesnippet.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');
     $response = new Response($this->getResponseBody());
     $this->assertFalse($response->getSuccess());
     $reponseError = $response->getError();
     $this->assertEquals(11, $reponseError[0]->code);
     $responseData = $response->getData();
     $this->assertObjectHasAttribute('importId', $responseData);
     $this->assertObjectHasAttribute('conflict', $responseData);
     $conflictData = $responseData->conflict;
     $this->assertObjectHasAttribute('templatesnippets', $conflictData);
     $this->assertObjectHasAttribute('templates', $conflictData);
     $this->assertObjectHasAttribute('modules', $conflictData);
     $this->assertObjectHasAttribute('media', $conflictData);
     $expectedConflictingTemplateSnippets = array();
     $conflictingTemplateSnippet = new \StdClass();
     $conflictingTemplateSnippet->id = 'TPLS-template-snip-pet0-test-000000000023-TPLS';
     $conflictingTemplateSnippet->oldName = 'TEMPLATE_SNIPPET_NAME_23';
     $conflictingTemplateSnippet->newName = 'Export_Test_TemplateSnippet_0';
     $expectedConflictingTemplateSnippets[] = $conflictingTemplateSnippet;
     $this->assertTrue(count($conflictData->templatesnippets) === count($expectedConflictingTemplateSnippets));
     $this->assertEquals($expectedConflictingTemplateSnippets, $conflictData->templatesnippets);
     $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);
         }
     }
 }
Example #6
0
 /**
  * @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;
     });
 }
Example #7
0
 /**
  * @param array $conflictData
  */
 protected function handleImportConflicts($conflictData)
 {
     $error = new Cms\Response\Error();
     $error->setCode(11);
     $error->setText(\Cms\Error::getMessageByCode(11));
     $this->responseData->addError($error);
     $this->responseData->setData(new ImportConflictResponse($conflictData));
 }