public function testInputFiltersAreSetCorrectly() { $issue = new Issue(); $inputFilter = $issue->getInputFilter(); $this->assertSame(2, $inputFilter->count()); $this->assertTrue($inputFilter->has('id')); $this->assertTrue($inputFilter->has('title')); }
public function testSaveIssueWillUpdateExistingIssuesIfTheyAlreadyHaveAnId() { $issueData = array('id' => 123, 'title' => 'Gun Control'); $issue = new Issue(); $issue->exchangeArray($issueData); $resultSet = new ResultSet(); $resultSet->setArrayObjectPrototype(new Issue()); $resultSet->initialize(array($issue)); $mockTableGateway = $this->getMock('Zend\\Db\\TableGateway\\TableGateway', array('select', 'update'), array(), '', false); $mockTableGateway->expects($this->once())->method('select')->with(array('id' => 123))->will($this->returnValue($resultSet)); $mockTableGateway->expects($this->once())->method('update')->with(array('title' => 'Gun Control', 'user_id' => 1), array('id' => 123)); $issueTable = new IssueTable($mockTableGateway); $issueTable->saveIssue($issue, 1); }
public function addAction() { if (!$this->zfcUserAuthentication()->hasIdentity()) { return $this->redirect()->toRoute('issue'); } $form = new IssueForm(); $form->get('submit')->setValue('Add'); $request = $this->getRequest(); if ($request->isPost()) { $issue = new Issue(); $form->setInputFilter($issue->getInputFilter()); $form->setData($request->getPost()); if ($form->isValid()) { $issue->exchangeArray($form->getData()); $this->getIssueTable()->saveIssue($issue, $this->zfcUserAuthentication()->getIdentity()->getId()); // Redirect to list of issues return $this->redirect()->toRoute('issue'); } } return array('form' => $form); }