Permalink
Browse files

Removed more redundant lines in ModelValidation tests

  • Loading branch information...
1 parent 18c2611 commit 30761f91536b2c0e7b41c6dc3c81ac0418a85354 @lorenzo lorenzo committed Apr 29, 2012
Showing with 3 additions and 77 deletions.
  1. +3 −77 lib/Cake/Test/Case/Model/ModelValidationTest.php
View
80 lib/Cake/Test/Case/Model/ModelValidationTest.php
@@ -126,7 +126,6 @@ public function testValidationParams() {
*/
public function testInvalidFieldsWithFieldListParams() {
$TestModel = new ValidationTest1();
- $Validator = new ModelValidator($TestModel);
$TestModel->validate = $validate = array(
'title' => array(
'rule' => 'alphaNumeric',
@@ -142,35 +141,27 @@ public function testInvalidFieldsWithFieldListParams() {
'title' => array('This field cannot be left blank')
);
$this->assertEquals($expected, $TestModel->validationErrors);
- $Validator->invalidFields(array('fieldList' => array('title')));
- $this->assertEquals($expected, $Validator->validationErrors);
- $TestModel->validationErrors = $Validator->validatiorErrors = array();
+ $TestModel->validationErrors = array();
$TestModel->invalidFields(array('fieldList' => array('name')));
$expected = array(
'name' => array('This field cannot be left blank')
);
$this->assertEquals($expected, $TestModel->validationErrors);
- $Validator->invalidFields(array('fieldList' => array('name')));
- $this->assertEquals($expected, $Validator->validationErrors);
- $TestModel->validationErrors = $Validator->validatiorErrors = array();
+ $TestModel->validationErrors = array();
$TestModel->invalidFields(array('fieldList' => array('name', 'title')));
$expected = array(
'name' => array('This field cannot be left blank'),
'title' => array('This field cannot be left blank')
);
$this->assertEquals($expected, $TestModel->validationErrors);
- $Validator->invalidFields(array('fieldList' => array('title', 'name')));
- $this->assertEquals($expected, $Validator->validationErrors);
- $TestModel->validationErrors = $Validator->validatiorErrors = array();
+ $TestModel->validationErrors = array();
$TestModel->whitelist = array('name');
$TestModel->invalidFields();
$expected = array('name' => array('This field cannot be left blank'));
$this->assertEquals($expected, $TestModel->validationErrors);
- $Validator->invalidFields();
- $this->assertEquals($expected, $Validator->validationErrors);
$this->assertEquals($TestModel->validate, $validate);
}
@@ -182,7 +173,6 @@ public function testInvalidFieldsWithFieldListParams() {
*/
public function testInvalidFieldsWhitelist() {
$TestModel = new ValidationTest1();
- $Validator = $TestModel->validator();
$TestModel->validate = array(
'title' => array(
'rule' => 'alphaNumeric',
@@ -198,7 +188,6 @@ public function testInvalidFieldsWhitelist() {
$expected = array('name' => array('This field cannot be left blank'));
$this->assertEquals($expected, $TestModel->validationErrors);
- $this->assertEquals($expected, $Validator->validationErrors);
}
/**
@@ -208,7 +197,6 @@ public function testInvalidFieldsWhitelist() {
*/
public function testValidates() {
$TestModel = new TestValidate();
- $Validator = new ModelValidator($TestModel);
$TestModel->validate = array(
'user_id' => 'numeric',
@@ -225,8 +213,6 @@ public function testValidates() {
$this->assertEquals($data, $result);
$result = $TestModel->validates();
$this->assertFalse($result);
- $result = $Validator->validates();
- $this->assertFalse($result);
$data = array('TestValidate' => array(
'user_id' => '1',
@@ -235,8 +221,6 @@ public function testValidates() {
));
$result = $TestModel->create($data) && $TestModel->validates();
$this->assertTrue($result);
- $result = $Validator->validates();
- $this->assertTrue($result);
$data = array('TestValidate' => array(
'user_id' => '1',
@@ -247,8 +231,6 @@ public function testValidates() {
$this->assertEquals($data, $result);
$result = $TestModel->validates();
$this->assertTrue($result);
- $result = $Validator->validates();
- $this->assertTrue($result);
$data = array('TestValidate' => array(
'user_id' => '1',
@@ -259,8 +241,6 @@ public function testValidates() {
$this->assertEquals($data, $result);
$result = $TestModel->validates();
$this->assertTrue($result);
- $result = $Validator->validates();
- $this->assertTrue($result);
$TestModel->validate['modified'] = array('allowEmpty' => true, 'rule' => 'date');
@@ -274,8 +254,6 @@ public function testValidates() {
$this->assertEquals($data, $result);
$result = $TestModel->validates();
$this->assertTrue($result);
- $result = $Validator->validates();
- $this->assertTrue($result);
$data = array('TestValidate' => array(
'user_id' => '1',
@@ -287,8 +265,6 @@ public function testValidates() {
$this->assertEquals($data, $result);
$result = $TestModel->validates();
$this->assertTrue($result);
- $result = $Validator->validates();
- $this->assertTrue($result);
$data = array('TestValidate' => array(
'user_id' => '1',
@@ -300,8 +276,6 @@ public function testValidates() {
$this->assertEquals($data, $result);
$result = $TestModel->validates();
$this->assertFalse($result);
- $result = $Validator->validates();
- $this->assertFalse($result);
$data = array('TestValidate' => array(
'user_id' => '1',
@@ -313,8 +287,6 @@ public function testValidates() {
$this->assertEquals($data, $result);
$result = $TestModel->validates();
$this->assertFalse($result);
- $result = $Validator->validates();
- $this->assertFalse($result);
$data = array('TestValidate' => array(
'user_id' => '1',
@@ -326,8 +298,6 @@ public function testValidates() {
$this->assertEquals($data, $result);
$result = $TestModel->validates();
$this->assertFalse($result);
- $result = $Validator->validates();
- $this->assertFalse($result);
$TestModel->validate['modified'] = array('allowEmpty' => false, 'rule' => 'date');
@@ -336,30 +306,22 @@ public function testValidates() {
$this->assertEquals($data, $result);
$result = $TestModel->validates();
$this->assertFalse($result);
- $result = $Validator->validates();
- $this->assertFalse($result);
$data = array('TestValidate' => array('modified' => false));
$result = $TestModel->create($data);
$this->assertEquals($data, $result);
$result = $TestModel->validates();
$this->assertFalse($result);
- $result = $Validator->validates();
- $this->assertFalse($result);
$data = array('TestValidate' => array('modified' => ''));
$result = $TestModel->create($data);
$this->assertEquals($data, $result);
- $result = $TestModel->validates();
- $this->assertFalse($result);
$data = array('TestValidate' => array(
'modified' => '2007-05-01'
));
$result = $TestModel->create($data);
$this->assertEquals($data, $result);
- $result = $TestModel->validates();
- $this->assertTrue($result);
$TestModel->validate['slug'] = array('allowEmpty' => false, 'rule' => array('maxLength', 45));
@@ -373,8 +335,6 @@ public function testValidates() {
$this->assertEquals($data, $result);
$result = $TestModel->validates();
$this->assertFalse($result);
- $result = $Validator->validates();
- $this->assertFalse($result);
$data = array('TestValidate' => array(
'user_id' => '1',
@@ -388,8 +348,6 @@ public function testValidates() {
$this->assertTrue($result);
$result = $Validator->validates();
$this->assertTrue($result);
- $result = $Validator->validates();
- $this->assertTrue($result);
$data = array('TestValidate' => array(
'user_id' => '1',
@@ -401,8 +359,6 @@ public function testValidates() {
$this->assertEquals($data, $result);
$result = $TestModel->validates();
$this->assertFalse($result);
- $result = $Validator->validates();
- $this->assertFalse($result);
$TestModel->validate = array(
'number' => array(
@@ -423,8 +379,6 @@ public function testValidates() {
$this->assertEquals($data, $result);
$result = $TestModel->validates();
$this->assertFalse($result);
- $result = $Validator->validates();
- $this->assertFalse($result);
$data = array('TestValidate' => array(
'title' => 'title',
@@ -434,8 +388,6 @@ public function testValidates() {
$this->assertEquals($data, $result);
$result = $TestModel->validates();
$this->assertFalse($result);
- $result = $Validator->validates();
- $this->assertFalse($result);
$data = array('TestValidate' => array(
'title' => 'title',
@@ -445,8 +397,6 @@ public function testValidates() {
$this->assertEquals($data, $result);
$result = $TestModel->validates();
$this->assertTrue($result);
- $result = $Validator->validates();
- $this->assertTrue($result);
$data = array('TestValidate' => array(
'title' => 'title',
@@ -456,8 +406,6 @@ public function testValidates() {
$this->assertEquals($data, $result);
$result = $TestModel->validates();
$this->assertTrue($result);
- $result = $Validator->validates();
- $this->assertTrue($result);
$TestModel->validate = array(
'number' => array(
@@ -478,8 +426,6 @@ public function testValidates() {
$this->assertEquals($data, $result);
$result = $TestModel->validates();
$this->assertFalse($result);
- $result = $Validator->validates();
- $this->assertFalse($result);
$data = array('TestValidate' => array(
'title' => 'title',
@@ -489,8 +435,6 @@ public function testValidates() {
$this->assertEquals($data, $result);
$result = $TestModel->validates();
$this->assertFalse($result);
- $result = $Validator->validates();
- $this->assertFalse($result);
$TestModel->validate = array(
'title' => array(
@@ -503,24 +447,18 @@ public function testValidates() {
$this->assertEquals($data, $result);
$result = $TestModel->validates();
$this->assertFalse($result);
- $result = $Validator->validates();
- $this->assertFalse($result);
$data = array('TestValidate' => array('title' => 'new title'));
$result = $TestModel->create($data);
$this->assertEquals($data, $result);
$result = $TestModel->validates();
$this->assertFalse($result);
- $result = $Validator->validates();
- $this->assertFalse($result);
$data = array('TestValidate' => array('title' => 'title-new'));
$result = $TestModel->create($data);
$this->assertEquals($data, $result);
$result = $TestModel->validates();
$this->assertTrue($result);
- $result = $Validator->validates();
- $this->assertTrue($result);
$TestModel->validate = array('title' => array(
'allowEmpty' => true,
@@ -531,8 +469,6 @@ public function testValidates() {
$this->assertEquals($data, $result);
$result = $TestModel->validates();
$this->assertTrue($result);
- $result = $Validator->validates();
- $this->assertTrue($result);
$TestModel->validate = array(
'title' => array(
@@ -545,8 +481,6 @@ public function testValidates() {
$this->assertEquals($data, $result);
$result = $TestModel->validates();
$this->assertTrue($result);
- $result = $Validator->validates();
- $this->assertTrue($result);
$TestModel->validate = array(
'title' => array(
@@ -557,8 +491,6 @@ public function testValidates() {
$this->assertEquals($data, $result);
$result = $TestModel->validates();
$this->assertFalse($result);
- $result = $Validator->validates();
- $this->assertFalse($result);
$data = array('TestValidate' => array(
'title' => 'My Article With a Different Title'
@@ -567,8 +499,6 @@ public function testValidates() {
$this->assertEquals($data, $result);
$result = $TestModel->validates();
$this->assertTrue($result);
- $result = $Validator->validates();
- $this->assertTrue($result);
$TestModel->validate = array(
'title' => array(
@@ -589,8 +519,6 @@ public function testValidates() {
$this->assertEquals($expected, $result);
$result = $Validator->validates();
$this->assertFalse($result);
- $result = $Validator->validationErrors;
- $this->assertEquals($expected, $result);
$TestModel->validate = array(
'title' => array(
@@ -640,7 +568,6 @@ public function testValidatesWithAssociations() {
$Something = new Something();
$JoinThing = $Something->JoinThing;
- $Validator = $Something->JoinThing->validator();
$JoinThing->validate = array('doomed' => array('rule' => 'notEmpty'));
@@ -650,7 +577,6 @@ public function testValidatesWithAssociations() {
$result = $Something->save($data);
$this->assertFalse($result, 'Save occurred even when with models failed. %s');
$this->assertEquals($expectedError, $JoinThing->validationErrors);
- $this->assertEquals($expectedError, $Validator->validationErrors);
$count = $Something->find('count', array('conditions' => array('Something.id' => $data['Something']['id'])));
$this->assertSame($count, 0);

0 comments on commit 30761f9

Please sign in to comment.