/** * @param string $moduleId * @param array $defaultModuleValues * * @return ModuleData */ protected function createModuleData($moduleId, array $defaultModuleValues) { $module = new ModuleData(); $module->setId($moduleId); $module->setFormvalues((object) $defaultModuleValues); return $module; }
/** * @param string $websiteId * @param DataModule $module * * @return SourceItem */ protected function createSourceItemForNewModule($websiteId, DataModule $module) { $moduleId = $module->getId(); if (empty($moduleId)) { $module->setNewGeneratedId(); $moduleId = $module->getId(); } $baseDirectory = $this->getWebsiteModulesDataDirectory($websiteId); $baseUrl = $this->getWebsiteModulesUrl($websiteId); return new SourceItem($moduleId, FS::joinPath($baseDirectory, $moduleId), $baseUrl . '/' . $moduleId, SourceItem::SOURCE_LOCAL, false, true); }
/** * @param \Cms\Service\Modul $moduleService * @param DataModule $module * @param string $importModuleDataDirectoryPath */ protected function replaceTranslationFile($moduleService, DataModule $module, $importModuleDataDirectoryPath) { $importTranslationFile = FS::joinPath($importModuleDataDirectoryPath, 'moduleTranslation.php'); if (is_readable($importTranslationFile)) { $dataPath = $moduleService->getDataPath($module->getWebsiteid(), $module->getId()); $moduleTranslationFile = FS::joinPath($dataPath, 'moduleTranslation.php'); FS::copyFile($importTranslationFile, $moduleTranslationFile); } }
/** * @test * @group library */ public function test_getById_success() { // ARRANGE $dao = $this->createModuleDao(); $sources = $this->getModuleSourceItemsFromGlobalSetAndPackage('module_test', 'rz_testing'); $moduleSource = new ModuleSource($this->websiteId, $sources); $expectedModuleId = 'rz_tests_module_only_global'; $expectedModule = new DataModule(); $expectedModule->setSourceType(DataModule::SOURCE_REPOSITORY); $expectedModule->setOverwritten(false); $expectedModule->setId($expectedModuleId); $expectedModule->setName('this is the name: rz_tests_module_only_global (global)'); $expectedModule->setDescription(''); $expectedModule->setVersion('test'); $expectedModule->setIcon('application.png'); $expectedModule->setCategory('{"de":"Default Module","en":"Default Modules"}'); $expectedModule->setModuletype('default'); $expectedModule->setAllowedchildmoduletype('*'); $expectedModule->setRerenderrequired(true); $expectedModule->setApiType('APIv1'); $expectedModule->setSessionRequired(true); // ACT $module = $dao->getById($moduleSource, $expectedModuleId); // ASSERT $this->assertSame($expectedModule->getId(), $module->getId()); $this->assertSame($expectedModule->getSourceType(), $module->getSourceType()); $this->assertSame($expectedModule->isOverwritten(), $module->isOverwritten()); $this->assertSame($expectedModule->getName(), $module->getName()); $this->assertSame($expectedModule->getDescription(), $module->getDescription()); $this->assertSame($expectedModule->getVersion(), $module->getVersion()); $this->assertSame($expectedModule->getIcon(), $module->getIcon()); $this->assertSame($expectedModule->getCategory(), $module->getCategory()); $this->assertSame($expectedModule->getModuletype(), $module->getModuletype()); $this->assertSame($expectedModule->getAllowedchildmoduletype(), $module->getAllowedchildmoduletype()); $this->assertSame($expectedModule->getRerenderrequired(), $module->getRerenderrequired()); $this->assertSame($expectedModule->getApiType(), $module->getApiType()); $this->assertSame($expectedModule->getSessionRequired(), $module->getSessionRequired()); }
/** * @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()); }
/** * @param $data */ protected function setValuesFromData(Data\Modul $data) { $this->setId($data->getId()); $this->setWebsiteid($data->getWebsiteId()); $this->setName($data->getName()); $this->setDescription($data->getDescription()); $this->setVersion($data->getVersion()); $this->setIcon($data->getIcon()); $this->setForm($data->getForm()); $this->setFormvalues($data->getFormvalues()); $this->setCategory($data->getCategory()); $this->setModuletype($data->getModuletype()); $this->setAllowedchildmoduletype($data->getAllowedchildmoduletype()); $this->setReRenderRequired($data->getRerenderrequired()); $this->setSourceType($data->getSourceType()); $this->setOverwritten($data->isOverwritten()); $this->setGhostContainerMode($data->getGhostContainerMode()); }
/** * Copies the whole module to the export module directory * @param DataModule $module */ private function copyModule($module) { $moduleDirectory = $module->getSource()->getDirectory(); $exportModuleDirectory = $this->getExportModuleDirectory($module->getId()); if (!is_dir($moduleDirectory)) { Registry::getLogger()->log(__CLASS__, __METHOD__, sprintf("Error exporting module '%s/%s'. Module source directory '%s' not exists.", $module->getWebsiteid(), $module->getId(), $moduleDirectory), SbLog::ERR); return; } FS::createDirIfNotExists($exportModuleDirectory, true); FS::copyDir($moduleDirectory, $exportModuleDirectory); }
/** * @param string $websiteId * @param string $moduleId * @param array $attributes * * @return ModulData */ protected function createModuleDataObject($websiteId, $moduleId, array $attributes = array()) { $module = new ModulData(); $module->setWebsiteid($websiteId); $module->setId($moduleId); if (array_key_exists('name', $attributes)) { $module->setName($attributes['name']); } if (array_key_exists('moduleType', $attributes)) { $module->setModuletype($attributes['moduleType']); } if (array_key_exists('form', $attributes)) { $module->setForm($attributes['form']); } if (array_key_exists('formValues', $attributes)) { $module->setFormvalues($attributes['formValues']); } return $module; }
/** * @test * @group library */ public function getAllShouldRetrieveExpectedModules() { $sortedIndex = array(1, 2, 0); /** @var \Cms\Data\Modul[] $creates */ $creates = array(); $newModule = new DataModule(); $newModule->setName(__METHOD__ . '_3'); $newModule->setDescription('TEST_DESCRIPTION_GET_ALL_3'); $newModule->setVersion('TEST_VERSION_GET_ALL_3'); $newModule->setIcon('TEST_ICON_GET_ALL_3'); $newModule->setForm(array()); $newModule->setFormvalues(SbJson::decode(SbJson::encode(array('foo' => 'bar')))); $newModule->setCategory('TEST_CATEGORY_GET_ALL_3'); $newModule->setModuletype('default'); $newModule->setAllowedchildmoduletype('extension'); $creates[] = $newModule; $newModule = new DataModule(); $newModule->setName(__METHOD__ . '_1'); $newModule->setDescription('TEST_DESCRIPTION_GET_ALL_1'); $newModule->setVersion('TEST_VERSION_GET_ALL_1'); $newModule->setIcon('TEST_ICON_GET_ALL_1'); $newModule->setForm(SbJson::decode(SbJson::encode(array(array('id' => 'abcdefg', 'name' => 'Titel und Beschreibung'))))); $newModule->setFormvalues(new \stdClass()); $newModule->setCategory('TEST_CATEGORY_GET_ALL_1'); $newModule->setModuletype('root'); $newModule->setAllowedchildmoduletype('*'); $creates[] = $newModule; $newModule = new DataModule(); $newModule->setName(__METHOD__ . '_2'); $newModule->setDescription('TEST_DESCRIPTION_GET_ALL_2'); $newModule->setVersion('TEST_VERSION_GET_ALL_2'); $newModule->setIcon('TEST_ICON_GET_ALL_2'); $newModule->setForm(array()); $newModule->setFormvalues(SbJson::decode(SbJson::encode(array('asdf' => 0)))); $newModule->setCategory('TEST_CATEGORY_GET_ALL_2'); $newModule->setModuletype('default'); $newModule->setAllowedchildmoduletype('extension'); $creates[] = $newModule; $moduleIds = array(); foreach ($creates as $create) { $createdModul = $this->service->create($this->websiteId, $create); $moduleIds[] = $createdModul->getId(); } /** @var \Cms\Data\Modul[] $modules */ $modules = $this->service->getAll($this->websiteId); /** @var \Cms\Data\Modul[] $createdModules */ $createdModules = array(); foreach ($modules as $module) { if ($module->getName() === $creates[0]->getName() || $module->getName() === $creates[1]->getName() || $module->getName() === $creates[2]->getName()) { $createdModules[] = $module; } } foreach ($createdModules as $returnedIndex => $module) { $index = $sortedIndex[$returnedIndex]; $this->assertInstanceOf('Cms\\Data\\Modul', $module); $this->assertSame($creates[$index]->getName(), $module->getName()); $this->assertSame($creates[$index]->getDescription(), $module->getDescription()); $this->assertSame($creates[$index]->getVersion(), $module->getVersion()); $this->assertSame($creates[$index]->getIcon(), $module->getIcon()); $this->assertEquals($creates[$index]->getForm(), $module->getForm()); $this->assertEquals($creates[$index]->getFormvalues(), $module->getFormvalues()); $this->assertSame($creates[$index]->getCategory(), $module->getCategory()); $this->assertSame($creates[$index]->getModuletype(), $module->getModuletype()); $this->assertSame($creates[$index]->getAllowedchildmoduletype(), $module->getAllowedchildmoduletype()); $uuidValidator = new UniqueIdValidator(\Orm\Data\Modul::ID_PREFIX, \Orm\Data\Modul::ID_SUFFIX); $this->assertTrue($uuidValidator->isValid($module->getId())); } }