Ejemplo n.º 1
0
 /**
  * @param  string $value
  * @return boolean
  */
 public function isValid($value)
 {
     $this->_setValue($value);
     if (empty($value)) {
         $this->_error(self::IS_EMPTY);
         return false;
     }
     if (!is_string($value)) {
         $this->_error(self::NOT_A_STRING);
         return false;
     }
     $parts = explode('.', $value);
     if (count($parts) != 3) {
         $this->_error(self::INVALID);
         return false;
     }
     $buildIdValidator = new BuildIdValidator();
     if (!$buildIdValidator->isValid($parts[0])) {
         $this->_error(self::INVALID);
         return false;
     }
     $integerValidator = new IntegerValidator();
     if (!$integerValidator->isValid($parts[1])) {
         $this->_error(self::INVALID);
         return false;
     }
     $uniqueIdValidator = new UniqueIdValidator('', '');
     if (!$uniqueIdValidator->isValid($parts[2])) {
         $this->_error(self::INVALID);
         return false;
     }
     return true;
 }
Ejemplo n.º 2
0
 /**
  * @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());
 }
Ejemplo n.º 3
0
 /**
  * @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()));
     }
 }
Ejemplo n.º 4
0
 /**
  * @test
  * @group library
  */
 public function getAllOnlyRetrieveModulesFromWebsite()
 {
     // ARRANGE
     $dao = $this->createModuleDao();
     $moduleSource = new ModuleSource($this->websiteId);
     $expectedModuleIds = array('MODUL-0rap5eb8-0df3-47e9-afac-90ae9d96d3c2-MODUL', 'MODUL-0rap62pl-0t4f-23c9-8628-f2cb4136ef45-MODUL', 'MODUL-0bin62pl-0t4f-23c9-8628-f2cb4136ef45-MODUL', 'MODUL-4mrap53m-2af9-4g2f-a4rb-4a93in3f70mu-MODUL');
     // ACT
     $modules = $dao->getAll($moduleSource);
     // ASSERT
     $this->assertEquals(count($expectedModuleIds), count($modules));
     foreach ($modules as $module) {
         $assertionMessage = 'module "' . $module->getId() . '" not expected';
         $this->assertTrue(in_array($module->getId(), $expectedModuleIds), $assertionMessage);
         if ($module->getId() == 'MODUL-0rap62pl-0t4f-23c9-8628-f2cb4136ef45-MODUL') {
             $this->assertInstanceOf('Cms\\Data\\Modul', $module);
             $this->assertEquals('Basismodul_Page', $module->getName());
             $this->assertEquals('some_description', $module->getDescription());
             $this->assertEquals(null, $module->getVersion());
             $this->assertEquals('some_icon', $module->getIcon());
             $this->assertEquals(array(), $module->getForm());
             $this->assertEquals(new \stdClass(), $module->getFormvalues());
             $this->assertEquals('some_category', $module->getCategory());
             $this->assertEquals('root', $module->getModuletype());
             $this->assertEquals('*', $module->getAllowedchildmoduletype());
             $this->assertEquals(true, $module->getRerenderrequired());
             $uuidValidator = new UniqueIdValidator(\Orm\Data\Modul::ID_PREFIX, \Orm\Data\Modul::ID_SUFFIX);
             $this->assertTrue($uuidValidator->isValid($module->getId()));
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * @param Orm\Iface\Data\Uuidable $uuidable
  * @param string $id
  * @return boolean
  */
 protected function validateUniqueId($uuidable, $id)
 {
     $uniqueIdValidator = new UniqueIdValidator($uuidable::ID_PREFIX, $uuidable::ID_SUFFIX);
     if (!$uniqueIdValidator->isValid($id)) {
         return false;
     }
     return true;
 }
Ejemplo n.º 6
0
 /**
  * @test
  * @group library
  * @dataProvider dataClassNameOrmDataAndCountProvider
  */
 public function serviceShouldGenerateExpectedUiids($dataClassName, $uuidable, $count)
 {
     $uuids = $this->business->getUuids($dataClassName, $count);
     $this->assertSame($count, count($uuids));
     $uuidValidator = new UniqueIdValidator($uuidable::ID_PREFIX, $uuidable::ID_SUFFIX);
     foreach ($uuids as $uuid) {
         $this->assertTrue($uuidValidator->isValid($uuid));
     }
 }
Ejemplo n.º 7
0
 /**
  * @param string $id
  * @return boolean
  */
 private function validateAlbumId($id)
 {
     $albumIdValidator = new UniqueIdValidator(DataAlbum::ID_PREFIX, DataAlbum::ID_SUFFIX);
     if (!$albumIdValidator->isValid($id)) {
         $messages = array_values($albumIdValidator->getMessages());
         $this->addError(new Error('id', $id, $messages));
         return false;
     }
     return true;
 }
Ejemplo n.º 8
0
 /**
  * @test
  * @group library
  */
 public function getByIdShouldReturnExpectedTemplateSnippet()
 {
     $websiteId = 'SITE-template-snip-pet0-test-000000000001-SITE';
     $create = array('name' => 'TEMPLATE_SNIPPET_NAME_' . __METHOD__, 'description' => 'TEMPLATE_SNIPPET_DESCRIPTION_' . __METHOD__, 'category' => 'TEMPLATE_SNIPPET_CATEGORY_' . __METHOD__, 'content' => '[]');
     $createdSnippet = $this->service->create($websiteId, $create);
     $idOfCreatedTemplateSnippet = $createdSnippet->getId();
     $getByIdTemplateSnippet = $this->service->getById($websiteId, $idOfCreatedTemplateSnippet);
     $this->assertInstanceOf('Cms\\Data\\TemplateSnippet', $getByIdTemplateSnippet);
     $this->assertSame($idOfCreatedTemplateSnippet, $getByIdTemplateSnippet->getId());
     $this->assertSame($create['name'], $getByIdTemplateSnippet->getName());
     $this->assertSame($create['description'], $getByIdTemplateSnippet->getDescription());
     $this->assertSame($create['category'], $getByIdTemplateSnippet->getCategory());
     $this->assertSame($create['content'], $getByIdTemplateSnippet->getContent());
     $uuidValidator = new UniqueIdValidator(\Orm\Data\TemplateSnippet::ID_PREFIX, \Orm\Data\TemplateSnippet::ID_SUFFIX);
     $this->assertTrue($uuidValidator->isValid($getByIdTemplateSnippet->getId()));
 }
Ejemplo n.º 9
0
 /**
  * @test
  * @group library
  */
 public function createShouldStoreExpectedModule()
 {
     // ARRANGE
     $moduleCountBefore = count($this->service->getAll($this->websiteId));
     $create = new DataModul();
     $create->setName(__METHOD__ . '_1');
     $create->setDescription('TEST_DESCRIPTION_CREATE_1');
     $create->setVersion('TEST_VERSION_CREATE_1');
     $create->setIcon('TEST_ICON_CREATE_1');
     $create->setForm(SbJson::decode(SbJson::encode(array(array('name' => 'Titel und Beschreibung', 'formGroupData' => array('params' => array('name' => 'Cmsvar', 'value' => 'title')))))));
     $create->setFormvalues(SbJson::decode(SbJson::encode(array(array('key' => 'value')))));
     $create->setCategory('TEST_CATEGORY_CREATE_1');
     $create->setModuletype('root');
     $create->setAllowedchildmoduletype('extension');
     $create->setRerenderrequired('rerenderrequired');
     // ACT
     $createdModul = $this->service->create($this->websiteId, $create);
     // ASSERT
     $modules = $this->service->getAll($this->websiteId);
     $this->assertTrue(count($modules) > $moduleCountBefore);
     /** @var \Cms\Data\Modul[] $modules */
     foreach ($modules as $module) {
         if ($module->getName() === $create->getName()) {
             $createdModule = $module;
         }
     }
     $this->assertInstanceOf('Cms\\Data\\Modul', $createdModule);
     $this->assertEquals($create->getName(), $createdModule->getName());
     $this->assertEquals($this->websiteId, $createdModule->getWebsiteId());
     $this->assertEquals($create->getDescription(), $createdModule->getDescription());
     $this->assertEquals($create->getVersion(), $createdModule->getVersion());
     $this->assertEquals($create->getIcon(), $createdModule->getIcon());
     $this->assertEquals($create->getForm(), $createdModule->getForm());
     $this->assertEquals($create->getFormvalues(), $createdModule->getFormvalues());
     $this->assertEquals($create->getCategory(), $createdModule->getCategory());
     $this->assertEquals($create->getModuletype(), $createdModule->getModuletype());
     $this->assertEquals($create->getAllowedchildmoduletype(), $createdModule->getAllowedchildmoduletype());
     $this->assertEquals($create->getRerenderrequired(), $createdModule->getReRenderRequired());
     // Timestamp der letzten Aenderung darf nicht aelter sein als ein paar Sekunden
     $this->assertNotNull($createdModule->getLastupdate());
     $maxAlter = date('Y-m-d H:i:s', time() - 2);
     $this->assertGreaterThan($maxAlter, $createdModule->getLastupdate());
     $uuidValidator = new UniqueIdValidator(\Orm\Data\Modul::ID_PREFIX, \Orm\Data\Modul::ID_SUFFIX);
     $this->assertTrue($uuidValidator->isValid($createdModule->getId()));
     // this call throws exception on error occured
     $this->service->getAssetsPath($this->websiteId, $createdModule->getId());
 }
Ejemplo n.º 10
0
 /**
  * @test
  * @group library
  */
 public function getAllDescShouldRetrieveExpectedTemplatesSnippets()
 {
     $websiteId = 'SITE-template-snip-pet0-test-000000000001-SITE';
     $expectedSnippets = array(array('id' => 'TPLS-template-snip-pet0-test-000000000001-TPLS', 'name' => 'TEMPLATE_SNIPPET_NAME_1', 'description' => 'TEMPLATE_SNIPPET_DESCRIPTION_1', 'category' => 'TEMPLATE_SNIPPET_CATEGORY_1', 'baselayout' => false, 'pagetypes' => array(), 'content' => '[]'), array('id' => 'TPLS-template-snip-pet0-test-000000000002-TPLS', 'name' => 'TEMPLATE_SNIPPET_NAME_2', 'description' => 'TEMPLATE_SNIPPET_DESCRIPTION_2', 'category' => 'TEMPLATE_SNIPPET_CATEGORY_2', 'baselayout' => false, 'pagetypes' => array(), 'content' => '[]'), array('id' => 'TPLS-template-snip-pet0-test-000000000003-TPLS', 'name' => 'TEMPLATE_SNIPPET_NAME_3', 'description' => 'TEMPLATE_SNIPPET_DESCRIPTION_3', 'category' => 'TEMPLATE_SNIPPET_CATEGORY_3', 'baselayout' => false, 'pagetypes' => array(), 'content' => '[]'));
     $actualSnippets = $this->service->getAll($websiteId, 'DESC');
     $this->assertSame(count($expectedSnippets), count($actualSnippets));
     foreach ($actualSnippets as $actualIndex => $snippet) {
         $index = count($expectedSnippets) - $actualIndex - 1;
         $this->assertInstanceOf('Cms\\Data\\TemplateSnippet', $snippet);
         $snippetAsArray = $snippet->toArray();
         foreach ($expectedSnippets[$index] as $attributeName => $expectedValue) {
             $this->assertEquals($expectedValue, $snippetAsArray[$attributeName]);
         }
         $uuidValidator = new UniqueIdValidator(\Orm\Data\TemplateSnippet::ID_PREFIX, \Orm\Data\TemplateSnippet::ID_SUFFIX);
         $this->assertTrue($uuidValidator->isValid($snippet->getId()));
     }
 }
Ejemplo n.º 11
0
 /**
  * @test
  * @group integration
  * @dataProvider uuidProvider
  * @param string  $action
  * @param string  $resource
  * @param integer $count
  */
 public function getUuidShouldReturnFiveValidUuidsForUuidProvider($action, $resource, $count)
 {
     $dispatchUri = sprintf('/uuid/%s/params/{"count":%d}', $action, $count);
     $this->dispatch($dispatchUri);
     $cmsResponse = new CmsResponse($this->getResponseBody());
     $data = $cmsResponse->getData();
     $this->assertObjectHasAttribute('uuids', $data);
     $this->assertInternalType('array', $data->uuids);
     $uuids = $data->uuids;
     $this->assertTrue(count($uuids) === $count);
     $dataResource = sprintf('Orm\\Data\\%s', $resource);
     $uniqueidValidator = new UniqueIdValidator($dataResource::ID_PREFIX, $dataResource::ID_SUFFIX);
     foreach ($uuids as $uuid) {
         $this->assertTrue($uniqueidValidator->isValid($uuid));
     }
     $this->resetResponse();
     $this->resetRequest();
 }
Ejemplo n.º 12
0
 /**
  * @test
  * @group library
  */
 public function success()
 {
     $attributes = array('email' => '*****@*****.**', 'lastname' => 'create test', 'firstname' => 'service user', 'gender' => 'm', 'isSuperuser' => false, 'isDeletable' => true);
     $newUser = $this->service->create($attributes);
     $this->assertInstanceOf('Cms\\Data\\User', $newUser);
     $this->assertSame($attributes['email'], $newUser->getEmail());
     $this->assertSame($attributes['lastname'], $newUser->getLastname());
     $this->assertSame($attributes['firstname'], $newUser->getFirstname());
     $this->assertSame($attributes['gender'], $newUser->getGender());
     $this->assertSame($attributes['isSuperuser'], $newUser->isSuperuser());
     $this->assertSame($attributes['isDeletable'], $newUser->isDeletable());
     $uuidValidator = new UniqueIdValidator(\Orm\Data\User::ID_PREFIX, \Orm\Data\User::ID_SUFFIX);
     $this->assertTrue($uuidValidator->isValid($newUser->getId()));
     // Timestamp der letzten Aenderung darf nicht aelter sein als ein paar Sekunden
     $this->assertNotNull($newUser->getLastupdate());
     $currentTime = time();
     $this->assertLessThanOrEqual($currentTime, $newUser->getLastupdate());
     $this->assertGreaterThan($currentTime - 2, $newUser->getLastupdate());
 }
Ejemplo n.º 13
0
 /**
  * @test
  * @group library
  */
 public function createShouldStoreExpectedTemplateSnippet()
 {
     $websiteId = 'SITE-template-snip-pet0-test-000000000001-SITE';
     $create = array('name' => __METHOD__, 'description' => 'TEMPLATE_SNIPPET_DESCRIPTION_' . __METHOD__, 'category' => 'TEMPLATE_SNIPPET_CATEGORY_' . __METHOD__, 'content' => '[]');
     $snippetId = $this->service->create($websiteId, $create);
     $createdTemplateSnippet = $this->service->getById($websiteId, $snippetId->getId());
     $this->assertInstanceOf('Cms\\Data\\TemplateSnippet', $createdTemplateSnippet);
     $this->assertSame($create['name'], $createdTemplateSnippet->getName());
     $this->assertSame($create['description'], $createdTemplateSnippet->getDescription());
     $this->assertSame($create['category'], $createdTemplateSnippet->getCategory());
     $this->assertSame($create['content'], $createdTemplateSnippet->getContent());
     $uuidValidator = new UniqueIdValidator(\Orm\Data\TemplateSnippet::ID_PREFIX, \Orm\Data\TemplateSnippet::ID_SUFFIX);
     $this->assertTrue($uuidValidator->isValid($createdTemplateSnippet->getId()));
     // Timestamp der letzten Aenderung darf nicht aelter sein als ein paar Sekunden
     $this->assertNotNull($createdTemplateSnippet->getLastupdate());
     $currentTime = time();
     $this->assertLessThanOrEqual($currentTime, $createdTemplateSnippet->getLastupdate());
     $this->assertGreaterThan($currentTime - 2, $createdTemplateSnippet->getLastupdate());
 }
Ejemplo n.º 14
0
 /**
  * @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()));
 }
Ejemplo n.º 15
0
 /**
  * @test
  * @group library
  */
 public function updateShouldAlterTemplateAsExpected()
 {
     $websiteId = 'SITE-30490289-dddb-4501-879f-9c6c7965f871-SITE';
     $create = array('name' => uniqid(__METHOD__, true), 'content' => array(array('id' => 'TEMPLATE_CONTENT_CREATE')));
     $this->business->create($websiteId, $create);
     $templates = $this->business->getAll($websiteId);
     foreach ($templates as $template) {
         if ($template->getName() === $create['name']) {
             $createdTemplate = $template;
             break;
         }
     }
     $idOfCreatedTemplated = $createdTemplate->getId();
     $update = array('name' => $create['name'] . '_EDIT', 'content' => array(array('id' => 'TEMPLATE_CONTENT_EDIT')), 'websiteid' => $websiteId);
     $this->business->update($idOfCreatedTemplated, $websiteId, $update);
     $getByIdTemplate = $this->business->getById($idOfCreatedTemplated, $websiteId);
     $this->assertInstanceOf('Cms\\Data\\Template', $getByIdTemplate);
     $this->assertSame($update['name'], $getByIdTemplate->getName());
     $this->assertSame(\Zend_Json::encode($update['content']), $getByIdTemplate->getContent());
     $uuidValidator = new UniqueIdValidator(\Orm\Data\Template::ID_PREFIX, \Orm\Data\Template::ID_SUFFIX);
     $this->assertTrue($uuidValidator->isValid($getByIdTemplate->getId()));
 }
Ejemplo n.º 16
0
 /**
  * @param  string  $id
  * @return boolean
  */
 private function validatePageId($id)
 {
     $pageIdValidator = new UniqueIdValidator(DataPage::ID_PREFIX, DataPage::ID_SUFFIX);
     $pageIdValidator->setMessage("Angegebene Page Id ist ungueltig", UniqueIdValidator::INVALID);
     if (!$pageIdValidator->isValid($id)) {
         $messages = array_values($pageIdValidator->getMessages());
         $this->addError(new Error('id', $id, $messages));
         return false;
     }
     return true;
 }
Ejemplo n.º 17
0
 /**
  * validate the website home
  *
  * $param string  home
  * @return boolean
  */
 private function validateHome($home)
 {
     $idValidator = new UniqueIdValidator(DataPage::ID_PREFIX, DataPage::ID_SUFFIX);
     if (!$idValidator->isValid($home)) {
         $messages = array_values($idValidator->getMessages());
         $this->addError(new Error('home', $home, $messages));
         return false;
     }
     return true;
 }
Ejemplo n.º 18
0
 /**
  * @test
  * @group integration
  */
 public function uploadShouldStoreFileAsExpectedAndHaveTextPlainContentType()
 {
     $expectedUploadCount = 1;
     $expectedUploadExtension = 'js';
     $config = Registry::getConfig();
     $testMediaFilesDirectory = $config->media->files->directory;
     $testFilesDirectory = $config->test->files->directory;
     $testUploadFile = $testFilesDirectory . DIRECTORY_SEPARATOR . 'backbone.js';
     $testTmpFile = DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'phpIsd9te';
     $websiteId = 'SITE-ra10e8ul-11af-46cd-a651-fc42dc78fe50-SITE';
     $mediaName = 'integration_test_upload';
     $albumId = 'ALBUM-ce2ecf03-acc4-4adb-ed34-72ebb08780up-ALBUM';
     $fileInputname = 'upload';
     $requestUri = sprintf('/media/upload/params/{"websiteid":"%s","albumid":"%s","name":"%s","fileinputname":"%s"}', $websiteId, $albumId, $mediaName, $fileInputname);
     $this->assertFakeUpload($fileInputname, $testUploadFile, $testTmpFile);
     $this->dispatch($requestUri);
     $response = $this->getResponseBody();
     $this->assertHeaderContains('Content-Type', 'text/plain');
     $this->assertNotNull($response);
     $this->assertInternalType('string', $response);
     $response = new Response($response);
     $this->assertTrue($response->getSuccess());
     $uniqueidValidator = new UniqueIdValidator(DataMedia::ID_PREFIX, DataMedia::ID_SUFFIX);
     $responseData = $response->getData();
     $this->assertObjectHasAttribute('id', $responseData);
     $mediaId = $responseData->id;
     $this->assertTrue($uniqueidValidator->isValid($mediaId));
     $expectedMediaWebsiteDirectory = $testMediaFilesDirectory . DIRECTORY_SEPARATOR . $websiteId;
     $this->assertTrue(is_dir($expectedMediaWebsiteDirectory));
     $directory = new \DirectoryIterator($expectedMediaWebsiteDirectory);
     $uploadedFiles = array();
     foreach ($directory as $fileinfo) {
         if (!$fileinfo->isDot()) {
             $splitFileName = explode(".", $fileinfo->getFilename());
             $this->assertSame($expectedUploadExtension, end($splitFileName));
             $uploadedFiles[] = $fileinfo->getFilename();
         }
     }
     $this->assertSame($expectedUploadCount, count($uploadedFiles));
     $testMediaWebsiteUploadDirectory = $testMediaFilesDirectory . DIRECTORY_SEPARATOR . $websiteId;
     $this->dispatch('/media/getbyid/params/{"websiteid":"' . $websiteId . '","id":"' . $mediaId . '"}');
     $response = $this->getResponseBody();
     $response = new Response($response);
     $this->assertTrue($response->getSuccess());
     $responseData = $response->getData();
     $this->assertObjectHasAttribute('dateUploaded', $responseData);
     $this->assertNotNull($responseData->dateUploaded, 'Upload-Datum muss automatisch gesetzt werden');
     $this->assertInternalType('int', $responseData->dateUploaded, 'Upload-Datum muss Timestamp sein');
     DirectoryHelper::removeRecursiv($testMediaWebsiteUploadDirectory, $testMediaFilesDirectory);
 }
Ejemplo n.º 19
0
 /**
  * @param  string  $pageId
  * @return boolean
  */
 private function validatePageId($pageId)
 {
     $pageIdValidator = new UniqueIdValidator(Unit\Page::ID_PREFIX, Unit\Page::ID_SUFFIX);
     if (!$pageIdValidator->isValid($pageId)) {
         Registry::getLogger()->logData(__METHOD__, __LINE__, 'No page id in page rights', $pageId, Log::ERR);
         return false;
     }
     return true;
 }
Ejemplo n.º 20
0
 /**
  * @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);
 }
Ejemplo n.º 21
0
 /**
  * @test
  * @group small
  * @group dev
  * @group library
  * @dataProvider uniqueIdValuesProvider
  */
 public function isValidShouldReturnTrueForUniqueIdValues($prefix, $suffix, $uuid)
 {
     $uuidValidator = new UniqueIdValidator($prefix, $suffix);
     $this->assertTrue($uuidValidator->isValid($uuid));
 }
Ejemplo n.º 22
0
 /**
  * @param string $id
  * @param string  $key
  *
  * @return boolean
  */
 protected function validateWebsiteId($id, $key = 'websiteid')
 {
     $websiteIdValidator = new UniqueIdValidator(DataSite::ID_PREFIX, DataSite::ID_SUFFIX);
     $websiteIdValidator->setMessage($this->_('error.validation.base.websiteid.invalid'), UniqueIdValidator::INVALID);
     if (!$websiteIdValidator->isValid($id)) {
         $messages = array_values($websiteIdValidator->getMessages());
         $this->addError(new Error($key, $id, $messages));
         return false;
     }
     return true;
 }
Ejemplo n.º 23
0
 /**
  * @param  string  $id
  * @return boolean
  */
 private function validateTemplateSnippetId($id, $fieldName = 'id')
 {
     $templateSnippetIdValidator = new UniqueIdValidator(DataTemplateSnippet::ID_PREFIX, DataTemplateSnippet::ID_SUFFIX);
     if (!$templateSnippetIdValidator->isValid($id)) {
         $messages = array_values($templateSnippetIdValidator->getMessages());
         $this->addError(new Error($fieldName, $id, $messages));
         return false;
     }
     return true;
 }
Ejemplo n.º 24
0
 public function __construct()
 {
     parent::__construct(UserData::ID_PREFIX, UserData::ID_SUFFIX, '/^(%s)?[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}(%s)?$/');
 }
Ejemplo n.º 25
0
 /**
  * @param mixed $ids
  * @return boolean
  */
 private function validateTemplateIds($ids)
 {
     $isArrayValidator = new IsArrayValidator(false);
     $isArrayValidator->setMessage("'%value%' ist kein Array", IsArrayValidator::INVALID_NO_ARRAY);
     if (!$isArrayValidator->isValid($ids)) {
         $messages = array_values($isArrayValidator->getMessages());
         $this->addError(new Error('templates', $ids, $messages));
         return false;
     }
     if (is_array($ids) && count($ids) > 0) {
         $templateIdValidator = new UniqueIdValidator(DataTemplate::ID_PREFIX, DataTemplate::ID_SUFFIX);
         $templateIdValidator->setMessage("Template Id ist ungueltig", UniqueIdValidator::INVALID);
         foreach ($ids as $id) {
             if (!$templateIdValidator->isValid($id)) {
                 $messages = array_values($templateIdValidator->getMessages());
                 $this->addError(new Error('templates', $id, $messages));
                 return false;
             }
         }
         return true;
     }
     return true;
 }
Ejemplo n.º 26
0
 /**
  * @param string $id
  *
  * @throws \Cms\Exception
  * @return boolean
  */
 private function validateMediaId($id)
 {
     $mediaIdValidator = new UniqueIdValidator(DataMedia::ID_PREFIX, DataMedia::ID_SUFFIX);
     $mediaIdValidator->setMessage("Angegebene Media Id ist ungueltig", UniqueIdValidator::INVALID);
     if (!$mediaIdValidator->isValid($id)) {
         $messages = $mediaIdValidator->getMessages();
         throw new CmsException(10, __METHOD__, __LINE__, array('detail' => reset($messages)));
         return false;
     }
     return true;
 }
Ejemplo n.º 27
0
 /**
  * validate den paramter id
  *
  * @param string $id
  * @return boolean
  */
 private function validateId($id, $type)
 {
     // die ID ist kein Pflichtfeld -> Validierung nicht immer noetig
     $idRequired = true;
     if ($type == 'page') {
         $idValidator = new UniqueIdValidator(DataPage::ID_PREFIX, DataPage::ID_SUFFIX);
     } elseif ($type == 'template') {
         $idValidator = new UniqueIdValidator(DataTemplate::ID_PREFIX, DataTemplate::ID_SUFFIX);
     } else {
         $idRequired = false;
     }
     if ($idRequired && !$idValidator->isValid($id)) {
         $messages = array_values($idValidator->getMessages());
         $this->addError(new Error('id', $id, $messages));
         return false;
     }
     return true;
 }
Ejemplo n.º 28
0
 private function validateTemplateId($templateId)
 {
     $idValidator = new UniqueIdValidator(DataTemplate::ID_PREFIX, DataTemplate::ID_SUFFIX);
     if (!$idValidator->isValid($templateId)) {
         $messages = array_values($idValidator->getMessages());
         $this->addError(new Error('templateId', $templateId, $messages));
         return false;
     }
     return true;
 }
Ejemplo n.º 29
0
 /**
  */
 public function __construct()
 {
     parent::__construct(self::PREFIX, self::SUFFIX);
 }
Ejemplo n.º 30
0
 public function __construct()
 {
     parent::__construct(OrmTemplateSnippet::ID_PREFIX, OrmTemplateSnippet::ID_SUFFIX);
 }