Skip to content

Commit

Permalink
Adding tests for the new conditional checking feature in the validator
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Jun 21, 2014
1 parent 985d3e0 commit f33850e
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/TestCase/Validation/ValidatorTest.php
Expand Up @@ -245,6 +245,46 @@ public function testNotEmptyAndIsAllowed() {
$this->assertFalse($validator->isEmptyAllowed('title', false));
}

/**
* Tests the allowEmpty method when passing a callback
*
* @return void
*/
public function testAllowEmptyCallback() {
$validator = new Validator;
$allow = true;
$validator->allowEmpty('title', function($context) use (&$allow) {
$this->assertEquals([], $context['data']);
$this->assertEquals([], $context['providers']);
$this->assertTrue($context['newRecord']);
return $allow;
});
$this->assertTrue($validator->isEmptyAllowed('title', true));

$allow = false;
$this->assertFalse($validator->isEmptyAllowed('title', true));
}

/**
* Tests the notEmpty method when passing a callback
*
* @return void
*/
public function testNotEmptyCallback() {
$validator = new Validator;
$prevent = true;
$validator->notEmpty('title', 'error message', function($context) use (&$prevent) {
$this->assertEquals([], $context['data']);
$this->assertEquals([], $context['providers']);
$this->assertFalse($context['newRecord']);
return $prevent;
});
$this->assertFalse($validator->isEmptyAllowed('title', false));

$prevent = false;
$this->assertTrue($validator->isEmptyAllowed('title', false));
}

/**
* Tests the isEmptyAllowed method
*
Expand Down

0 comments on commit f33850e

Please sign in to comment.