public function testValidate()
 {
     $user1 = $user = $this->users('user1');
     $user2 = $user = $this->users('user2');
     // Update collection with wrong email
     $controller = new ApiController('api');
     $controller->method = 'PUT';
     $controller->model = new User('update');
     $controller->data = array(array('id' => $user1->id, 'login' => $user1->login, 'email' => 'wrong_email'), array('id' => $user2->id, 'login' => $user2->login));
     $result = $controller->validate(false);
     $this->assertFalse($result);
     $errors = $controller->getModelErrors();
     $this->assertEquals(1, count($errors));
     $this->assertArrayHasKey('email', $errors[0]);
     // Update collection with right email
     $controller = new ApiController('api');
     $controller->method = 'PUT';
     $controller->model = new User('update');
     $controller->data = array(array('id' => $user1->id, 'login' => $user1->login, 'email' => '*****@*****.**'), array('id' => $user2->id, 'login' => $user2->login));
     $result = $controller->validate(false);
     $this->assertTrue($result);
     $this->assertNull($controller->getModelErrors());
     // Create collection with wrong email
     $controller = new ApiController('api');
     $controller->method = 'POST';
     $controller->model = new User('create');
     $controller->data = array(array('login' => 'new_user_1', 'email' => 'wrong_email.com', 'password' => '1234567', 'password_repeat' => '1234567'), array('login' => 'new_user_2', 'email' => '*****@*****.**', 'password' => '1234567', 'password_repeat' => '1234567'));
     $result = $controller->validate(false);
     $errors = $controller->getModelErrors();
     $this->assertEquals(1, count($errors));
     $this->assertArrayHasKey('email', $errors[0]);
     // Create single record with wrong email
     $controller = new ApiController('api');
     $controller->method = 'POST';
     $controller->model = new User('create');
     $controller->data = array('login' => 'new_user_1', 'email' => 'wrong_email.com', 'password' => '1234567', 'password_repeat' => '1234567');
     $result = $controller->validate(false);
     $errors = $controller->getModelErrors();
     $this->assertFalse($result);
     $this->assertEquals(1, count($errors));
     $this->assertArrayHasKey('email', $errors);
     // Create single record with right email
     $controller = new ApiController('api');
     $controller->method = 'POST';
     $controller->model = new User('create');
     $controller->data = array('login' => 'new_user_1', 'email' => '*****@*****.**', 'password' => '1234567', 'password_repeat' => '1234567');
     $result = $controller->validate(false);
     $this->assertTrue($result);
     $this->assertNull($controller->getModelErrors());
 }