protected function createContent() { $this->view = ViewModel::fromArray(array('name' => 'View', 'identifier' => 'ViewContentIdentifier', 'description' => 'Description', 'content' => 'Content of the webpage <br/>This is my view')); $this->view->save(); $this->layout = LayoutModel::fromArray(array('name' => 'Layout', 'identifier' => 'LayoutContentIdentifier', 'description' => 'Description', 'content' => '<?php echo $this->content; ')); $this->layout->save(); $this->script = ScriptModel::fromArray(array('name' => 'Script', 'identifier' => 'ScriptContentIdentifier', 'description' => 'Description', 'content' => '')); $this->script->save(); $this->documentType = DocumentTypeModel::fromArray(array('name' => 'DocumentType', 'description' => 'description', 'icon_id' => 1, 'default_view_id' => $this->view->getId(), 'user_id' => $this->user->getId())); $this->documentType->save(); $this->documentType->setDependencies(array($this->documentType->getId())); $this->documentType->addView($this->view->getId()); $this->documentType->save(); $this->datatype = DatatypeModel::fromArray(array('name' => 'DatatypeTest', 'model' => 'Textstring')); $this->datatype->save(); $this->tabModel = TabModel::fromArray(array('name' => 'test', 'description' => 'test', 'document_type_id' => $this->documentType->getId())); $this->tabModel->save(); $this->property = PropertyModel::fromArray(array('name' => 'test', 'identifier' => 'azd', 'description' => 'test', 'tab_id' => $this->tabModel->getId(), 'datatype_id' => $this->datatype->getId(), 'is_required' => true)); $this->property->save(); $this->document = DocumentModel::fromArray(array('name' => 'test', 'url_key' => '', 'status' => DocumentModel::STATUS_ENABLE, 'user_id' => $this->user->getId(), 'document_type_id' => $this->documentType->getId(), 'view_id' => $this->view->getId(), 'layout_id' => $this->layout->getId(), 'parent_id' => null)); $this->document->save(); $this->property->setDocumentId($this->document->getId()); $this->property->setValue('string'); $this->property->saveValue(); }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. * * @return void */ protected function setUp() { $this->view = ViewModel::fromArray(array('name' => 'View Name', 'identifier' => 'View identifier', 'description' => 'View Description', 'content' => 'View Content')); $this->view->save(); $this->layout = LayoutModel::fromArray(array('name' => 'Layout Name', 'identifier' => 'Layout identifier', 'description' => 'Layout Description', 'content' => 'Layout Content')); $this->layout->save(); $this->user = UserModel::fromArray(array('lastname' => 'User test', 'firstname' => 'User test', 'email' => '*****@*****.**', 'login' => 'test', 'user_acl_role_id' => 1)); $this->user->setPassword('test'); $this->user->save(); $this->documentType = DocumentTypeModel::fromArray(array('name' => 'Document Type Name', 'description' => 'Document Type description', 'icon_id' => 1, 'defaultview_id' => $this->view->getId(), 'user_id' => $this->user->getId())); $this->documentType->save(); $this->datatype = DatatypeModel::fromArray(array('name' => 'jQueryFileUploadTest', 'prevalue_value' => '', 'model' => 'jQueryFileUpload')); $this->datatype->save(); $this->tab = TabModel::fromArray(array('name' => 'TabTest', 'description' => 'TabTest', 'sort_order' => 1, 'document_type_id' => $this->documentType->getId())); $this->tab->save(); $this->property = PropertyModel::fromArray(array('name' => 'DatatypeTest', 'identifier' => 'DatatypeTest', 'description' => 'DatatypeTest', 'required' => false, 'sort_order' => 1, 'tab_id' => $this->tab->getId(), 'datatype_id' => $this->datatype->getId())); $this->property->save(); $this->document = DocumentModel::fromArray(array('name' => 'jQueryFileUploadTest', 'url_key' => '/jqueryfileupload-test', 'status' => DocumentModel::STATUS_ENABLE, 'sort_order' => 1, 'show_in_nav' => false, 'user_id' => $this->user->getId(), 'document_type_id' => $this->documentType->getId(), 'view_id' => $this->view->getId(), 'layout_id' => $this->layout->getId(), 'parent_id' => 0)); $this->document->save(); $datatype = new Datatype(); $application = Registry::get('Application'); $datatype->setRequest($application->getServiceManager()->get('Request')); $datatype->setRouter($application->getServiceManager()->get('Router')); $datatype->setHelperManager($application->getServiceManager()->get('viewhelpermanager')); $datatype->load($this->datatype, $this->document->getId()); $this->object = $datatype->getEditor($this->property); }
/** * Test * * @return void */ public function testSortOrderAction() { $this->dispatch('/admin/content/document/sort', 'POST', array('order' => 'document_' . $this->document->getId())); $this->assertResponseStatusCode(200); $this->assertModuleName('GcContent'); $this->assertControllerName('DocumentController'); $this->assertControllerClass('DocumentController'); $this->assertMatchedRouteName('content/document/sort'); }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. * * @return void */ protected function setUp() { $this->view = ViewModel::fromArray(array('name' => 'View Name', 'identifier' => 'View identifier', 'description' => 'View Description', 'content' => 'View Content')); $this->view->save(); $this->layout = LayoutModel::fromArray(array('name' => 'Layout Name', 'identifier' => 'Layout identifier', 'description' => 'Layout Description', 'content' => 'Layout Content')); $this->layout->save(); $this->user = UserModel::fromArray(array('lastname' => 'User test', 'firstname' => 'User test', 'email' => '*****@*****.**', 'login' => 'test', 'user_acl_role_id' => 1)); $this->user->setPassword('test'); $this->user->save(); $this->documentType = DocumentTypeModel::fromArray(array('name' => 'Document Type Name', 'description' => 'Document Type description', 'icon_id' => 1, 'defaultview_id' => $this->view->getId(), 'user_id' => $this->user->getId())); $this->documentType->save(); $this->document = DocumentModel::fromArray(array('name' => 'Document name', 'url_key' => 'url-key', 'status' => DocumentModel::STATUS_ENABLE, 'show_in_nav' => true, 'user_id' => $this->user->getId(), 'document_type_id' => $this->documentType->getId(), 'view_id' => $this->view->getId(), 'layout_id' => $this->layout->getId())); $this->document->save(); $this->documentChildren = DocumentModel::fromArray(array('name' => 'Document name', 'url_key' => 'url-key', 'status' => DocumentModel::STATUS_ENABLE, 'show_in_nav' => true, 'user_id' => $this->user->getId(), 'document_type_id' => $this->documentType->getId(), 'view_id' => $this->view->getId(), 'layout_id' => $this->layout->getId(), 'parent_id' => $this->document->getId())); $this->documentChildren->save(); $this->object = new TreeView(); }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. * * @return void */ protected function setUp() { $this->view = ViewModel::fromArray(array('name' => 'View Name', 'identifier' => 'View identifier', 'description' => 'View Description', 'content' => 'View Content')); $this->view->save(); $this->layout = LayoutModel::fromArray(array('name' => 'Layout Name', 'identifier' => 'Layout identifier', 'description' => 'Layout Description', 'content' => 'Layout Content')); $this->layout->save(); $this->user = UserModel::fromArray(array('lastname' => 'User test', 'firstname' => 'User test', 'email' => '*****@*****.**', 'login' => 'test', 'user_acl_role_id' => 1)); $this->user->setPassword('test'); $this->user->save(); $this->documentType = DocumentTypeModel::fromArray(array('name' => 'Document Type Name', 'description' => 'Document Type description', 'icon_id' => 1, 'defaultview_id' => $this->view->getId(), 'user_id' => $this->user->getId())); $this->documentType->save(); $this->document = DocumentModel::fromArray(array('name' => 'Document name', 'url_key' => 'url-key', 'status' => DocumentModel::STATUS_ENABLE, 'show_in_nav' => true, 'user_id' => $this->user->getId(), 'document_type_id' => $this->documentType->getId(), 'view_id' => $this->view->getId(), 'layout_id' => $this->layout->getId(), 'parent_id' => null)); $this->document->save(); $this->renderer = new PhpRenderer(); $renderer = Registry::get('Application')->getServiceManager()->get('Zend\\View\\Renderer\\PhpRenderer'); $this->renderer->setHelperPluginManager(clone $renderer->getHelperPluginManager()); $this->renderer->layout()->currentDocument = DocumentModel::fromArray(array('id' => $this->document->getId())); $this->module = ModuleModel::fromArray(array('name' => 'Blog')); $this->module->save(); $this->boostrap = new Module(); $this->boostrap->install(); $this->object = new CommentList(); $this->object->plugin('layout')->setController($this->getMockForAbstractClass('\\Zend\\Mvc\\Controller\\AbstractController')); }
/** * Test * * @return void */ public function testAddWithWrongValues() { $data = array('message' => '', 'username' => '', 'email' => ''); $this->assertFalse($this->object->add($data, $this->document->getId())); }
/** * Test * * @return void */ public function testInvokeWithParameters() { $this->assertInternalType('array', $this->object->__invoke(1)); $this->assertInternalType('array', $this->object->__invoke('url-key')); $this->assertInternalType('array', $this->object->__invoke(array(0, $this->document->getId()))); }
/** * Load properties from document type, tab and document * * @param integer $documentTypeId Document type id * @param DocumentModel $document Document model * @param ServiceManager $serviceLocator Service manager * * @return array */ public function load($documentTypeId, DocumentModel $document, ServiceManager $serviceLocator) { $tabs = $this->loadTabs($documentTypeId); $tabsArray = array(); $idx = 1; foreach ($tabs as $tab) { $tabsArray[] = $tab->getName(); $properties = $this->loadProperties($documentTypeId, $tab->getId(), $document->getId()); $fieldset = new ZendForm\Fieldset('tabs-' . $idx); foreach ($properties as $property) { $elements = AbstractForm::addContent($fieldset, Datatype\Model::loadEditor($serviceLocator, $property)); if (!is_array($elements)) { $elements = array($elements); } foreach ($elements as $element) { if (empty($element)) { continue; } $element->setOption('required', $property->isRequired()); $element->setOption('description', $property->getDescription()); } } $this->add($fieldset); $idx++; } $formDocumentAdd = new DocumentInformation(); $formDocumentAdd->load($document, $serviceLocator->get('Config')); $formDocumentAdd->setAttribute('name', 'tabs-' . $idx); $this->add($formDocumentAdd); return $tabsArray; }
/** * Test * * @return void */ public function testGetIterableId() { $this->assertEquals('document_' . $this->object->getId(), $this->object->getIterableId()); }
/** * Test * * @return void */ public function testLoadWithParentId() { $this->object->load($this->document->getId()); $this->assertInternalType('array', $this->object->getDocuments()); }
/** * Test * * @return void */ public function testLoad() { $this->assertInstanceOf('Gc\\Property\\Value\\Model', $this->object->load($this->object->getId(), $this->document->getId(), $this->property->getId())); }
/** * Load document form from DocumentModel * * @param DocumentModel $document Document model * @param array $config Configuration * * @return void */ public function load(DocumentModel $document, array $config) { $this->get('document-name')->setValue($document->getName()); $this->get('document-url_key')->setValue($document->getUrlKey()); $status = new Element\Checkbox('document-status'); $status->setLabel('Publish')->setValue($document->isPublished())->setAttribute('id', 'status')->setAttribute('class', 'input-checkbox')->setCheckedValue((string) DocumentModel::STATUS_ENABLE); $this->add($status); $showInNav = new Element\Checkbox('document-show_in_nav'); $showInNav->setLabel('Show in nav')->setValue($document->showInNav())->setAttribute('id', 'show_in_nav')->setAttribute('class', 'input-checkbox')->setCheckedValue((string) DocumentModel::STATUS_ENABLE); $this->add($showInNav); $canBeCached = new Element\Checkbox('document-can_be_cached'); $canBeCached->setLabel('Can be cached')->setValue($document->canBeCached())->setAttribute('id', 'can_be_cached')->setAttribute('class', 'input-checkbox')->setCheckedValue((string) DocumentModel::STATUS_ENABLE); $this->add($canBeCached); array_unshift($config['locales'], '-- Use parent configuration'); $locale = new Element\Select('document-locale'); $locale->setLabel('Locale')->setValueOptions($config['locales'])->setValue($document->getLocale())->setAttribute('id', 'locale')->setAttribute('class', 'form-control'); $this->add($locale); $documentType = $document->getDocumentType(); $viewsCollection = $documentType->getAvailableViews(); $select = $viewsCollection->getSelect(); $viewSelected = $document->getViewId(); $viewModel = View\Model::fromId($document->getDocumentType()->getDefaultViewId()); if (!empty($viewModel)) { $select = $select + array($viewModel->getId() => $viewModel->getName()); if (empty($viewSelected)) { $viewSelected = $viewModel->getId(); } } $view = new Element\Select('document-view'); $view->setValueOptions($select)->setValue((string) $viewSelected)->setAttribute('id', 'view')->setAttribute('class', 'form-control')->setLabel('View'); $inputFilterFactory = $this->getInputFilter(); $inputFilterFactory->add(array('name' => 'document-view', 'required' => true, 'validators' => array(array('name' => 'not_empty'))), 'document-view'); $this->add($view); $layoutsCollection = new Layout\Collection(); $layout = new Element\Select('document-layout'); $layout->setValueOptions($layoutsCollection->getSelect())->setValue((string) $document->getLayoutId())->setAttribute('id', 'layout')->setAttribute('class', 'form-control')->setLabel('Layout'); $inputFilterFactory->add(array('name' => 'document-layout', 'required' => true, 'validators' => array(array('name' => 'not_empty'))), 'document-layout'); $this->add($layout); $this->remove('document_type'); $this->remove('parent'); $moreInformation = new Element\Hidden('more_information'); $moreInformation->setAttribute('content', ''); $this->add($moreInformation); $this->parentId = $document->getParentId(); $this->documentId = $document->getId(); $this->loadValues($document); }
/** * 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); } } }
/** * Paste document * * @return \Zend\View\Model\JsonModel */ public function pasteAction() { $parentId = $this->getRouteMatch()->getParam('id', null); $session = $this->getSession(); if (!empty($parentId)) { $parentDocument = DocumentModel::fromId($parentId); if (empty($parentDocument)) { return $this->returnJson(array('success' => false)); } } if (!empty($session['document-cut'])) { $document = DocumentModel::fromId($session['document-cut']); if (empty($document)) { return $this->returnJson(array('success' => false)); } if (!empty($parentDocument)) { $availableChildren = $parentDocument->getDocumentType()->getDependencies(); if (!in_array($document->getDocumentType()->getId(), $availableChildren)) { return $this->returnJson(array('success' => false)); } } $searchDocument = DocumentModel::fromUrlKey($document->getUrlKey(), $parentId); if (!empty($searchDocument)) { return $this->returnJson(array('success' => false)); } $document->setParentId($parentId); $document->save(); unset($session['document-cut']); return $this->returnJson(array('success' => true)); } elseif (!empty($session['document-copy'])) { $urlKey = $this->getRequest()->getQuery('url_key'); $searchDocument = DocumentModel::fromUrlKey($urlKey, $parentId); if (!empty($searchDocument)) { return $this->returnJson(array('success' => false)); } $document = DocumentModel::fromId($session['document-copy']); if (empty($document)) { return $this->returnJson(array('success' => false)); } if (!empty($parentDocument)) { $availableChildren = $parentDocument->getDocumentType()->getDependencies(); if (!in_array($document->getDocumentType()->getId(), $availableChildren)) { return $this->returnJson(array('success' => false)); } } $copyDocument = new DocumentModel(); $copyDocumentProperties = new Property\Collection(); $copyDocumentProperties->load(null, null, $document->getId()); $copyDocument->addData($document->getData()); $copyDocument->setData('id', null); $copyDocument->setParentId($parentId); $copyDocument->setName($this->getRequest()->getQuery('name')); $copyDocument->setUrlKey($urlKey); $copyDocument->save(); foreach ($copyDocumentProperties->getProperties() as $property) { $value = $property->getValueModel(); if (empty($value)) { continue; } $copyProperty = new Property\Value\Model(); $copyProperty->addData($value->getData()); $copyProperty->setData('id', null); $copyProperty->setDocumentId($copyDocument->getId()); $copyProperty->save(); } return $this->returnJson(array('success' => true)); } else { return $this->returnJson(array('success' => false)); } }