Ejemplo n.º 1
0
 public function indexAction()
 {
     if (!($user = $this->authenticationService->getUser())) {
         throw new UnauthorizedAccessException('You must be logged in.');
     }
     /** @var Request $request */
     $request = $this->getRequest();
     $this->form->bind($user);
     if ($request->isPost()) {
         $this->form->setData($request->getPost()->toArray());
         if ($this->form->isValid()) {
             $this->repositoryService->store($user);
             $vars = array('valid' => true);
             $this->notification()->success('Password successfully changed');
         } else {
             // form is invalid
             $vars = array('valid' => false);
             // @TODO the messages are distributed to the hierarchy of the subElements, either we reduce that to flat plain text, or we make a message handling in JS
             $messages = $this->form->getMessages();
             $this->notification()->error('Password could not be changed');
         }
     }
     $vars['form'] = $this->form;
     if ($request->isXmlHttpRequest()) {
         return new JsonModel($vars);
     }
     return $vars;
 }
Ejemplo n.º 2
0
 public function testIndexAction_WithPostRequest()
 {
     $postData = array('valid data');
     $request = new Request();
     $request->setMethod(Request::METHOD_POST);
     $request->setPost(new Parameters($postData));
     $userEntity = UserEntityProvider::createEntityWithRandomData();
     $this->authenticationServiceMock->expects($this->once())->method('getUser')->willReturn($userEntity);
     $this->formMock->expects($this->once())->method('bind')->with($userEntity);
     $this->formMock->expects($this->once())->method('setData')->with($postData);
     $this->formMock->expects($this->once())->method('isValid')->willReturn(true);
     $this->repositoriesMock->expects($this->once())->method('store')->with($userEntity);
     $result = $this->controller->dispatch($request);
     $expected = array('valid' => true, 'form' => $this->formMock);
     $this->assertResponseStatusCode(Response::STATUS_CODE_200);
     $this->assertSame($expected, $result);
 }