/** * Form for displaying and merging duplicate clients * * @return array|\Zend\Http\Response array(form) or Redirect response */ public function manageAction() { if ($this->getRequest()->isPost()) { $this->_showDuplicates->setData($this->params()->fromPost()); if ($this->_showDuplicates->isValid()) { $data = $this->_showDuplicates->getData(); $this->_duplicates->merge($data['clients'], $data['mergeCustomFields'], $data['mergeGroups'], $data['mergePackages']); $this->flashMessenger()->addSuccessMessage('The selected clients have been merged.'); return $this->redirectToRoute('duplicates', 'index'); } } $this->setActiveMenu('Inventory', 'Duplicates'); $ordering = $this->getOrder('Id', 'asc'); $clients = $this->_duplicates->find($this->params()->fromQuery('criteria'), $ordering['order'], $ordering['direction']); $this->_showDuplicates->setOptions(array('clients' => $clients, 'order' => $ordering['order'], 'direction' => $ordering['direction'])); return array('form' => $this->_showDuplicates); }
public function testManageActionPostInvalid() { $this->_showDuplicates->expects($this->once())->method('setData'); $this->_showDuplicates->expects($this->once())->method('isValid')->will($this->returnValue(false)); $this->_showDuplicates->expects($this->never())->method('getData'); $this->_showDuplicates->expects($this->once())->method('setOptions')->with(array('clients' => 'client_list', 'order' => 'Id', 'direction' => 'asc')); $this->_showDuplicates->expects($this->once())->method('getMessages')->willReturn(array('clients' => array('invalid'))); $this->_showDuplicates->expects($this->once())->method('render')->willReturn('<form></form>'); $this->_duplicates->expects($this->once())->method('find')->with('Name', 'Id', 'asc')->willReturn('client_list'); $this->_duplicates->expects($this->never())->method('merge'); $this->dispatch('/console/duplicates/manage/?criteria=Name', 'POST'); $this->assertResponseStatusCode(200); $this->assertXPathQueryCount('//ul', 1); $this->assertXPathQueryCount('//li', 1); $this->assertXPathQueryContentContains('//ul[@class="error"]/li', 'invalid'); $this->assertXpathQuery('//form'); }