Exemplo n.º 1
0
 /**
  * @param HttpRequest $request
  *
  * @return \Zend\View\Model\ViewModel
  */
 public function build(HttpRequest $request, SmartServiceResult $result, $action)
 {
     $viewModel = null;
     if ($request->isXmlHttpRequest()) {
         $viewModel = new JsonModel();
         $viewModel->setTerminal(true);
     } else {
         $viewModel = new \Zend\View\Model\ViewModel();
         $viewModel->setVariable('entity', $result->getEntity());
         $viewModel->setVariable('form', $result->getForm());
         $viewModel->setVariable('list', $result->getList());
         $viewModel->setTemplate(sprintf($this->getTemplate(), $action));
     }
     return $viewModel;
 }
Exemplo n.º 2
0
 /**
  * @param \Phpro\SmartCrud\Gateway\CrudGatewayInterface $gateway
  * @param \Zend\EventManager\EventManager               $eventManager
  * @param \Zend\Form\Form                               $form
  * @param \Phpro\SmartCrud\Service\SmartServiceResult   $result
  */
 public function it_should_handle_valid_data($gateway, $eventManager, $form, $result)
 {
     $entity = new \StdClass();
     $postData = $this->getMockPostData();
     $gateway->loadEntity('entityKey', null)->shouldBecalled()->willReturn($entity);
     $gateway->delete($entity, $postData)->shouldBecalled()->willReturn(true);
     $result->setSuccess(true)->shouldBeCalled();
     $result->setEntity($entity)->shouldBeCalled();
     $this->setEntityKey('entityKey');
     $this->setGateway($gateway);
     $this->setResult($result);
     $this->setForm($form);
     $this->run(null, $this->getMockPostData())->shouldReturn($result);
     $eventManager->trigger(Argument::which('getName', CrudEvent::INVALID_DELETE))->shouldNotBeCalled();
     $eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_DELETE))->shouldBeCalled();
     $eventManager->trigger(Argument::which('getName', CrudEvent::AFTER_DELETE))->shouldBeCalled();
 }
Exemplo n.º 3
0
 /**
  * @param \Phpro\SmartCrud\Gateway\CrudGatewayInterface $gateway
  * @param \Zend\EventManager\EventManager               $eventManager
  * @param \Phpro\SmartCrud\Service\SmartServiceResult   $result
  */
 public function it_should_return_a_result($gateway, $eventManager, $result)
 {
     $entity = new \StdClass();
     $entity->id = 1;
     $postData = null;
     $gateway->loadEntity('entityKey', $entity->id)->shouldBecalled()->willReturn($entity);
     $result->setSuccess(Argument::any())->shouldBeCalled();
     $result->setForm(Argument::any())->shouldNotBeCalled();
     $result->setEntity($entity)->shouldBeCalled();
     $this->setEntityKey('entityKey');
     $this->setGateway($gateway);
     $this->setResult($result);
     $this->run($entity->id, $postData)->shouldReturn($result);
     $eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_DATA_VALIDATION))->shouldNotBeCalled();
     $eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_READ))->shouldBeCalled();
     $eventManager->trigger(Argument::which('getName', CrudEvent::AFTER_READ))->shouldBeCalled();
 }
Exemplo n.º 4
0
 /**
  * @param \Phpro\SmartCrud\Gateway\CrudGatewayInterface $gateway
  * @param \Zend\EventManager\EventManager               $eventManager
  * @param \Phpro\SmartCrud\Service\PaginatorServiceFactory $paginatorFactory
  * @param \Phpro\SmartCrud\Service\SmartServiceResult   $result
  * @param \Zend\Paginator\Paginator $paginator
  * @param \Phpro\SmartCrud\Query\QueryProviderInterface $queryProvider
  */
 public function it_should_return_a_result($gateway, $eventManager, $paginatorFactory, $result, $paginator, $queryProvider)
 {
     $getData = array();
     $list = array();
     $this->setQueryProvider($queryProvider);
     $gateway->getList('entityKey', $getData, $queryProvider)->willReturn($list);
     $paginatorFactory->createPaginator($list, Argument::cetera())->willReturn($paginator);
     $this->setPaginatorFactory($paginatorFactory);
     $result->setSuccess(Argument::any())->shouldBeCalled();
     $result->setForm(Argument::any())->shouldNotBeCalled();
     $result->setList($paginator)->shouldBeCalled();
     $this->setEntityKey('entityKey');
     $this->setGateway($gateway);
     $this->setResult($result);
     $this->run(Argument::any(), $getData)->shouldReturn($result);
     $eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_LIST))->shouldBeCalled();
     $eventManager->trigger(Argument::which('getName', CrudEvent::AFTER_LIST))->shouldBeCalled();
 }
Exemplo n.º 5
0
 /**
  * @param \Zend\Http\PhpEnvironment\Request            $request
  * @param \Zend\Mvc\MvcEvent                           $mvcEvent
  * @param \Phpro\SmartCrud\Service\DeleteService       $smartService
  * @param \Phpro\SmartCrud\Service\SmartServiceResult  $smartResult
  * @param \Zend\Mvc\Controller\Plugin\Params           $params
  * @param \Phpro\SmartCrud\View\Model\ViewModelBuilder $viewModelBuilder
  */
 public function it_should_handle_invalid_post_to_a_delete_action($request, $mvcEvent, $smartService, $smartResult, $params, $viewModelBuilder)
 {
     $postParameters = array('property' => 'value');
     $action = 'delete';
     $smartResult->isSuccessFull()->shouldBeCalled()->willReturn(false);
     $smartService->run(Argument::any(), Argument::any())->shouldBeCalled()->willReturn($smartResult);
     $this->mockInvalidPost($request, $mvcEvent, $smartResult, $smartService, $params, $action, $postParameters, $viewModelBuilder);
 }
Exemplo n.º 6
0
 /**
  * @param \Phpro\SmartCrud\Gateway\CrudGatewayInterface $gateway
  * @param \Zend\EventManager\EventManager               $eventManager
  * @param \Zend\Form\Form                               $form
  * @param \Phpro\SmartCrud\Service\SmartServiceResult   $result
  */
 public function it_should_handle_valid_data($gateway, $eventManager, $form, $result)
 {
     $entity = new \StdClass();
     $entity->id = 1;
     $postData = $this->getMockPostData();
     $gateway->loadEntity('entityKey', $entity->id)->shouldBecalled()->willReturn($entity);
     $gateway->update($entity, $postData)->shouldBecalled()->willReturn(true);
     $form->hasValidated()->shouldBeCalled()->willreturn(false);
     $form->bind(Argument::any())->shouldBeCalled();
     $form->bindOnValidate()->shouldBeCalled();
     $form->setData(Argument::exact($this->getMockPostData()))->shouldBeCalled()->willReturn($form);
     $form->isValid()->shouldBeCalled()->willreturn(true);
     $result->setSuccess(true)->shouldBeCalled();
     $result->setForm($form)->shouldBeCalled();
     $result->setEntity($entity)->shouldBeCalled();
     $this->setEntityKey('entityKey');
     $this->setGateway($gateway);
     $this->setForm($form);
     $this->setResult($result);
     $this->run($entity->id, $this->getMockPostData())->shouldReturn($result);
     $eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_DATA_HYDRATION))->shouldBeCalled();
     $eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_DATA_VALIDATION))->shouldBeCalled();
     $eventManager->trigger(Argument::which('getName', CrudEvent::INVALID_UPDATE))->shouldNotBeCalled();
     $eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_UPDATE))->shouldBeCalled();
     $eventManager->trigger(Argument::which('getName', CrudEvent::AFTER_UPDATE))->shouldBeCalled();
 }