Пример #1
0
 protected function getServiceWithDaoMock($allowCallDaoMethods)
 {
     $testService = new ModuleService('Modul');
     $daoMock = $this->getMock('\\Cms\\Dao\\Module');
     // getById
     $daoMock->expects($this->any())->method('getById')->will($this->returnValue($this->getMock('\\Cms\\Data\\Modul')));
     if ($allowCallDaoMethods == true) {
         $daoMock->expects($this->any())->method($this->anything());
     } else {
         $daoMock->expects($this->never())->method($this->anything());
     }
     /** @noinspection PhpParamsInspection */
     $testService->setDao($daoMock);
     return $testService;
 }
Пример #2
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());
 }
Пример #3
0
 /**
  * @param  string  $websiteId
  * @param  string  $modulId
  * @param  array   $files
  * @return boolean
  */
 protected function createTestAssets($websiteId, $modulId, array $files)
 {
     $config = Registry::getConfig();
     $moduleAssetsDirectory = $this->moduleService->getAssetsPath($websiteId, $modulId);
     if (is_dir($moduleAssetsDirectory)) {
         foreach ($files as $name) {
             if (strstr($name, DIRECTORY_SEPARATOR)) {
                 $testAssetDirectory = $moduleAssetsDirectory . DIRECTORY_SEPARATOR . dirname($name);
                 mkdir($testAssetDirectory);
             }
             $testAssetFile = $moduleAssetsDirectory . DIRECTORY_SEPARATOR . $name;
             file_put_contents($testAssetFile, '');
         }
         return true;
     }
     return false;
 }
Пример #4
0
 /**
  * @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);
     }
 }
Пример #5
0
 /**
  * Aktualisiert die Default-Werte in den globalen Variablen
  *
  * @param string $websiteId
  * @param mixed  $globalcontent
  * @param \Cms\Service\Modul
  */
 public function insertDefaultValuesIntoGlobalContent($websiteId, &$globalContent, \Cms\Service\Modul $moduleService)
 {
     // ggf. Globale Variablen in Array umwandeln
     if (is_string($globalContent)) {
         $globalContent = \Zend_Json::decode($globalContent);
     }
     if (is_array($globalContent) && count($globalContent) > 0) {
         foreach ($globalContent as $varName => &$units) {
             foreach ($units as &$unitData) {
                 // Modul-Id vorhanden?
                 if (isset($unitData['moduleId'])) {
                     // Muss noch die globalen Variablen-Namen dieses Moduls ermittelt werden?
                     if (isset($unitData['moduleId']) && !empty($unitData['moduleId']) && !isset($this->moduleFormValues[$websiteId][$unitData['moduleId']])) {
                         // Form-Werte des Moduls ermitteln
                         try {
                             $module = $moduleService->getById($unitData['moduleId'], $websiteId);
                             $formValues = $module->getFormvalues();
                             if (is_string($formValues)) {
                                 $formValues = \Zend_Json::decode($formValues);
                             }
                             $this->moduleFormValues[$websiteId][$unitData['moduleId']] = $formValues;
                         } catch (\Exception $e) {
                         }
                     }
                     // Globale Felder vorhanden
                     if (is_array($this->moduleFormValues[$websiteId][$unitData['moduleId']]) && count($this->moduleFormValues[$websiteId][$unitData['moduleId']]) > 0) {
                         // Modul-Wert des globalen Feldes vorhanden?
                         if (isset($unitData['isUnitValue']) && !$unitData['isUnitValue']) {
                             if (isset($this->moduleFormValues[$websiteId][$unitData['moduleId']][$varName])) {
                                 $unitData['value'] = $this->moduleFormValues[$websiteId][$unitData['moduleId']][$varName];
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Пример #6
0
 /**
  * @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()));
     }
 }