/** * Test * * @return void */ public function testFromId() { $this->assertInstanceOf('Gc\\Property\\Model', Model::fromId($this->object->getId())); }
/** * Test * * @return void */ public function testExport() { $this->createUser(); $this->createContent(); $result = $this->object->export($this->what); $this->assertInternalType('string', $result); $dom = new SimpleXMLElement($result); //Test documents $this->assertContains('<documents>', $result); $xpath = $dom->xpath('/gotcms/documents/document[@id="' . $this->document->getId() . '"]/name'); $this->assertEquals($this->document->getName(), (string) $xpath[0]); $xpath = $dom->xpath('/gotcms/documents/document[@id="' . $this->document->getId() . '"]/url_key'); $this->assertEquals('', (string) $xpath[0]); $xpath = $dom->xpath('/gotcms/documents/document[@id="' . $this->document->getId() . '"]/document_type_id'); $this->assertEquals($this->document->getDocumentTypeId(), (string) $xpath[0]); $xpath = $dom->xpath('/gotcms/documents/document[@id="' . $this->document->getId() . '"]/layout_id'); $this->assertEquals($this->document->getLayoutId(), (string) $xpath[0]); $xpath = $dom->xpath('/gotcms/documents/document[@id="' . $this->document->getId() . '"]/view_id'); $this->assertEquals($this->document->getViewId(), (string) $xpath[0]); $xpath = $dom->xpath('/gotcms/documents/document[@id="' . $this->document->getId() . '"]/parent_id'); $this->assertEquals($this->document->getParentId(), (string) $xpath[0]); //Test documents properties $this->assertContains('<properties>', $result); $xpath = $dom->xpath('/gotcms/documents/document[@id="' . $this->document->getId() . '"]/properties/property_value[@id="' . $this->property->getValueModel()->getId() . '"]/document_id'); $this->assertEquals($this->document->getId(), (string) $xpath[0]); $xpath = $dom->xpath('/gotcms/documents/document[@id="' . $this->document->getId() . '"]/properties/property_value[@id="' . $this->property->getValueModel()->getId() . '"]/property_id'); $this->assertEquals($this->property->getId(), (string) $xpath[0]); $xpath = $dom->xpath('/gotcms/documents/document[@id="' . $this->document->getId() . '"]/properties/property_value[@id="' . $this->property->getValueModel()->getId() . '"]/value'); $this->assertEquals(base64_encode($this->property->getValueModel()->getValue()), (string) $xpath[0]); //Test document types $this->assertContains('<document_types>', $result); $xpath = $dom->xpath('/gotcms/document_types/document_type[@id="' . $this->documentType->getId() . '"]/name'); $this->assertEquals($this->documentType->getName(), (string) $xpath[0]); $xpath = $dom->xpath('/gotcms/document_types/document_type[@id="' . $this->documentType->getId() . '"]/description'); $this->assertEquals($this->documentType->getDescription(), (string) $xpath[0]); $xpath = $dom->xpath('/gotcms/document_types/document_type[@id="' . $this->documentType->getId() . '"]/icon_id'); $this->assertEquals($this->documentType->getIconId(), (string) $xpath[0]); $xpath = $dom->xpath('/gotcms/document_types/document_type[@id="' . $this->documentType->getId() . '"]/default_view_id'); $this->assertEquals($this->documentType->getDefaultViewId(), (string) $xpath[0]); $xpath = $dom->xpath('/gotcms/document_types/document_type[@id="' . $this->documentType->getId() . '"]/user_id'); $this->assertEquals($this->documentType->getUserId(), (string) $xpath[0]); $xpath = $dom->xpath('/gotcms/document_types/document_type[@id="' . $this->documentType->getId() . '"]/tabs/tab[@id="' . $this->tabModel->getId() . '"]/name'); $this->assertEquals($this->tabModel->getName(), (string) $xpath[0]); $xpath = $dom->xpath('/gotcms/document_types/document_type[@id="' . $this->documentType->getId() . '"]/tabs/tab[@id="' . $this->tabModel->getId() . '"]/description'); $this->assertEquals($this->tabModel->getDescription(), (string) $xpath[0]); $xpath = $dom->xpath('/gotcms/document_types/document_type[@id="' . $this->documentType->getId() . '"]/tabs/tab[@id="' . $this->tabModel->getId() . '"]/properties/property[@id="' . $this->property->getId() . '"]/name'); $this->assertEquals($this->property->getName(), (string) $xpath[0]); $xpath = $dom->xpath('/gotcms/document_types/document_type[@id="' . $this->documentType->getId() . '"]/tabs/tab[@id="' . $this->tabModel->getId() . '"]/properties/property[@id="' . $this->property->getId() . '"]/identifier'); $this->assertEquals($this->property->getIdentifier(), (string) $xpath[0]); $xpath = $dom->xpath('/gotcms/document_types/document_type[@id="' . $this->documentType->getId() . '"]/tabs/tab[@id="' . $this->tabModel->getId() . '"]/properties/property[@id="' . $this->property->getId() . '"]/description'); $this->assertEquals($this->property->getDescription(), (string) $xpath[0]); $xpath = $dom->xpath('/gotcms/document_types/document_type[@id="' . $this->documentType->getId() . '"]/tabs/tab[@id="' . $this->tabModel->getId() . '"]/properties/property[@id="' . $this->property->getId() . '"]/required'); $this->assertEquals((int) $this->property->getRequired(), (int) $xpath[0]); $this->assertEquals((int) $this->property->getRequired(), (int) $xpath[0]); $xpath = $dom->xpath('/gotcms/document_types/document_type[@id="' . $this->documentType->getId() . '"]/tabs/tab[@id="' . $this->tabModel->getId() . '"]/properties/property[@id="' . $this->property->getId() . '"]/datatype_id'); $this->assertEquals($this->datatype->getId(), (string) $xpath[0]); $xpath = $dom->xpath('/gotcms/document_types/document_type[@id="' . $this->documentType->getId() . '"]/dependencies/id[text()="' . $this->documentType->getId() . '"]'); $this->assertEquals($this->documentType->getId(), (string) $xpath[0]); $xpath = $dom->xpath('/gotcms/document_types/document_type[@id="' . $this->documentType->getId() . '"]/available_views/id[text()="' . $this->view->getId() . '"]'); $this->assertEquals($this->view->getId(), (string) $xpath[0]); //Test views $this->assertContains('<views>', $result); $xpath = $dom->xpath('/gotcms/views/view[@id="' . $this->view->getId() . '"]/name'); $this->assertEquals($this->view->getName(), (string) $xpath[0]); $xpath = $dom->xpath('/gotcms/views/view[@id="' . $this->view->getId() . '"]/identifier'); $this->assertEquals($this->view->getIdentifier(), (string) $xpath[0]); $xpath = $dom->xpath('/gotcms/views/view[@id="' . $this->view->getId() . '"]/description'); $this->assertEquals($this->view->getDescription(), (string) $xpath[0]); $xpath = $dom->xpath('/gotcms/views/view[@id="' . $this->view->getId() . '"]/content'); $this->assertEquals($this->view->getContent(), (string) $xpath[0]); //Test layouts $this->assertContains('<views>', $result); $xpath = $dom->xpath('/gotcms/layouts/layout[@id="' . $this->layout->getId() . '"]/name'); $this->assertEquals($this->layout->getName(), (string) $xpath[0]); $xpath = $dom->xpath('/gotcms/layouts/layout[@id="' . $this->layout->getId() . '"]/identifier'); $this->assertEquals($this->layout->getIdentifier(), (string) $xpath[0]); $xpath = $dom->xpath('/gotcms/layouts/layout[@id="' . $this->layout->getId() . '"]/description'); $this->assertEquals($this->layout->getDescription(), (string) $xpath[0]); $xpath = $dom->xpath('/gotcms/layouts/layout[@id="' . $this->layout->getId() . '"]/content'); $this->assertEquals($this->layout->getContent(), (string) $xpath[0]); //Test scripts $this->assertContains('<views>', $result); $xpath = $dom->xpath('/gotcms/scripts/script[@id="' . $this->script->getId() . '"]/name'); $this->assertEquals($this->script->getName(), (string) $xpath[0]); $xpath = $dom->xpath('/gotcms/scripts/script[@id="' . $this->script->getId() . '"]/identifier'); $this->assertEquals($this->script->getIdentifier(), (string) $xpath[0]); $xpath = $dom->xpath('/gotcms/scripts/script[@id="' . $this->script->getId() . '"]/description'); $this->assertEquals($this->script->getDescription(), (string) $xpath[0]); $xpath = $dom->xpath('/gotcms/scripts/script[@id="' . $this->script->getId() . '"]/content'); $this->assertEquals($this->script->getContent(), (string) $xpath[0]); //Test datatype $this->assertContains('<views>', $result); $xpath = $dom->xpath('/gotcms/datatypes/datatype[@id="' . $this->datatype->getId() . '"]/name'); $this->assertEquals($this->datatype->getName(), (string) $xpath[0]); $xpath = $dom->xpath('/gotcms/datatypes/datatype[@id="' . $this->datatype->getId() . '"]/prevalue_value'); $this->assertEquals($this->datatype->getPrevalueValue(), (string) unserialize($xpath[0])); $xpath = $dom->xpath('/gotcms/datatypes/datatype[@id="' . $this->datatype->getId() . '"]/model'); $this->assertEquals($this->datatype->getModel(), (string) $xpath[0]); $this->removeContent(); $this->removeUser(); }
/** * Test * * @return void */ public function testLoad() { $this->assertInstanceOf('Gc\\Property\\Value\\Model', $this->object->load($this->object->getId(), $this->document->getId(), $this->property->getId())); }
/** * Save properties * * @param Zend\InputFilter\InputFilter $propertiesSubform Properties sub form * @param array $existingTabs Array of tabs * * @return array */ protected function saveProperties($propertiesSubform, $existingTabs) { $existingProperties = array(); $idx = 0; foreach ($propertiesSubform->getValidInput() as $propertyId => $propertyValues) { if (!preg_match('~^property(\\d+)$~', $propertyId, $matches)) { continue; } $propertyId = $matches[1]; $propertyModel = Property\Model::fromId($propertyId); if (empty($propertyModel) or !in_array($propertyModel->getTabId(), $existingTabs)) { $propertyModel = new Property\Model(); } $propertyModel->setDescription($propertyValues->getValue('description')); $propertyModel->setName($propertyValues->getValue('name')); $propertyModel->setIdentifier($propertyValues->getValue('identifier')); $propertyModel->setTabId($existingTabs[$propertyValues->getValue('tab')]); $propertyModel->setDatatypeId($propertyValues->getValue('datatype')); $required = $propertyValues->getValue('required'); $propertyModel->isRequired(!empty($required) ? true : false); $propertyModel->setSortOrder(++$idx); $propertyModel->save(); $existingProperties[] = $propertyModel->getId(); } return $existingProperties; }
/** * Import Document types * * @param array &$ids Ids * @param array &$errors Errors * @param array $children Children list * * @return void */ protected function importDocumentTypes(&$ids, &$errors, $children) { $documentTypes = array(); foreach ($children['children'] as $child) { $attributes = $child->attributes(); $id = (int) $attributes['id']; $model = DocumentType\Model::fromId($id); if (empty($model)) { $model = new DocumentType\Model(); } $viewid = isset($ids['views'][(int) $child->default_view_id]) ? $ids['views'][(int) $child->default_view_id] : (int) $child->default_view_id; $name = (string) $child->name; $model->addData(array('name' => empty($name) ? $model->getName() : $name, 'description' => (string) $child->description, 'icon_id' => (int) $child->icon_id, 'default_view_id' => $viewid)); if ($model->getUserId() === null) { $model->setUserId($this->serviceLocator->get('Auth')->getIdentity()->getId()); } try { if (!empty($model)) { $model->save(); $tabs = (array) $child->tabs; if (isset($tabs['tab']) and is_array($tabs['tab'])) { $tabs = $tabs['tab']; } foreach ($tabs as $tab) { $tabAttributes = $tab->attributes(); $tabId = (int) $tabAttributes['id']; $tabModel = Tab\Model::fromId($tabId); if (empty($tabModel)) { $tabModel = new Tab\Model(); } $tabModel->addData(array('name' => (string) $tab->name, 'description' => (string) $tab->description, 'sort_order' => (int) $tab->sort_order, 'document_type_id' => $model->getId())); $tabModel->save(); $properties = (array) $tab->properties; if (isset($properties['property']) and is_array($properties['property'])) { $properties = $properties['property']; } foreach ($properties as $property) { $propAttributes = $property->attributes(); $propertyId = (int) $propAttributes['id']; $propertyModel = Property\Model::fromId($propertyId); if (empty($propertyModel)) { $propertyModel = new Property\Model(); } $datatypeId = isset($ids['datatypes'][(int) $property->datatype_id]) ? $ids['datatypes'][(int) $property->datatype_id] : (string) $property->datatype_id; $propertyModel->addData(array('name' => (string) $property->name, 'description' => (string) $property->description, 'identifier' => (string) $property->identifier, 'sort_order' => (int) $property->sort_order, 'tab_id' => $tabModel->getId(), 'datatype_id' => $datatypeId)); $propertyModel->save(); $ids['properties'][$propertyId] = $propertyModel->getId(); } } $ids['document_types'][$id] = $model->getId(); $documentTypes[] = array('model' => $model, 'dependencies' => (array) $child->dependencies, 'views' => (array) $child->available_views); } } catch (Exception $e) { $errors[] = sprintf($this->serviceLocator->get('MvcTranslator')->translate('Cannot save document type with id (%d)'), $id); } } return $documentTypes; }
/** * Test * * @return void */ public function testGetName() { $this->assertEquals('datatype' . $this->property->getId(), $this->object->getName()); }