/** * 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->datatype = DatatypeModel::fromArray(array('name' => 'AbstractEditorTest', 'prevalue_value' => 's:26:"AbstractPrevalueEditorTest";', 'model' => 'AbstractEditorTest')); $this->datatype->save(); $mockDatatype = $this->getMockForAbstractClass('Gc\\Datatype\\AbstractDatatype'); $application = Registry::get('Application'); $mockDatatype->setRequest($application->getServiceManager()->get('Request')); $mockDatatype->setRouter($application->getServiceManager()->get('Router')); $mockDatatype->setHelperManager($application->getServiceManager()->get('viewhelpermanager')); $mockDatatype->load($this->datatype, 1); $this->object = $this->getMockForAbstractClass('Gc\\Datatype\\AbstractDatatype\\AbstractPrevalueEditor', array($mockDatatype)); }
/** * Set datatype collection * * @return \Gc\Datatype\Collection */ protected function setDatatypes() { $rows = $this->fetchAll($this->select(function (Select $select) { $select->order('name'); })); $datatypes = array(); foreach ($rows as $row) { $datatypes[] = Model::fromArray((array) $row); } $this->datatypes = $datatypes; return $this; }
/** * 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); }
/** * 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->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); }
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); }
/** * 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->datatype = DatatypeModel::fromArray(array('name' => 'AbstractEditorTest', 'prevalue_value' => 's:18:"AbstractEditorTest";', 'model' => 'AbstractEditorTest')); $this->datatype->save(); $this->view = ViewModel::fromArray(array('name' => 'View Name', 'identifier' => 'View identifier', 'description' => 'View Description', 'content' => 'View Content')); $this->view->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->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(); $mockDatatype = $this->getMockForAbstractClass('Gc\\Datatype\\AbstractDatatype'); $application = Registry::get('Application'); $mockDatatype->setRequest($application->getServiceManager()->get('Request')); $mockDatatype->setRouter($application->getServiceManager()->get('Router')); $mockDatatype->setHelperManager($application->getServiceManager()->get('viewhelpermanager')); $mockDatatype->setProperty($this->property); $mockDatatype->load($this->datatype, 1); $this->object = $this->getMockForAbstractClass('Gc\\Datatype\\AbstractDatatype\\AbstractEditor', array($mockDatatype)); }
/** * 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; }
/** * 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->datatype->delete(); unset($this->datatype); unset($this->object); }
/** * Load Datatype * * @param ServiceManager $serviceManager Service manager * @param integer $datatypeId Datatype id * @param integer $documentId Optional document id * * @return mixed */ public static function loadDatatype(ServiceManager $serviceManager, $datatypeId, $documentId = null) { $datatype = Model::fromId($datatypeId); $class = 'Datatypes\\' . $datatype->getModel() . '\\Datatype'; $object = new $class(); $object->setRequest($serviceManager->get('Request'))->setRouter($serviceManager->get('Router'))->setHelperManager($serviceManager->get('viewhelpermanager'))->setDatatypesList($serviceManager->get('DatatypesList'))->load($datatype, $documentId); return $object; }
/** * 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->datatype = DatatypeModel::fromArray(array('name' => 'DatatypeCollectionTest', 'prevalue_value' => '', 'model' => 'DatatypeCollectionTest')); $this->datatype->save(); $this->object = new Collection(); }
/** * Edit Document * * @return \Zend\View\Model\ViewModel|array */ public function editAction() { $documentId = $this->getRouteMatch()->getParam('id'); $document = DocumentModel::fromId($documentId); if (empty($document)) { $this->flashMessenger()->addErrorMessage('Document does not exists!'); return $this->redirect()->toRoute('content'); } $documentForm = new Form\Document(); $documentForm->init($this->url()->fromRoute('content/document/edit', array('id' => $documentId))); $hasError = false; $documentTypeId = $document->getDocumentTypeId(); $oldUrlKey = $document->getUrlKey(); if ($this->getRequest()->isPost()) { $documentVars = $this->getRequest()->getPost()->toArray(); $document->setName(empty($documentVars['document-name']) ? $document->getName() : $documentVars['document-name']); $document->setStatus(empty($documentVars['document-status']) ? DocumentModel::STATUS_DISABLE : DocumentModel::STATUS_ENABLE); $document->showInNav(empty($documentVars['document-show_in_nav']) ? false : $documentVars['document-show_in_nav']); $document->canBeCached(empty($documentVars['document-can_be_cached']) ? false : $documentVars['document-can_be_cached']); $document->setLayoutId(empty($documentVars['document-layout']) ? false : $documentVars['document-layout']); $document->setViewId(empty($documentVars['document-view']) ? $document->getViewId() : $documentVars['document-view']); $document->setUrlKey(empty($documentVars['document-url_key']) ? '' : $documentVars['document-url_key']); $document->setLocale(empty($documentVars['document-locale']) ? null : $documentVars['document-locale']); $tabs = $documentForm->loadTabs($documentTypeId); foreach ($tabs as $tab) { $properties = $documentForm->loadProperties($documentTypeId, $tab->getId(), $document->getId()); $connection = $document->getAdapter()->getDriver()->getConnection(); try { $connection->beginTransaction(); foreach ($properties as $property) { $property->setDocumentId($document->getId())->loadValue(); if (!Datatype\Model::saveEditor($this->getServiceLocator(), $property)) { $hasError = true; } } if ($hasError) { $connection->rollBack(); } else { $connection->commit(); } } catch (Exception $e) { $connection->rollBack(); } } } $tabsArray = $documentForm->load($documentTypeId, $document, $this->getServiceLocator()); $tabsArray[] = $this->getServiceLocator()->get('MvcTranslator')->translate('Document information'); $formDocumentAdd = $documentForm->get('tabs-' . count($tabsArray)); if ($this->getRequest()->isPost()) { $formDocumentAdd->setData($this->getRequest()->getPost()->toArray()); if ($hasError or !$formDocumentAdd->isValid()) { $document->setStatus(DocumentModel::STATUS_DISABLE); $document->setUrlKey($oldUrlKey); $this->flashMessenger()->addErrorMessage('This document cannot be saved because one or more properties values are required !'); $this->useFlashMessenger(); } else { $this->flashMessenger()->addSuccessMessage('This document has been saved'); $document->addData($formDocumentAdd->getInputFilter()->getValues()); $document->save(); return $this->redirect()->toRoute('content/document/edit', array('id' => $documentId)); } } $this->layout()->setVariable('documentId', $documentId); return array('form' => $documentForm, 'tabs' => new Component\Tabs($tabsArray), 'document' => $document); }
/** * 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(); }
/** * Delete datatype * * @return \Zend\View\Model\JsonModel */ public function deleteAction() { $datatype = Datatype\Model::fromId($this->getRouteMatch()->getParam('id', null)); if (!empty($datatype) and $datatype->delete()) { return $this->returnJson(array('success' => true, 'message' => 'This datatype has been deleted')); } return $this->returnJson(array('success' => false, 'message' => 'Datatype does not exists')); }
/** * Test * * @return void */ public function testDeleteAction() { $datatypeModel = DatatypeModel::fromArray(array('name' => 'LayoutName', 'model' => 'Textstring')); $datatypeModel->save(); $this->dispatch('/admin/development/datatype/delete/' . $datatypeModel->getId()); $this->assertResponseStatusCode(200); $this->assertModuleName('GcDevelopment'); $this->assertControllerName('DatatypeController'); $this->assertControllerClass('DatatypeController'); $this->assertMatchedRouteName('development/datatype/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); }
/** * Import Datatypes * * @param array &$ids Ids * @param array &$errors Errors * @param array $children Children list * * @return void */ protected function importDatatypes(&$ids, &$errors, $children) { foreach ($children['children'] as $child) { $attributes = $child->attributes(); $id = (int) $attributes['id']; $model = Datatype\Model::fromId($id); if ($model === false) { $model = new Datatype\Model(); } $name = (string) $child->name; $datatypeModel = (string) $child->model; $model->addData(array('name' => empty($name) ? $model->getName() : $name, 'model' => empty($datatypeModel) ? $model->getModel() : $datatypeModel)); $model->setPrevalueValue((string) $child->prevalue_value); try { if (!empty($model)) { $model->save(); $ids['datatypes'][$id] = $model->getId(); } } catch (Exception $e) { $errors[] = sprintf($this->serviceLocator->get('MvcTranslator')->translate('Cannot save datatype with id (%d)'), $id); } } }
/** * 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 testLoadDatatype() { $this->assertInstanceOf('Gc\\Datatype\\AbstractDatatype', Model::loadDatatype(Registry::get('Application')->getServiceManager(), $this->object->getId())); }