Skip to content
Browse files

added tests for custom validation

  • Loading branch information...
1 parent 8364647 commit b0e2f5c71140461818591dd7c22880ec9772ecba @marcopeg marcopeg committed Oct 29, 2012
View
20 lib/Cake/Test/test_app/Controller/CustomValidationObjectController.php
@@ -0,0 +1,20 @@
+<?php
+class CustomValidationObjectController extends AppController {
+
+ public $autoRender = false;
+
+ public $uses = array( 'CustomValidationModel' );
+
+ public function index() {
+ $data = array( 'CustomValidationModel' => array(
+ 'name' => '',
+ 'surname' => '',
+ 'age' => '',
+ 'odd_number' => 23
+ ));
+ $this->CustomValidationModel->set($data);
+ $this->CustomValidationModel->validates();
+ debug($this->CustomValidationModel->validationErrors);
+ }
+
+}
View
19 lib/Cake/Test/test_app/Model/CustomValidationModel.php
@@ -0,0 +1,19 @@
+<?php
+class CustomValidationModel extends AppModel {
+
+ public $useTable = false;
+
+ public $validate = array(
+ 'name' => 'notEmpty',
+ 'surname' => array(
+ 'rule' => 'CustomValidationObject::myCustomRule',
+ 'message' => 'value not accepted'
+ ),
+ 'age' => 'NonExistingObject::nonExistingMethod',
+ 'odd_number' => array(
+ 'rule' => 'CustomValidationObject::odd',
+ 'message' => 'Please insert odd number'
+ )
+ );
+
+}
View
12 lib/Cake/Test/test_app/Model/Validation/CustomValidationObject.php
@@ -0,0 +1,12 @@
+<?php
+class CustomValidationObject {
+
+ public static function odd($value) {
+ return $value & 1;
+ }
+
+ public static function myCustomRule($value) {
+ return self::odd(rand(2,10));
+ }
+
+}

0 comments on commit b0e2f5c

Please sign in to comment.
Something went wrong with that request. Please try again.