/** * @test * @group small * @group dev * @group library */ public function test_updateThrowNotExistsExceptionAsExpected() { // ARRANGE $dao = $this->getFilesystemDao(); $websiteId = 'WEBSITE-ID'; $snippetId = 'SNIPPET-ID-NOT-EXISTS'; $sourceItems = $this->getSourceItemsFromDirectory($this->getBaseDirectory('snippets'), '/url/to/templateSnippet', SourceItem::SOURCE_REPOSITORY, true); $source = $this->getTemplateSnippetSource($websiteId, $sourceItems); $expectedExceptionData = array('id' => $snippetId, 'websiteid' => $websiteId); $snippet = new DataTemplateSnippet(); $snippet->setId($snippetId); // ACT try { $dao->update($source, $snippet); $actualException = null; } catch (CmsException $actualException) { } // ASSERT $this->assertInstanceOf('\\Cms\\Exception', $actualException); $this->assertEquals(1602, $actualException->getCode()); $actualExceptionData = $actualException->getData(); $this->assertEquals($expectedExceptionData, $actualExceptionData); }
/** * @param string $websiteId * @param string $id * @param SourceItem $sourceItem * @param \stdClass $manifest * @param string $lastUpdate * @param string $previewImageUrl * * @return DataTemplateSnippet */ protected function loadDataObject($websiteId, $id, SourceItem $sourceItem, \stdClass $manifest, $lastUpdate, $previewImageUrl) { $snippet = new DataTemplateSnippet(); $snippet->setWebsiteid($websiteId); $snippet->setId($id); $snippet->setReadonly($sourceItem->isReadonly()); $snippet->setSourceType($sourceItem->getType()); $snippet->setLastupdate($lastUpdate); if (!empty($previewImageUrl)) { $snippet->setPreviewImageUrl($previewImageUrl); } if (property_exists($manifest, 'name')) { $snippet->setName($manifest->name); } if (property_exists($manifest, 'description')) { $snippet->setDescription($manifest->description); } if (property_exists($manifest, 'category')) { $snippet->setCategory($manifest->category); } if (property_exists($manifest, 'content')) { $snippet->setContent($manifest->content); } if (property_exists($manifest, 'baseLayout')) { $snippet->setBaseLayout($manifest->baseLayout); } if (property_exists($manifest, 'pageTypes') && is_array($manifest->pageTypes)) { $snippet->setPageTypes($manifest->pageTypes); } return $snippet; }
/** * @param string $count * @param string $suffix * @param array $attributes * * @return \Cms\Data\TemplateSnippet[] */ protected function createDataSnippets($count, $suffix, $attributes = array()) { $snippets = array(); for ($i = 1; $i <= $count; $i++) { $snippet = new DataTemplateSnippet(); if (array_key_exists('websiteid', $attributes)) { $snippet->setWebsiteid($attributes['websiteid']); } if (array_key_exists('id', $attributes)) { $snippet->setId($attributes['id']); } else { $snippet->setNewGeneratedId(); } if (array_key_exists('name', $attributes)) { $snippet->setName($attributes['name']); } else { $snippet->setName(sprintf('name_%04d%s', $i, $suffix)); } if (array_key_exists('description', $attributes)) { $snippet->setDescription($attributes['description']); } else { $snippet->setDescription(sprintf('description_%04d%s', $i, $suffix)); } if (array_key_exists('category', $attributes)) { $snippet->setCategory($attributes['category']); } else { $snippet->setCategory(sprintf('category_%04d%s', $i, $suffix)); } if (array_key_exists('content', $attributes)) { $snippet->setContent($attributes['content']); } else { $snippet->setCategory(json_encode(array(array('attribute' => sprintf('content_%04d%s', $i, $suffix))))); } if (array_key_exists('readonly', $attributes)) { $snippet->setReadonly($attributes['readonly']); } else { $snippet->setReadonly(false); } if (array_key_exists('sourcetype', $attributes)) { $snippet->setSourceType($attributes['sourcetype']); } else { $snippet->setSourceType($snippet::SOURCE_LOCAL); } if (array_key_exists('overwritten', $attributes)) { $snippet->setOverwritten($attributes['overwritten']); } else { $snippet->setOverwritten(false); } if (array_key_exists('lastupdate', $attributes)) { $snippet->setLastupdate($attributes['lastupdate']); } else { $snippet->setLastupdate(time()); } $snippets[] = $snippet; } return $snippets; }