/** * Test unpacking definition * * @author Sergey Startsev */ public function testUnPack() { $page_path_xml = $this->fixture()->getFileOwn('Page.xml'); $page_path_json = $this->fixture()->getFileOwn('Page.json'); $page_expected_definition = file_get_contents($page_path_json); $definition_xml = file_get_contents($page_path_xml); $definition_array = afsXmlDefinition::create()->init($definition_xml)->unpack()->get(); $this->assertTrue(is_array($definition_array), 'check get definition from afsXmlDefinition class, should return array'); $definition_json = json_encode($definition_array); $this->assertEquals($page_expected_definition, $definition_json, "actual and expected json definition doesn't match"); }
/** * Save page functionality * * @return afResponse * @author Sergey Startsev */ public function save() { $definition = afsXmlDefinition::create(); if ($this->isNew()) { $this->addAreaTopElement()->addTitleTopElement($this->getTitle()); $definition->init($this->getDefinition()); $definition->rootAttributes('layout'); } else { $definition->init($this->getDefinition()); } $definition->pack(); $status = $definition->validate(); if (is_bool($status) && $status) { $model_validator = afsPageModelValidator::create($this)->execute(); if (!$model_validator->isValid()) { return afResponseHelper::create()->success(false)->message($model_validator->getMessages(true)); } afStudioUtil::writeFile($this->getPagePath(), $definition->get()); $this->setNew(false); $this->createAction(); return afResponseHelper::create()->success(true); } return afResponseHelper::create()->success(false)->message($status); }
/** * Save widget definition * * @return afResponse * @author Sergey Startsev */ public function save() { $definition_array = $this->getDefinition(); $definition_array = afsWidgetModelOrderHelper::fixing($definition_array, $this->getType()); $definition = afsXmlDefinition::create()->init($definition_array); if ($this->isNew()) { $definition->rootAttributes($this->getType()); } $definition->pack(); // prepare folder for definition saving if (!file_exists($this->getPlaceConfigPath())) { afsFileSystem::create()->mkdirs($this->getPlaceConfigPath(), 0774); } if ($definition->validate()) { $model_validator = afsWidgetModelValidator::create($this)->execute(); if (!$model_validator->isValid()) { return afResponseHelper::create()->success(false)->message($model_validator->getMessages(true)); } afStudioUtil::writeFile($this->getPlaceConfigPath() . DIRECTORY_SEPARATOR . "{$this->getAction()}.xml", $definition->get()); \AppFlower\Studio\Cache\Widget::create()->update($this)->push(); $this->ensureSecurityExists(); // check exists action or not return afResponseHelper::create()->success($this->ensureActionExists()); } return afResponseHelper::create()->success(false)->message('Widget XML is not valid.'); }