Skip to content

Commit

Permalink
Removed more redundant lines in ModelValidation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Apr 29, 2012
1 parent 18c2611 commit 30761f9
Showing 1 changed file with 3 additions and 77 deletions.
80 changes: 3 additions & 77 deletions lib/Cake/Test/Case/Model/ModelValidationTest.php
Expand Up @@ -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',
Expand All @@ -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);
}
Expand All @@ -182,7 +173,6 @@ public function testInvalidFieldsWithFieldListParams() {
*/
public function testInvalidFieldsWhitelist() {
$TestModel = new ValidationTest1();
$Validator = $TestModel->validator();
$TestModel->validate = array(
'title' => array(
'rule' => 'alphaNumeric',
Expand All @@ -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);
}

/**
Expand All @@ -208,7 +197,6 @@ public function testInvalidFieldsWhitelist() {
*/
public function testValidates() {
$TestModel = new TestValidate();
$Validator = new ModelValidator($TestModel);

$TestModel->validate = array(
'user_id' => 'numeric',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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');

Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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');

Expand All @@ -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));

Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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(
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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(
Expand All @@ -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',
Expand All @@ -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(
Expand All @@ -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,
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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'
Expand All @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -640,7 +568,6 @@ public function testValidatesWithAssociations() {

$Something = new Something();
$JoinThing = $Something->JoinThing;
$Validator = $Something->JoinThing->validator();

$JoinThing->validate = array('doomed' => array('rule' => 'notEmpty'));

Expand All @@ -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);

Expand Down

0 comments on commit 30761f9

Please sign in to comment.