/** * Load tabs from document type * * @param integer $documentTypeId Document type id * * @return array */ public function loadTabs($documentTypeId) { if (empty($this->tabs[$documentTypeId])) { $documentType = DocumentType\Model::fromId($documentTypeId); $tabs = $documentType->getTabs(); $this->tabs[$documentTypeId] = $tabs; } return $this->tabs[$documentTypeId]; }
/** * Test * * @return void */ public function testGetProperties() { $documentModel = DocumentModel::fromArray(array('name' => 'DocumentTest', 'url_key' => 'document-test', 'status' => DocumentModel::STATUS_ENABLE, 'sort_order' => 1, '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' => 0)); $documentModel->save(); $this->object->setDocumentId($documentModel->getId()); $this->object->save(); $this->object->load($this->documentType->getId(), $this->tab->getId(), 1); $this->assertInternalType('array', $this->object->getProperties(true)); $this->object->load(); $this->assertInternalType('array', $this->object->getProperties(true)); }
/** * 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 = Model::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->object = new Collection(); }
/** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. * * @return void */ protected function tearDown() { $this->object->delete(); $this->documentType->delete(); $this->user->delete(); $this->layout->delete(); $this->view->delete(); unset($this->documentType); unset($this->user); unset($this->layout); unset($this->view); unset($this->object); }
/** * Test * * @return void */ public function testPasteActionWithCutSession() { $document = DocumentModel::fromArray(array('name' => 'test', 'url_key' => 'about', '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)); $document->save(); $session = new SessionContainer(); $session->offsetSet('document-cut', $this->document->getId()); $this->dispatch('/admin/content/document/paste/' . $document->getId()); $this->assertResponseStatusCode(200); $this->assertModuleName('GcContent'); $this->assertControllerName('DocumentController'); $this->assertControllerClass('DocumentController'); $this->assertMatchedRouteName('content/document/paste'); $document->delete(); }
/** * Test * * @return void */ public function testIndexActionWithUrlKeyWithPreview() { $auth = new AuthenticationService(new Storage\Session(UserModel::BACKEND_AUTH_NAMESPACE)); $auth->clearIdentity(); $document = DocumentModel::fromArray(array('name' => 'test', 'url_key' => 'test', '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)); $document->save(); $this->dispatch($document->getUrl() . '?preview'); $this->assertResponseStatusCode(200); $this->assertModuleName('GcFrontend'); $this->assertControllerName('IndexController'); $this->assertControllerClass('IndexController'); $this->assertMatchedRouteName('cms'); $document->delete(); $enableCache = $this->config->setValue('cache_is_active', 0); }
/** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. * * @return void */ public function tearDown() { StaticEventManager::resetInstance(); ModuleModel::uninstall(Registry::get('Application')->getServiceManager()->get('CustomModules')->getModule('Blog'), ModuleModel::fromName('Blog')); $this->document->delete(); $this->view->delete(); $this->layout->delete(); $this->documentType->delete(); unset($this->document); unset($this->object); unset($this->view); unset($this->layout); unset($this->documentType); parent::tearDown(); }
/** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. * * @return void */ protected function tearDown() { $this->property->delete(); $this->datatype->delete(); $this->tab->delete(); $this->documentType->delete(); $this->user->delete(); $this->view->delete(); unset($this->datatype); unset($this->property); unset($this->documentType); unset($this->tab); unset($this->user); unset($this->view); unset($this->object); }
/** * Initialize document types * * @return \Gc\Document\Collection */ protected function setDocumentTypes() { $parentId = $this->getParentId(); $rows = $this->fetchAll($this->select(function (Select $select) use($parentId) { if ($parentId !== null) { $select->join(array('dtd' => 'document_type_dependency'), 'dtd.children_id = document_type.id', array()); $select->where->equalTo('dtd.parent_id', $parentId); } $select->order('name ASC'); })); $documentTypes = array(); foreach ($rows as $row) { $documentTypes[] = Model::fromArray((array) $row); } $this->setData('document_types', $documentTypes); }
/** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. * * @return void */ protected function tearDown() { $this->boostrap->uninstall(); $this->document->delete(); $this->view->delete(); $this->layout->delete(); $this->documentType->delete(); $this->user->delete(); $this->module->delete(); unset($this->module); unset($this->document); unset($this->view); unset($this->layout); unset($this->documentType); unset($this->user); unset($this->object); unset($this->renderer); }
/** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. * * @return void */ protected function tearDown() { $this->document->delete(); $this->documentType->delete(); $this->user->delete(); $this->layout->delete(); $this->view->delete(); unset($this->document); unset($this->documentType); unset($this->user); unset($this->layout); unset($this->view); unset($this->object); StaticEventManager::resetInstance(); if (file_exists($this->filePath)) { unlink($this->filePath); } }
protected function removeContent() { $this->documentType->delete(); $this->property->delete(); $this->tabModel->delete(); $this->view->delete(); $this->layout->delete(); $this->script->delete(); $this->datatype->delete(); $this->document->delete(); unset($this->documentType); unset($this->property); unset($this->tabModel); unset($this->view); unset($this->layout); unset($this->script); unset($this->datatype); unset($this->document); }
/** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. * * @return void */ protected function tearDown() { $_FILES = array(); $_POST = array(); $this->datatype->delete(); $this->documentType->delete(); $this->layout->delete(); $this->property->delete(); $this->tab->delete(); $this->user->delete(); $this->view->delete(); unset($this->datatype); unset($this->documentType); unset($this->layout); unset($this->property); unset($this->tab); unset($this->user); unset($this->view); unset($this->object); }
/** * Test * * @return void */ public function testRenderWithIterableInterface() { $view = ViewModel::fromArray(array('name' => 'View Name', 'identifier' => 'View identifier', 'description' => 'View Description', 'content' => 'View Content')); $view->save(); $layout = LayoutModel::fromArray(array('name' => 'Layout Name', 'identifier' => 'Layout identifier', 'description' => 'Layout Description', 'content' => 'Layout Content')); $layout->save(); $user = UserModel::fromArray(array('lastname' => 'User test', 'firstname' => 'User test', 'email' => '*****@*****.**', 'login' => 'test', 'user_acl_role_id' => 1)); $user->setPassword('test'); $user->save(); $documentType = DocumentTypeModel::fromArray(array('name' => 'Document Type Name', 'description' => 'Document Type description', 'icon_id' => 1, 'defaultview_id' => $view->getId(), 'user_id' => $user->getId())); $documentType->save(); $document = DocumentModel::fromArray(array('name' => 'Document name', 'url_key' => 'url-key', 'status' => DocumentModel::STATUS_ENABLE, 'show_in_nav' => true, 'user_id' => $user->getId(), 'document_type_id' => $documentType->getId(), 'view_id' => $view->getId(), 'layout_id' => $layout->getId(), 'parent_id' => 0)); $document->save(); $collection = new DocumentCollection(); $collection->load(0); $this->assertEquals(sprintf('<ul><li><a href="#tabs-%d">Document name</a></li></ul>', $document->getId()), $this->object->render($collection->getChildren())); $document->delete(); $documentType->delete(); $layout->delete(); $view->delete(); $user->delete(); }
/** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. * * @return void */ protected function tearDown() { $this->document->delete(); unset($this->document); $this->documentTwo->delete(); unset($this->documentTwo); $this->documentChildren->delete(); unset($this->documentChildren); $this->documentSecondChildren->delete(); unset($this->documentSecondChildren); $this->documentThirdChildren->delete(); unset($this->documentThirdChildren); $this->documentForthChildren->delete(); unset($this->documentForthChildren); $this->view->delete(); unset($this->view); $this->user->delete(); unset($this->user); $this->layout->delete(); unset($this->layout); $this->documentType->delete(); unset($this->documentType); unset($this->object); }
/** * Test * * @return void */ public function testFromIdentifier() { $documentModel = DocumentModel::fromArray(array('name' => 'DocumentTest', 'url_key' => 'document-test', 'status' => DocumentModel::STATUS_ENABLE, 'sort_order' => 1, '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' => 0)); $documentModel->save(); $this->assertInstanceOf('Gc\\Property\\Model', Model::fromIdentifier($this->object->getIdentifier(), $documentModel->getId())); }
/** * Test * * @return void */ public function testSetValues() { $documentTypeModel = DocumentTypeModel::fromarray(array('name' => 'Name', 'description' => 'Description', 'icon_id' => 1)); $this->object->setValues($documentTypeModel); }
/** * test * * @return void */ protected function createDocuments() { $this->view = View\Model::fromArray(array('name' => 'View Name', 'identifier' => 'View identifier', 'description' => 'View Description', 'content' => 'View Content')); $this->view->save(); $this->layout = Layout\Model::fromArray(array('name' => 'Layout Name', 'identifier' => 'Layout identifier', 'description' => 'Layout Description', 'content' => 'Layout Content')); $this->layout->save(); $this->user = User\Model::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 = DocumentType\Model::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->homeDocument = Document\Model::fromArray(array('name' => 'Document name', 'url_key' => '', 'status' => Document\Model::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' => 0)); $this->homeDocument->save(); $this->parentDocument = Document\Model::fromArray(array('name' => 'Document name', 'url_key' => 'parent', 'status' => Document\Model::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' => 0)); $this->parentDocument->save(); $this->document = Document\Model::fromArray(array('name' => 'Document name', 'url_key' => 'children', 'status' => Document\Model::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->parentDocument->getId())); $this->document->save(); }
/** * Get model from id * * @param integer $documentTypeId Document type id * * @return \Gc\DocumentType\Model */ public static function fromId($documentTypeId) { $documentTypeTable = new Model(); $row = $documentTypeTable->fetchRow($documentTypeTable->select(array('id' => (int) $documentTypeId))); $documentTypeTable->events()->trigger(__CLASS__, 'before.load', $documentTypeTable); if (!empty($row)) { $documentTypeTable->setData((array) $row); $documentTypeTable->setOrigData(); $documentTypeTable->events()->trigger(__CLASS__, 'after.load', $documentTypeTable); return $documentTypeTable; } else { $documentTypeTable->events()->trigger(__CLASS__, 'after.load.failed', $documentTypeTable); return false; } }
/** * Test * * @return void */ public function testLoad() { $user = UserModel::fromArray(array('lastname' => 'Test', 'firstname' => 'Test', 'email' => '*****@*****.**', 'login' => 'test-user-model', 'user_acl_role_id' => 1)); $user->setPassword('test-user-model-password'); $user->save(); $view = ViewModel::fromArray(array('name' => 'View', 'identifier' => 'ViewIdentifier', 'description' => 'Description', 'content' => '')); $view->save(); $layout = LayoutModel::fromArray(array('name' => 'View', 'identifier' => 'ViewIdentifier', 'description' => 'Description', 'content' => '')); $layout->save(); $documenttype = DocumentTypeModel::fromArray(array('name' => 'DocumentType', 'description' => 'description', 'icon_id' => 1, 'default_view_id' => $view->getId(), 'user_id' => $user->getId())); $documenttype->save(); $documenttype->setDependencies(array($documenttype->getId())); $documenttype->save(); $datatype = DatatypeModel::fromArray(array('name' => 'DatatypeTest', 'model' => 'Textstring')); $datatype->save(); $tab = TabModel::fromArray(array('name' => 'test', 'description' => 'test', 'document_type_id' => $documenttype->getId())); $tab->save(); $property = PropertyModel::fromArray(array('name' => 'test', 'identifier' => 'test', 'description' => 'test', 'tab_id' => $tab->getId(), 'datatype_id' => $datatype->getId(), 'is_required' => true)); $property->save(); $document = DocumentModel::fromArray(array('name' => 'test', 'url_key' => '', 'status' => DocumentModel::STATUS_ENABLE, 'user_id' => $user->getId(), 'document_type_id' => $documenttype->getId(), 'view_id' => $view->getId(), 'layout_id' => $layout->getId(), 'parent_id' => null)); $document->save(); $this->assertNull($this->object->load($document, array('locales' => array('en_GB' => 'English')))); $this->object->setData(array()); $this->assertFalse($this->object->isValid()); $document->delete(); $documenttype->delete(); $property->delete(); $tab->delete(); $view->delete(); $layout->delete(); $user->delete(); $datatype->delete(); unset($documenttype); unset($document); unset($property); unset($tab); unset($view); unset($layout); unset($user); unset($datatype); }
/** * Test * * @return void */ public function testImportTabActionWithPostData() { $viewModel = ViewModel::fromArray(array('name' => 'Test', 'identifier' => 'Test', 'content' => 'Test')); $viewModel->save(); $datatypeModel = DatatypeModel::fromArray(array('name' => 'DatatypeTest', 'model' => 'Textstring')); $datatypeModel->save(); $documentTypeModel = DocumentTypeModel::fromArray(array('name' => 'TestDocumentType', 'icon_id' => 3, 'default_view_id' => $viewModel->getId(), 'user_id' => $this->user->getId())); $documentTypeModel->save(); $tabModel = TabModel::fromArray(array('name' => 'test', 'description' => 'test', 'document_type_id' => $documentTypeModel->getId())); $tabModel->save(); $propertyModel = PropertyModel::fromArray(array('name' => 'test', 'identifier' => 'test', 'description' => 'test', 'tab_id' => $tabModel->getId(), 'datatype_id' => $datatypeModel->getId())); $propertyModel->save(); $this->dispatch('/admin/development/document-type/import-tab', 'POST', array('tab_id' => $tabModel->getId())); $this->assertResponseStatusCode(200); $this->assertModuleName('GcDevelopment'); $this->assertControllerName('DocumentTypeController'); $this->assertControllerClass('DocumentTypeController'); $this->assertMatchedRouteName('development/document-type/import-tab'); $documentTypeModel->delete(); $propertyModel->delete(); $tabModel->delete(); $viewModel->delete(); $datatypeModel->delete(); }
/** * 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 testDelete() { $this->object->setTabs(array(array('name' => 'TabTest', 'description' => 'TabTest', 'sort_order' => 2, 'document_type_id' => $this->documentType->getId()))); $this->object->save(); $this->assertTrue($this->object->delete()); }
/** * Test * * @return void */ public function testDelete() { $model = Model::fromIdentifier('identifier-collection-test'); $documentType = DocumentTypeModel::fromArray(array('name' => 'Document type name', 'description' => 'Document type description', 'defaultview_id' => $model->getId(), 'icon_id' => 1, 'user_id' => 1)); $documentType->save(); $this->object->init($documentType->getId()); $this->object->addElement($model); $this->object->save(); $this->assertTrue($this->object->delete()); $documentType->delete(); }
/** * Test * * @return void */ public function testFromFakeId() { $model = Model::fromId(1000); $this->assertFalse($model); }
/** * Get Document type * * @return \Gc\DocumentType\Model */ public function getDocumentType() { if ($this->getData('document_type') === null) { $this->setData('document_type', \Gc\DocumentType\Model::fromId($this->getDocumentTypeId())); } return $this->getData('document_type'); }
/** * Delete Document type * * @return \Zend\View\Model\JsonModel */ public function deleteAction() { $documentType = DocumentType\Model::fromId($this->getRouteMatch()->getParam('id', null)); if (!empty($documentType) and $documentType->delete()) { return $this->returnJson(array('success' => true, 'message' => 'This document type has been deleted')); } return $this->returnJson(array('success' => false, 'message' => 'Document type does not exists')); }
/** * Test * * @return void */ public function testSaveEditor() { $viewModel = ViewModel::fromArray(array('name' => 'View Name', 'identifier' => 'View identifier', 'description' => 'View Description', 'content' => 'View Content')); $viewModel->save(); $layoutModel = LayoutModel::fromArray(array('name' => 'Layout Name', 'identifier' => 'Layout identifier', 'description' => 'Layout Description', 'content' => 'Layout Content')); $layoutModel->save(); $userModel = UserModel::fromArray(array('lastname' => 'User test', 'firstname' => 'User test', 'email' => '*****@*****.**', 'login' => 'test', 'user_acl_role_id' => 1)); $userModel->setPassword('test'); $userModel->save(); $documentTypeModel = DocumentTypeModel::fromArray(array('name' => 'Document Type Name', 'description' => 'Document Type description', 'icon_id' => 1, 'defaultview_id' => $viewModel->getId(), 'user_id' => $userModel->getId())); $documentTypeModel->save(); $tabModel = TabModel::fromArray(array('name' => 'TabTest', 'description' => 'TabTest', 'sort_order' => 1, 'document_type_id' => $documentTypeModel->getId())); $tabModel->save(); $documentModel = DocumentModel::fromArray(array('name' => 'DocumentTest', 'url_key' => 'document-test', 'status' => DocumentModel::STATUS_ENABLE, 'sort_order' => 1, 'show_in_nav' => true, 'user_id' => $userModel->getId(), 'document_type_id' => $documentTypeModel->getId(), 'view_id' => $viewModel->getId(), 'layout_id' => $layoutModel->getId(), 'parent_id' => 0)); $documentModel->save(); $propertyModel = PropertyModel::fromArray(array('datatype_id' => $this->object->getId(), 'document_id' => $documentModel->getId(), 'tab_id' => $tabModel->getId(), 'name' => 'PropertyTest', 'identifier' => 'PropertyTest', 'description' => 'PropertyTest', 'required' => true, 'sort_order' => 1)); $propertyModel->save(); $this->assertFalse(Model::saveEditor(Registry::get('Application')->getServiceManager(), $propertyModel)); $propertyModel->isRequired(false); $this->assertTrue(Model::saveEditor(Registry::get('Application')->getServiceManager(), $propertyModel)); $propertyModel->delete(); $documentModel->delete(); $tabModel->delete(); $documentTypeModel->delete(); $viewModel->delete(); $layoutModel->delete(); }