コード例 #1
0
 /**
  * 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())));
 }
コード例 #2
0
 public function testFetchById()
 {
     $resultSet = new ResultSet();
     $record = new FeedModel();
     $record->exchangeArray($this->_recordData);
     $feedId = 21;
     $resultSet->initialize(array($record));
     $mockSql = \Mockery::mock('Zend\\Db\\Sql\\Select');
     $mockSql->shouldReceive('select')->andReturn($mockSql);
     $mockSql->shouldReceive('where')->with(array('feedId' => $feedId))->times(1)->andReturn($mockSql);
     $mockTableGateway = \Mockery::mock('Zend\\Db\\TableGateway\\TableGateway');
     $mockTableGateway->shouldReceive('getSql')->andReturn($mockSql);
     $mockTableGateway->shouldReceive('selectWith')->times(1)->with($mockSql)->andReturn($resultSet);
     $mockFeedTable = new FeedTable($mockTableGateway);
     $this->assertEquals($record, $mockFeedTable->fetchById($feedId));
 }