/** * 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)); }
/** * 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->tab->delete(); $this->documentType->delete(); $this->user->delete(); $this->layout->delete(); $this->view->delete(); unset($this->tab); unset($this->documentType); unset($this->user); unset($this->layout); unset($this->view); unset($this->object); }
/** * 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); }
/** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. * * @return void */ public function tearDown() { $this->documentType->delete(); $this->property->delete(); $this->tabModel->delete(); $this->view->delete(); $this->layout->delete(); $this->user->delete(); $this->datatype->delete(); unset($this->documentType); unset($this->property); unset($this->tabModel); unset($this->view); unset($this->layout); unset($this->user); unset($this->datatype); }
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 testFromArray() { $model = Model::fromArray(array('name' => 'DatatypeTest', 'identifier' => 'DatatypeTest', 'description' => 'DatatypeTest', 'required' => false, 'sort_order' => 1, 'tab_id' => $this->tab->getId(), 'datatype_id' => $this->datatype->getId())); $this->assertInstanceOf('Gc\\Property\\Model', $model); }
/** * Test * * @return void */ public function testGetProperties() { $this->assertInternalType('array', $this->object->getProperties()); }
/** * Initialize from id * * @param integer $tabId Tab id * * @return \Gc\Tab\Model */ public static function fromId($tabId) { $tabTable = new Model(); $row = $tabTable->fetchRow($tabTable->select(array('id' => (int) $tabId))); $tabTable->events()->trigger(__CLASS__, 'before.load', $tabTable); if (!empty($row)) { $tabTable->setData((array) $row); $tabTable->setOrigData(); $tabTable->events()->trigger(__CLASS__, 'after.load', $tabTable); return $tabTable; } else { $tabTable->events()->trigger(__CLASS__, 'after.load.failed', $tabTable); return false; } }
/** * Add tab in session * * @return \Zend\View\Model\JsonModel */ public function importTabAction() { if (!$this->getRequest()->isPost()) { return $this->returnJson(array('success' => false, 'message' => 'Error')); } $tabId = $this->getRequest()->getPost()->get('tab_id'); $tabModel = Tab\Model::fromId($tabId); $propertiesList = $tabModel->getProperties(); $properties = array(); foreach ($propertiesList as $property) { $properties[] = array('name' => $property->getName(), 'identifier' => $property->getIdentifier(), 'description' => $property->getDescription(), 'datatype' => $property->getDatatypeId(), 'isRequired' => $property->isRequired()); } $tab = array('name' => $tabModel->getName(), 'description' => $tabModel->getDescription(), 'properties' => $properties); return $this->returnJson(array('success' => true, 'tab' => $tab)); }
/** * 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 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(); }
/** * 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 testAddTabWithTabModel() { $tabModel = TabModel::fromArray(array('id' => 1, 'name' => 'Name', 'description' => 'Description', 'sort_order' => 1, 'document_type_id' => 1)); $this->assertInstanceOf('GcDevelopment\\Form\\DocumentType', $this->object->addTab($tabModel)); }
/** * Add tab from array * * @param array $array Data * * @return void */ public function addTab(array $array) { $tabs = $this->getTabs(); $tabs[] = Model::fromArray($array); $this->setData('tabs', $tabs); }
/** * 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(); }