/**
  * Test if when I error is set it will be rendered and values bill be ignored.
  */
 public function testRenderWithError()
 {
     $result = new Result();
     $result->addError('error', 1);
     $view = new JsonView();
     $view->assignValue('test', 'foo');
     $view->setResult($result);
     $this->assertSame(json_encode(['errors' => [['message' => 'error', 'code' => 1]]]), $view->render());
 }
Exemple #2
0
 /**
  * @param string $name
  * @param string $password
  * @return Result
  */
 public function login($name, $password)
 {
     $result = new Result();
     $name = Type::string($name);
     $password = Type::string($password);
     if ($this->isLoggedIn()) {
         $result->addValue($this->session->get('user_id'));
         return $result;
     }
     $user = $this->users->getUserByLoginData($name, $password);
     if ($user) {
         $this->session->set('user_id', $user->getId());
         $result->addValue($user->getId());
     } else {
         $result->addError(L10n::msgReplace('%s is a invalid user or wrong password.', $name));
     }
     return $result;
 }
 /**
  * @param Result $result
  */
 public function setResult(Result $result)
 {
     $this->errors = $result->getErrors();
     foreach ($result->getValues() as $key => $value) {
         $this->assignValue($key, $value);
     }
 }