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(); }
/** * Get user model * * @return \Gc\User\Model */ public function getUser() { if ($this->getData('user') === null and $this->getUserId() != null) { $this->setData('user', User\Model::fromId($this->getUserId())); } return $this->getData('user'); }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. * * @return void */ protected function setUp() { $collection = new Collection(); foreach ($collection->getUsers() as $user) { $user->delete(); } unset($collection); $this->object = Model::fromArray(array('lastname' => 'Test', 'firstname' => 'Test', 'email' => '*****@*****.**', 'login' => 'test', 'user_acl_role_id' => 1)); $this->object->setPassword('test'); $this->object->save(); }
/** * 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)); }
/** * Set users collection * * @return void */ protected function setUsers() { $select = $this->select(function (Select $select) { $select->order('lastname'); }); $rows = $this->fetchAll($select); $users = array(); foreach ($rows as $row) { $users[] = Model::fromArray((array) $row); } $this->setData('users', $users); }
/** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. * * @return void */ protected function tearDown() { unset($this->object); $this->documentType->delete(); unset($this->documentType); $this->view->delete(); unset($this->view); $this->layout->delete(); unset($this->layout); $this->user->delete(); unset($this->user); }
/** * List all resources by group * * @param array $group Resource group * * @return array */ public function listResourcesByGroup($group) { $result = null; $select = new Select(); $select->from(array('uar' => 'user_acl_resource'))->join(array('uap' => 'user_acl_permission'), 'uar.id = uap.user_acl_resource_id')->where->equalTo('uar.resource', $group); $group = $this->roleTable->fetchAll($select); foreach ($group as $key => $value) { if ($this->isAllowed($this->user->getRole()->getName(), $value['resource'], $value['permission'])) { $result[] = $value['permission']; } } return $result; }
/** * 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(); unset($this->document); unset($this->object); unset($this->view); unset($this->layout); unset($this->documentType); unset($this->user); }
/** * 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 */ 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); } }
/** * Test * * @return void */ public function testInit() { $collection = new UserCollection(); foreach ($collection->getUsers() as $user) { $user->delete(); } unset($collection); $userModel = UserModel::fromArray(array('lastname' => 'Test', 'firstname' => 'Test', 'email' => '*****@*****.**', 'login' => 'test-user-model', 'user_acl_role_id' => 1)); $userModel->setPassword('test-user-model-password'); $userModel->save(); $viewModel = ViewModel::fromArray(array('name' => 'View', 'identifier' => 'ViewIdentifier', 'description' => 'Description', 'content' => '')); $viewModel->save(); $documentTypeModel = DocumentTypeModel::fromArray(array('name' => 'DocumentType', 'description' => 'description', 'icon_id' => 1, 'default_view_id' => $viewModel->getId(), 'user_id' => $userModel->getId())); $documentTypeModel->save(); $form = new DocumentType(); $this->assertNull($form->init()); $viewModel->delete(); $documentTypeModel->delete(); $userModel->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() { $_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 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 testInvokeWithAUthenticationShouldReturnUserModel() { $this->user->authenticate('test', 'test'); $this->assertInstanceOf('Gc\\User\\Model', $this->object->__invoke()); }
/** * 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(); }
/** * 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->user->delete(); unset($this->user); unset($this->object); }
/** * Test * * @return void */ public function testOnDispatchWithIdentityAndAdminRole() { $userModel = UserModel::fromArray(array('lastname' => 'Test', 'firstname' => 'Test', 'email' => '*****@*****.**', 'login' => 'login-test', 'user_acl_role_id' => 1)); $userModel->setPassword('password-test'); $userModel->save(); $userModel->authenticate('login-test', 'password-test'); $routeMatch = new RouteMatch(array()); $routeMatch->setMatchedRouteName('cms'); $this->object->getEvent()->setRouteMatch($routeMatch); $this->assertInstanceOf('Zend\\View\\Model\\ViewModel', $this->object->dispatch(Registry::get('Application')->getRequest(), null)); $userModel->delete(); }
/** * Constructor * * @param UserModel $user User model to retrieve Acl, role name and check permission */ public function __construct(UserModel $user) { $this->acl = $user->getAcl(true); $this->roleName = $user->getRole()->getName(); }
/** * Edit user * * @return \Zend\View\Model\ViewModel|array */ public function editAction() { $userId = $this->getRouteMatch()->getParam('id'); $userModel = User\Model::fromId($userId); if (empty($userModel)) { $this->flashMessenger()->addErrorMessage("Can't edit this user"); return $this->redirect()->toRoute('config/user'); } $form = new UserForm(); $form->setAttribute('action', $this->url()->fromRoute('config/user/edit', array('id' => $userId))); $form->loadValues($userModel); if ($this->getRequest()->isPost()) { $post = $this->getRequest()->getPost()->toArray(); if (!empty($post['password'])) { $form->passwordRequired(); $form->getInputFilter()->get('password_confirm')->getValidatorChain()->addValidator(new Identical($post['password'])); } $form->setData($post); if ($form->isValid()) { $userModel->addData($post); $userModel->setActive(empty($post['active']) ? false : $post['active']); if (!empty($post['password'])) { $userModel->setPassword($post['password']); } $userModel->save(); $this->flashMessenger()->addSuccessMessage('This user has been saved'); return $this->redirect()->toRoute('config/user/edit', array('id' => $userId)); } $this->flashMessenger()->addErrorMessage('User can not be saved'); } return array('form' => $form); }
/** * Test * * @return void */ public function testEditActionWithPostData() { $userModel = UserModel::fromArray(array('lastname' => 'Test', 'firstname' => 'Test', 'email' => '*****@*****.**', 'login' => 'testlogin', 'user_acl_role_id' => 2)); $userModel->setPassword('passwordtest'); $userModel->save(); $this->dispatch('/admin/config/user/edit/' . $userModel->getId(), 'POST', array('lastname' => 'Test', 'firstname' => 'Test', 'email' => '*****@*****.**', 'login' => 'testlogin', 'user_acl_role_id' => 2, 'password' => 'test', 'password_confirm' => 'test')); $this->assertResponseStatusCode(302); $this->assertModuleName('GcConfig'); $this->assertControllerName('UserController'); $this->assertControllerClass('UserController'); $this->assertMatchedRouteName('config/user/edit'); $userModel->delete(); }
/** * 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 testLoadValues() { $model = Model::fromArray(array('name' => 'Name')); $inputFilterFactory = new InputFilterFactory(); $inputFilter = $inputFilterFactory->createInputFilter(array('name' => array('required' => true, 'validators' => array(array('name' => 'not_empty'), array('name' => 'db\\no_record_exists', 'options' => array('table' => 'datatype', 'field' => 'name', 'adapter' => $this->object->getAdapter())))))); $this->object->setInputFilter($inputFilter); $this->object->add(new Element\Text('name')); $this->assertInstanceOf('Gc\\Form\\AbstractForm', $this->object->loadValues($model)); }
/** * Test * * @return void */ public function testGetUser() { $user = UserModel::fromArray(array('lastname' => 'User test', 'firstname' => 'User test', 'email' => '*****@*****.**', 'login' => 'test', 'user_acl_role_id' => 1)); $user->setPassword('test'); $user->save(); $this->object->setUserId($user->getId()); $this->assertInstanceOf('Gc\\User\\Model', $this->object->getUser()); $user->delete(); unset($user); }
/** * Test * * @return void */ public function testRenderWithHelperVariable() { $template = array(); $template['template'] = '<?= $this->event->getParam(\'user\')->getName() ?> has saved the user model ' . '<a href="<?= $this->url(\'config/user/edit\', array(\'id\' => $this->event->getParam' . '(\'object\')->getId())) ?>"><?= $this->event->getParam(\'object\')->getId() ?></a>'; $template['event_identifier'] = 'Gc\\User\\Model'; $template['event_name'] = 'on.something'; $result = 'Pierre Rambaud has saved the user model ' . '<a href="/admin/config/user/edit/1">1</a>'; $event = new Event(); $user = new UserModel(); $user->setFirstname('Pierre'); $user->setLastname('Rambaud'); $event->setParam('user', $user); $user = new UserModel(); $user->setData('id', 1); $event->setParam('object', $user); $this->assertEquals($result, $this->object->render($event, $template)); }
/** * Retrieve user who trigger the event * * @return boolean|\Gc\User\Model */ public function getUser() { if ($this->hasData('user') === false) { $this->setData('user', UserModel::fromId($this->getUserId())); } return $this->getData('user'); }
/** * Initiliaze from id * * @param integer $userId User id * * @return \Gc\User\Model */ public static function fromId($userId) { $userTable = new Model(); $row = $userTable->fetchRow($userTable->select(array('id' => (int) $userId))); $userTable->events()->trigger(__CLASS__, 'before.load', $userTable); if (!empty($row)) { $userTable->setData((array) $row); $userTable->unsetData('password'); $userTable->setOrigData(); $userTable->events()->trigger(__CLASS__, 'after.load', $userTable); return $userTable; } else { $userTable->events()->trigger(__CLASS__, 'after.load.failed', $userTable); return false; } }
/** * Test * * @return void */ public function testGetName() { $this->assertEquals('Test Test', $this->object->getName()); }
/** * Check user acl * * @param UserModel $userModel User model * * @return \Zend\Http\Response|null */ protected function checkAcl(UserModel $userModel) { if (!empty($this->aclPage) and $userModel->getRole()->getName() !== RoleModel::PROTECTED_NAME) { $permission = null; $acl = $userModel->getAcl(true); if ($this->aclPage['resource'] == 'modules') { $moduleId = $this->getRouteMatch()->getParam('m'); if (empty($moduleId)) { $action = $this->getRouteMatch()->getParam('action'); $permission = $action === 'index' ? 'list' : $action; } else { $moduleModel = ModuleModel::fromId($moduleId); if (!empty($moduleModel)) { $permission = $moduleModel->getName(); } } } else { $permission = empty($this->aclPage['permission']) ? null : $this->aclPage['permission']; if ($this->aclPage['permission'] != 'index' and !in_array($this->aclPage['resource'], array('content', 'stats'))) { $action = $this->getRouteMatch()->getParam('action'); $permission .= (!empty($permission) ? '/' : '') . ($action === 'index' ? 'list' : $action); } } if (!$acl->isAllowed($userModel->getRole()->getName(), $this->aclPage['resource'], $permission)) { return $this->redirect()->toRoute('config/user/forbidden'); } } }