Ejemplo n.º 1
0
 /**
  * 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();
 }
Ejemplo n.º 2
0
 /**
  * Import Documents
  *
  * @param array &$ids     Ids
  * @param array &$errors  Errors
  * @param array $children Children list
  *
  * @return void
  */
 protected function importDocuments(&$ids, &$errors, $children)
 {
     foreach ($children['children'] as $child) {
         $urlKey = (string) $child->url_key;
         $model = Document\Model::fromUrlKey($urlKey);
         $attributes = $child->attributes();
         $id = (int) $attributes['id'];
         if (empty($model)) {
             $model = Document\Model::fromId($id);
             if (empty($model)) {
                 $model = new Document\Model();
             }
         }
         $documentTypeId = isset($ids['document_types'][(int) $child->document_type_id]) ? $ids['document_types'][(int) $child->document_type_id] : $model->getDocumentTypeId();
         $viewId = isset($ids['views'][(int) $child->view_id]) ? $ids['views'][(int) $child->view_id] : $model->getViewId();
         $layoutId = isset($ids['layouts'][(int) $child->layout_id]) ? $ids['layouts'][(int) $child->layout_id] : $model->getLayoutId();
         $parentId = isset($ids['layouts'][(int) $child->parent_id]) ? $ids['layouts'][(int) $child->parent_id] : $model->getParentId();
         $name = (string) $child->name;
         $status = (string) $child->status;
         $userId = (int) $child->user_id;
         $sortOrder = (int) $child->sort_order;
         $showInNav = (int) $child->show_in_nav;
         $model->addData(array('name' => empty($name) ? $model->getName() : $name, 'url_key' => $urlKey, 'status' => empty($status) ? $model->getStatus() : $status, 'show_in_nav' => empty($showInNav) ? $model->getShowInNav() : $showInNav, 'sort_order' => empty($sortOrder) ? $model->getSortOrder() : $sortOrder, 'icon_id' => (int) $child->icon_id, 'view_id' => $viewId, 'parent_id' => $parentId, 'user_id' => $userId, 'layout_id' => $layoutId, 'document_type_id' => empty($documentTypeId) ? $model->getDocumentTypeId() : $documentTypeId));
         if ($model->getUserId() === null) {
             $model->setUserId($this->serviceLocator->get('Auth')->getIdentity()->getId());
         }
         try {
             if (!empty($model)) {
                 $model->save();
                 $ids['documents'][$id] = $model->getId();
                 $values = (array) $child->properties;
                 if (isset($values['property_value']) and is_array($values['property_value'])) {
                     $values = $values['property_value'];
                 }
                 foreach ($values as $value) {
                     $documentId = (int) $value->document_id;
                     $propertyId = (int) $value->property_id;
                     $valueModel = new Property\Value\Model();
                     $valueModel->load(null, isset($ids['documents'][$documentId]) ? $ids['documents'][$documentId] : $documentId, isset($ids['properties'][$propertyId]) ? $ids['properties'][$propertyId] : $propertyId);
                     $valueModel->setValue((string) base64_decode($value->value));
                     $valueModel->save();
                 }
             }
         } catch (Exception $e) {
             $errors[] = sprintf($this->serviceLocator->get('MvcTranslator')->translate('Cannot save document with id (%d)'), $id);
         }
     }
 }