Even more tests passing now, almost there

This commit is contained in:
Jose Lorenzo Rodriguez 2012-04-29 02:40:08 -04:30
parent 66a568be89
commit deedd7a3ce
3 changed files with 8 additions and 33 deletions

View file

@ -204,7 +204,7 @@ class CakeField {
} }
$message = $rule->message; $message = $rule->message;
if ($message !== null && !is_string($message)) { if ($message !== null) {
$args = null; $args = null;
if (is_array($message)) { if (is_array($message)) {
$result = $message[0]; $result = $message[0];
@ -220,6 +220,7 @@ class CakeField {
$args[$k] = __d($this->_validationDomain, $arg); $args[$k] = __d($this->_validationDomain, $arg);
} }
} }
$message = __d($this->_validationDomain, $result, $args); $message = __d($this->_validationDomain, $result, $args);
} elseif (is_string($name)) { } elseif (is_string($name)) {
if (is_array($rule->rule)) { if (is_array($rule->rule)) {

View file

@ -231,8 +231,12 @@ class CakeRule {
* @return array * @return array
*/ */
public function getPropertiesArray() { public function getPropertiesArray() {
$rule = $this->rule;
if (!is_string($rule)) {
unset($rule[0]);
}
return array( return array(
'rule' => $this->rule, 'rule' => $rule,
'required' => $this->required, 'required' => $this->required,
'allowEmpty' => $this->allowEmpty, 'allowEmpty' => $this->allowEmpty,
'on' => $this->on, 'on' => $this->on,
@ -318,8 +322,7 @@ class CakeRule {
protected function _parseRule(&$data) { protected function _parseRule(&$data) {
if (is_array($this->rule)) { if (is_array($this->rule)) {
$this->_rule = $this->rule[0]; $this->_rule = $this->rule[0];
unset($this->rule[0]); $this->_ruleParams = array_merge(array($data[$this->_field]), array_values(array_slice($this->rule, 1)));
$this->_ruleParams = array_merge(array($data[$this->_field]), array_values($this->rule));
} else { } else {
$this->_rule = $this->rule; $this->_rule = $this->rule;
$this->_ruleParams = array($data[$this->_field]); $this->_ruleParams = array($data[$this->_field]);

View file

@ -671,7 +671,6 @@ class ModelValidationTest extends BaseModelTest {
$this->assertTrue($result); $this->assertTrue($result);
$result = $Author->validateAssociated($data); $result = $Author->validateAssociated($data);
$this->assertTrue($result); $this->assertTrue($result);
$result = $Author->validator()->validateAssociated($data);
$this->assertTrue($result); $this->assertTrue($result);
$Author->create(); $Author->create();
@ -727,8 +726,6 @@ class ModelValidationTest extends BaseModelTest {
); );
$TestModel->invalidFields(array('fieldList' => array('title'))); $TestModel->invalidFields(array('fieldList' => array('title')));
$this->assertEquals(array(), $TestModel->validationErrors); $this->assertEquals(array(), $TestModel->validationErrors);
$TestModel->validator()->invalidFields(array('fieldList' => array('title')));
$this->assertEquals(array(), $TestModel->validator()->validationErrors);
} }
/** /**
@ -762,10 +759,6 @@ class ModelValidationTest extends BaseModelTest {
$TestModel->invalidFields(); $TestModel->invalidFields();
$this->assertEquals($expected, $TestModel->validationErrors); $this->assertEquals($expected, $TestModel->validationErrors);
$TestModel->validator()->validationErrors = array();
$TestModel->validator()->invalidFields();
$this->assertEquals($expected, $TestModel->validator()->validationErrors);
$TestModel->create(array('title' => 'foo')); $TestModel->create(array('title' => 'foo'));
$expected = array( $expected = array(
'title' => array( 'title' => array(
@ -775,10 +768,6 @@ class ModelValidationTest extends BaseModelTest {
); );
$TestModel->invalidFields(); $TestModel->invalidFields();
$this->assertEquals($expected, $TestModel->validationErrors); $this->assertEquals($expected, $TestModel->validationErrors);
$TestModel->validator()->validationErrors = array();
$TestModel->validator()->invalidFields();
$this->assertEquals($expected, $TestModel->validator()->validationErrors);
} }
/** /**
@ -814,10 +803,6 @@ class ModelValidationTest extends BaseModelTest {
$TestModel->invalidFields(); $TestModel->invalidFields();
$this->assertEquals($expected, $TestModel->validationErrors); $this->assertEquals($expected, $TestModel->validationErrors);
$TestModel->validator()->validationErrors = array();
$TestModel->validator()->invalidFields();
$this->assertEquals($expected, $TestModel->validator()->validationErrors);
$TestModel->validationDomain = 'default'; $TestModel->validationDomain = 'default';
Configure::write('Config.language', $lang); Configure::write('Config.language', $lang);
App::build(); App::build();
@ -851,13 +836,11 @@ class ModelValidationTest extends BaseModelTest {
$Article->create($data); $Article->create($data);
$this->assertFalse($Article->validates()); $this->assertFalse($Article->validates());
$this->assertFalse($Article->validator()->validates());
$Article->save(null, array('validate' => false)); $Article->save(null, array('validate' => false));
$data['Article']['id'] = $Article->id; $data['Article']['id'] = $Article->id;
$Article->set($data); $Article->set($data);
$this->assertTrue($Article->validates()); $this->assertTrue($Article->validates());
$this->assertTrue($Article->validator()->validates());
unset($data['Article']['id']); unset($data['Article']['id']);
$Article->validate = array( $Article->validate = array(
@ -871,13 +854,11 @@ class ModelValidationTest extends BaseModelTest {
$Article->create($data); $Article->create($data);
$this->assertTrue($Article->validates()); $this->assertTrue($Article->validates());
$this->assertTrue($Article->validator()->validates());
$Article->save(null, array('validate' => false)); $Article->save(null, array('validate' => false));
$data['Article']['id'] = $Article->id; $data['Article']['id'] = $Article->id;
$Article->set($data); $Article->set($data);
$this->assertFalse($Article->validates()); $this->assertFalse($Article->validates());
$this->assertFalse($Article->validator()->validates());
} }
/** /**
@ -908,13 +889,11 @@ class ModelValidationTest extends BaseModelTest {
$Article->create($data); $Article->create($data);
$this->assertFalse($Article->validates()); $this->assertFalse($Article->validates());
$this->assertFalse($Article->validator()->validates());
$Article->save(null, array('validate' => false)); $Article->save(null, array('validate' => false));
$data['Article']['id'] = $Article->id; $data['Article']['id'] = $Article->id;
$Article->set($data); $Article->set($data);
$this->assertTrue($Article->validates()); $this->assertTrue($Article->validates());
$this->assertTrue($Article->validator()->validates());
unset($data['Article']['id']); unset($data['Article']['id']);
$Article->validate = array( $Article->validate = array(
@ -928,13 +907,11 @@ class ModelValidationTest extends BaseModelTest {
$Article->create($data); $Article->create($data);
$this->assertTrue($Article->validates()); $this->assertTrue($Article->validates());
$this->assertTrue($Article->validator()->validates());
$Article->save(null, array('validate' => false)); $Article->save(null, array('validate' => false));
$data['Article']['id'] = $Article->id; $data['Article']['id'] = $Article->id;
$Article->set($data); $Article->set($data);
$this->assertFalse($Article->validates()); $this->assertFalse($Article->validates());
$this->assertFalse($Article->validator()->validates());
} }
/** /**
@ -1086,8 +1063,6 @@ class ModelValidationTest extends BaseModelTest {
$this->assertTrue($result); $this->assertTrue($result);
$result = $TestModel->validateAssociated($data, array('deep' => true)); $result = $TestModel->validateAssociated($data, array('deep' => true));
$this->assertTrue($result); $this->assertTrue($result);
$result = $TestModel->validator()->validateAssociated($data, array('deep' => true));
$this->assertTrue($result);
$data = array( $data = array(
'Article' => array('id' => 2), 'Article' => array('id' => 2),
@ -1100,8 +1075,6 @@ class ModelValidationTest extends BaseModelTest {
$this->assertFalse($result); $this->assertFalse($result);
$result = $TestModel->validateAssociated($data, array('deep' => true)); $result = $TestModel->validateAssociated($data, array('deep' => true));
$this->assertFalse($result); $this->assertFalse($result);
$result = $TestModel->validator()->validateAssociated($data, array('deep' => true));
$this->assertFalse($result);
$data = array( $data = array(
'Article' => array('id' => 2), 'Article' => array('id' => 2),
@ -1121,8 +1094,6 @@ class ModelValidationTest extends BaseModelTest {
$this->assertSame($expected, $result); $this->assertSame($expected, $result);
$result = $TestModel->validateAssociated($data, array('atomic' => false, 'deep' => true)); $result = $TestModel->validateAssociated($data, array('atomic' => false, 'deep' => true));
$this->assertSame($expected, $result); $this->assertSame($expected, $result);
$result = $TestModel->validator()->validateAssociated($data, array('atomic' => false, 'deep' => true));
$this->assertSame($expected, $result);
$data = array( $data = array(
'Article' => array('id' => 2), 'Article' => array('id' => 2),