/** * Display and manage group memberships * * @return array client, order, direction [, form (Console\Form\GroupMemberships) if groups are available] */ public function groupsAction() { $vars = $this->getOrder('GroupName'); $vars['client'] = $this->_currentClient; $vars['memberships'] = array(); $groups = $this->_groupManager->getGroups(null, null, 'Name'); if ($groups->count()) { $memberships = $this->_currentClient->getGroupMemberships(\Model\Client\Client::MEMBERSHIP_ANY); $data = array(); // Create form data for all groups and actual membership list foreach ($groups as $group) { $id = $group['Id']; $name = $group['Name']; if (isset($memberships[$id])) { $type = $memberships[$id]; $data['Groups'][$name] = $type; if ($type != \Model\Client\Client::MEMBERSHIP_NEVER) { $vars['memberships'][] = array('GroupName' => $name, 'Membership' => $type); } } else { // Default to automatic membership $data['Groups'][$group['Name']] = \Model\Client\Client::MEMBERSHIP_AUTOMATIC; } } $form = $this->_formManager->get('Console\\Form\\GroupMemberships'); $form->setData($data); $form->setAttribute('action', $this->urlFromRoute('client', 'managegroups', array('id' => $this->_currentClient['Id']))); $vars['form'] = $form; } return $vars; }
public function testGroupsActionMember() { $groups = array(array('Id' => 1, 'Name' => 'group1'), array('Id' => 2, 'Name' => 'group2')); $resultSet = new \Zend\Db\ResultSet\ResultSet(); $resultSet->initialize($groups); $memberships = array(1 => \Model\Client\Client::MEMBERSHIP_AUTOMATIC, 2 => \Model\Client\Client::MEMBERSHIP_ALWAYS); $formGroups = array('group1' => \Model\Client\Client::MEMBERSHIP_AUTOMATIC, 'group2' => \Model\Client\Client::MEMBERSHIP_ALWAYS); $form = $this->getApplicationServiceLocator()->get('FormElementManager')->get('Console\\Form\\GroupMemberships'); $form->expects($this->once())->method('render')->will($this->returnValue('<form></form>')); $form->expects($this->once())->method('setData')->with(array('Groups' => $formGroups)); $form->expects($this->once())->method('setAttribute')->with('action', '/console/client/managegroups/?id=1'); $client = $this->createMock('Model\\Client\\Client'); $client->expects($this->once())->method('getGroupMemberships')->with(\Model\Client\Client::MEMBERSHIP_ANY)->willReturn($memberships); $client->method('offsetGet')->will($this->returnValueMap(array(array('Id', 1)))); $this->_clientManager->method('getClient')->willReturn($client); $this->_groupManager->expects($this->once())->method('getGroups')->with(null, null, 'Name')->willReturn($resultSet); $this->dispatch('/console/client/groups/?id=1'); $this->assertResponseStatusCode(200); $this->assertXpathQueryContentContains('//h2', "\nGruppenmitgliedschaften\n"); $this->assertXpathQueryContentContains('//tr[2]/td[1]/a[@href="/console/group/general/?name=group1"]', 'group1'); $this->assertXpathQueryContentContains('//tr[2]/td[2]', "\nautomatisch\n"); $this->assertXpathQueryContentContains('//tr[3]/td[1]/a[@href="/console/group/general/?name=group2"]', 'group2'); $this->assertXpathQueryContentContains('//tr[3]/td[2]', "\nmanuell\n"); $this->assertXpathQueryContentContains('//h2', "\nMitgliedschaften verwalten\n"); $this->assertXPathQuery('//form'); }
public function testDeleteActionPostYesError() { $group = $this->getMock('Model\\Group\\Group'); $group->method('offsetGet')->with('Name')->willReturn('test'); $this->_groupManager->expects($this->once())->method('getGroup')->with('test')->willReturn($group); $this->_groupManager->expects($this->once())->method('deleteGroup')->with($group)->will($this->throwException(new \Model\Group\RuntimeException())); $this->dispatch('/console/group/delete/?name=test', 'POST', array('yes' => 'Yes')); $this->assertRedirectTo('/console/group/index/'); $this->assertEquals(array(), $this->_getControllerPlugin('FlashMessenger')->getCurrentSuccessMessages()); $this->assertEquals(array(array('Group \'%s\' could not be deleted. Try again later.' => 'test')), $this->_getControllerPlugin('FlashMessenger')->getCurrentErrorMessages()); }
public function testProcessExistingGroup() { $group = $this->createMock('Model\\Group\\Group'); $group->expects($this->once())->method('setMembersFromQuery')->with('what', 'filter', 'search', 'operator', 'invert'); $this->_groupManager->expects($this->never())->method('createGroup'); $this->_groupManager->expects($this->once())->method('getGroup')->with('name')->willReturn($group); $data = array('What' => 'what', 'Where' => 'existing', 'ExistingGroup' => 'name'); $form = $this->getMockBuilder('Console\\Form\\AddToGroup')->setMethods(array('getData'))->getMock(); $form->expects($this->once())->method('getData')->will($this->returnValue($data)); $form->setOption('GroupManager', $this->_groupManager); $this->assertEquals($group, $form->process('filter', 'search', 'operator', 'invert')); }
/** * Group deletion form * * @return array|\Zend\Http\Response array(name) or redirect response */ public function deleteAction() { $name = $this->_currentGroup['Name']; if ($this->getRequest()->isPost()) { if ($this->params()->fromPost('yes')) { try { $this->_groupManager->deleteGroup($this->_currentGroup); $this->flashMessenger()->addSuccessMessage(array($this->_('Group \'%s\' was successfully deleted.') => $name)); } catch (\Model\Group\RuntimeException $e) { $this->flashMessenger()->addErrorMessage(array($this->_('Group \'%s\' could not be deleted. Try again later.') => $name)); } return $this->redirectToRoute('group', 'index'); } else { return $this->redirectToRoute('group', 'general', array('name' => $this->_currentGroup['Name'])); } } else { return array('name' => $name); } }