/** * @test * @group library */ public function createShouldStoreExpectedTemplate() { // ARRANGE $websiteId = 'SITE-30490289-dddb-4501-879f-9c6c7965f871-SITE'; $create = array('name' => uniqid(__METHOD__, true), 'content' => array(array('id' => 'TEST_CONTENT_CREATE')), 'pageType' => 'the_page_type_id'); // ACT $this->service->create($websiteId, $create); // ASSERT $templates = $this->service->getAll($websiteId); foreach ($templates as $template) { if ($template->getName() === $create['name']) { $createdTemplate = $template; break; } } $this->assertInstanceOf('Cms\\Data\\Template', $createdTemplate); $this->assertSame($create['name'], $createdTemplate->getName()); $this->assertSame($create['pageType'], $createdTemplate->getPageType()); $this->assertSame(\Zend_Json::encode($create['content']), $createdTemplate->getContent()); $uuidValidator = new UniqueIdValidator(\Orm\Data\Template::ID_PREFIX, \Orm\Data\Template::ID_SUFFIX); $this->assertTrue($uuidValidator->isValid($createdTemplate->getId())); // Timestamp der letzten Aenderung darf nicht aelter sein als ein paar Sekunden $this->assertNotNull($createdTemplate->getLastupdate()); $currentTime = time(); $this->assertLessThanOrEqual($currentTime, $createdTemplate->getLastupdate()); $this->assertGreaterThan($currentTime - 2, $createdTemplate->getLastupdate()); }
/** * @test * @group small * @group dev * @group library */ public function test_updateAllContentsOfWebsite_success() { // ARRANGE $websiteId = 'SITE-update00-defa-ult0-form-values000001-SITE'; $templateSnippetId = 'TPLS-update00-defa-ult0-form-values000001-TPLS'; $templateId = 'TPL-update00-defa-ult0-form-values000001-TPL'; $pageId = 'PAGE-update00-defa-ult0-form-values000001-PAGE'; $orgTemplateContentChecksum = 'theoriginaltemplatechecksum'; $contentUpdaterBusiness = new ContentUpdaterBusiness('ContentUpdater'); $templateSnippetService = new TemplateSnippetService('TemplateSnippet'); $templateService = new TemplateService('Template'); $pageService = new PageService('Page'); $expectedSnippetContent = json_decode(FS::readContentFromFile(FS::joinPath($this->jsonFilesDirectory, 'expected_templatesnippet_content.json'))); $expectedTemplateContent = json_decode(FS::readContentFromFile(FS::joinPath($this->jsonFilesDirectory, 'expected_template_content.json'))); $expectedPageContent = json_decode(FS::readContentFromFile(FS::joinPath($this->jsonFilesDirectory, 'expected_page_1_content.json'))); // ACT $contentUpdaterBusiness->updateAllContentsOfWebsite($websiteId); // ASSERT $snippet = $templateSnippetService->getById($websiteId, $templateSnippetId); $actualSnippetContent = json_decode($snippet->getContent()); $this->assertEquals($expectedSnippetContent, $actualSnippetContent); $template = $templateService->getById($templateId, $websiteId); $this->assertNotSame($orgTemplateContentChecksum, $template->getContentchecksum()); $actualTemplateContent = json_decode($template->getContent()); $this->assertEquals($expectedTemplateContent, $actualTemplateContent); $page = $pageService->getById($pageId, $websiteId); $this->assertNotSame($orgTemplateContentChecksum, $page->getTemplatecontentchecksum()); $actualPageContent = json_decode($page->getContent()); $this->assertFormValuesOfPageContent($expectedPageContent, $actualPageContent); }
/** * @test * @group library */ public function getAllShouldRetrieveExpectedTemplates() { $websiteId = 'SITE-30490289-dddb-4501-879f-9c6c7965f871-SITE'; $uniqName = uniqid(__METHOD__, true); $creates = array(array('name' => $uniqName . '_1', 'content' => array(array('id' => 'TEST_CONTENT_GET_ALL_1')), 'pageType' => 'TEST_PAGETYPE_GET_ALL_1'), array('name' => $uniqName . '_2', 'content' => array(array('id' => 'TEST_CONTENT_GET_ALL_2')), 'pageType' => 'TEST_PAGETYPE_GET_ALL_2'), array('name' => $uniqName . '_3', 'content' => array(array('id' => 'TEST_CONTENT_GET_ALL_3')))); foreach ($creates as $create) { $this->service->create($websiteId, $create); } $templates = $this->service->getAll($websiteId); $this->assertSame(count($creates) + count($templates), count($templates) + count($creates)); foreach ($creates as $create) { foreach ($templates as $template) { if ($create['name'] === $template->getName()) { $createdTemplates[] = $template; } } } $this->assertSame(count($creates), count($createdTemplates)); foreach ($createdTemplates as $index => $template) { $this->assertInstanceOf('Cms\\Data\\Template', $template); $this->assertSame($creates[$index]['name'], $template->getName()); $this->assertSame(\Zend_Json::encode($creates[$index]['content']), $template->getContent()); if (array_key_exists('pageType', $creates[$index])) { $this->assertEquals($creates[$index]['pageType'], $template->getPageType()); } else { $this->assertNull($template->getPageType()); } $uuidValidator = new UniqueIdValidator(\Orm\Data\Template::ID_PREFIX, \Orm\Data\Template::ID_SUFFIX); $this->assertTrue($uuidValidator->isValid($template->getId())); } }
/** * @test * @group library * * @dataProvider provider_test_getIdsByWebsiteId */ public function test_getIdsByWebsiteId($websiteId, $expectedIds) { // ACT $actualTemplateIds = $this->service->getIdsByWebsiteId($websiteId); // ASSERT $this->assertSame($expectedIds, $actualTemplateIds); }
public function setUp() { parent::setUp(); $pageService = new PageService('Page'); $this->page = $pageService->getById('PAGE-033d84e8-cc3e-4a1f-a408-b8fa374af75f-PAGE', $this->websiteId); $templateService = new TemplateService('Template'); $this->template = $templateService->getById('TPL-0db7eaa7-7fc5-464a-bd47-16b3b8af67eb-TPL', $this->websiteId); }
/** * Legt fuer eine angegebene Website ein oder mehrere Templates an * * Die Template-IDs werden zurueckgegbene * * @param string $websiteId * @param int $number * @return array */ private function createTemplatesForWebsite($websiteId, $number = 1) { $templateIds = array(); $uniqName = uniqid(__METHOD__, true); $createdCounter = 0; while ($createdCounter < $number) { $createdCounter++; $create = array('name' => $uniqName . '_' . $createdCounter, 'content' => array(array('id' => 'TEST_CONTENT_GET_BY_ID_' . $createdCounter))); $template = $this->service->create($websiteId, $create); $templateIds[] = $template->getId(); } return $templateIds; }
/** * @test * @group small * @group dev * @group library */ public function test_updateDefaultFormValuesOfTemplate_success() { // ARRANGE $websiteId = 'SITE-update00-defa-ult0-form-values000001-SITE'; $templateId = 'TPL-update00-defa-ult0-form-values000001-TPL'; $orgTemplateContentChecksum = 'theoriginaltemplatechecksum'; $contentUpdaterService = new ContentUpdaterService('ContentUpdater'); $templateService = new TemplateService('Template'); $expectedContentJson = FS::readContentFromFile(FS::joinPath($this->jsonFilesDirectory, 'expected_template_content.json')); $expectedContent = json_decode($expectedContentJson); // ACT $contentUpdaterService->updateDefaultFormValuesOfTemplate($websiteId, $templateId); // ASSERT $template = $templateService->getById($templateId, $websiteId); $this->assertNotSame($orgTemplateContentChecksum, $template->getContentchecksum()); $templateContent = json_decode($template->getContent()); $this->assertEquals($expectedContent, $templateContent); }
/** * @test * @group library */ public function getByIdShouldReturnExpectedTemplate() { $websiteId = 'SITE-30490289-dddb-4501-879f-9c6c7965f871-SITE'; $create = array('name' => uniqid(__METHOD__, true), 'content' => array(array('id' => 'TEST_CONTENT_GET_BY_ID')), 'pageType' => 'TEST_PAGETYPE_GET_BY_ID'); $this->service->create($websiteId, $create); $templates = $this->service->getAll($websiteId); foreach ($templates as $template) { if ($template->getName() === $create['name']) { $createdTemplate = $template; break; } } $idOfCreatedTemplated = $createdTemplate->getId(); $getByIdTemplate = $this->service->getById($idOfCreatedTemplated, $websiteId); $this->assertInstanceOf('Cms\\Data\\Template', $getByIdTemplate); $this->assertSame($create['name'], $getByIdTemplate->getName()); $this->assertSame(\Zend_Json::encode($create['content']), $getByIdTemplate->getContent()); $this->assertSame($create['pageType'], $getByIdTemplate->getPageType()); $uuidValidator = new UniqueIdValidator(\Orm\Data\Template::ID_PREFIX, \Orm\Data\Template::ID_SUFFIX); $this->assertTrue($uuidValidator->isValid($getByIdTemplate->getId())); }
/** * @test * @group library * @expectedException Cms\Exception */ public function deleteShouldRejectDeleteWhenTemplateAssociatedToPage() { $this->service->delete('TPL-17rap53f-2bf8-4g4f-a47b-4a97223fbdea-TPL', 'SITE-25rapd17-fbc4-489e-9b1d-905608acedf7-SITE'); }
/** * @test * @group library * * @dataProvider provider_test_updateOrCreateTemplateFromTemplateJson_success */ public function test_updateOrCreateTemplateFromTemplateJson_success($websiteId, $templateId, $expectedTemplate) { // ARRANGE $templateJsonFile = FS::joinPath($this->testFilesDirectory, 'import', 'import_test_002', 'templates', $templateId, 'template.json'); $templateService = new TemplateService('Template'); $importServiceMock = $this->getMockBuilder('\\Cms\\Service\\Import')->setConstructorArgs(array('Import'))->setMethods(array('cleaningColorIds'))->getMock(); // ACT $actualImportedData = $this->callMethod($importServiceMock, 'updateOrCreateTemplateFromTemplateJson', array($templateId, $websiteId, $templateJsonFile)); // ASSERT $this->assertEquals($templateId, $actualImportedData['id']); $actualTemplate = $templateService->getById($templateId, $websiteId); $this->assertInstanceOf('\\Cms\\Data\\Template', $actualTemplate); $actualTemplateAsArray = $actualTemplate->toArray(); foreach ($expectedTemplate as $attributeName => $expectedValue) { $this->assertArrayHasKey($attributeName, $actualTemplateAsArray); $this->assertEquals($expectedValue, $actualTemplateAsArray[$attributeName]); } }