/** * All a user to add and update a feed in the application * * @return ViewModel */ public function manageAction() { $formManager = $this->serviceLocator->get('FormElementManager'); $form = $formManager->get('BabyMonitor\\Forms\\ManageRecordForm'); $feedId = (int) $this->params()->fromRoute('id'); if ($this->getRequest()->isGet()) { if (!empty($feedId)) { if ($feed = $this->_feedTable->fetchById($feedId)) { $form->setData($feed->getArrayCopy()); } else { $this->flashMessenger()->addInfoMessage('Unable to find that feed. Perhaps a new one?'); return $this->redirect()->toRoute(self::DEFAULT_ROUTE, array('action' => 'manage')); } } } if ($this->getRequest()->isPost()) { $form->setData($this->getRequest()->getPost()); if ($form->isValid()) { $feed = new FeedModel(); $feed->exchangeArray($form->getData()); $this->_feedTable->save($feed); if (!is_null($this->_cache)) { $this->_cache->removeItem(self::KEY_ALL_RESULTS); } $this->getEventManager()->trigger('Feed.Modify', $this, array('feedData' => $feed)); return $this->redirect()->toRoute(self::DEFAULT_ROUTE, array()); } } return new ViewModel(array('form' => $form, 'cancelTitle' => $feedId ? "Don't update the record" : "Don't create the record", 'messages' => array('info' => $this->flashMessenger()->hasInfoMessages()))); }
public function testSaveUserWillUpdateExistingUsersIfTheyAlreadyHaveAnId() { $recordData = $this->_recordData; $feedId = $recordData['feedId']; $feed = new FeedModel(); $feed->exchangeArray($this->_recordData); $resultSet = new ResultSet(); $resultSet->setArrayObjectPrototype(new FeedModel()); $resultSet->initialize(array($feed)); $mockTableGateway = \Mockery::mock('Zend\\Db\\TableGateway\\TableGateway'); $mockTableGateway->shouldReceive('update')->with(array('userId' => 21, 'feedDate' => "2012-01-01", 'feedTime' => "12:00:00", 'feedAmount' => 21.04, 'feedTemperature' => 14, 'feedNotes' => "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus mattis vitae nisi eget suscipit. Suspendisse condimentum sapien purus, eu porta dolor elementum vel. Praesent quis nunc dolor. Phasellus in luctus lorem, a tempus velit. Proin varius magna urna, id accumsan ante eleifend eleifend. Nullam id nulla ligula. Praesent id felis vel felis tempor vestibulum. Nulla pretium, tortor eu placerat suscipit, purus ipsum aliquet eros, non dictum mi odio in odio. Morbi ac porta enim. In non purus at dui consequat rhoncus. Nullam libero nisl, rutrum non mi vel, molestie gravida lectus. Sed laoreet vitae sem at tincidunt. Etiam volutpat nunc ut nunc fringilla, at imperdiet urna congue. Sed lacinia sit amet leo id vehicula. Aenean interdum purus id gravida varius."), array('feedId' => $feedId))->andReturn($this->_recordData); $feedTable = new FeedTable($mockTableGateway); $feedTable->save($feed, $feedId); }