浏览代码

Merge pull request #146 from dereuromark/2.x-tests

2.x tests
Mark S. 10 年之前
父节点
当前提交
c7647f524a

+ 3 - 3
Model/Behavior/PasswordableBehavior.php

@@ -91,7 +91,7 @@ class PasswordableBehavior extends ModelBehavior {
 			],
 			'formFieldRepeat' => [
 				'validateNotEmpty' => [
-					'rule' => ['notEmpty'],
+					'rule' => ['notBlank'],
 					'message' => __d('tools', 'valErrPwdRepeat'),
 					'allowEmpty' => true,
 					'last' => true,
@@ -104,8 +104,8 @@ class PasswordableBehavior extends ModelBehavior {
 				],
 			],
 			'formFieldCurrent' => [
-				'notEmpty' => [
-					'rule' => ['notEmpty'],
+				'notBlank' => [
+					'rule' => ['notBlank'],
 					'message' => __d('tools', 'valErrProvideCurrentPwd'),
 					'allowEmpty' => null,
 					'last' => true,

+ 6 - 6
Model/ContactForm.php

@@ -19,8 +19,8 @@ class ContactForm extends ToolsAppModel {
 
 	public $validate = [
 		'name' => [
-			'notEmpty' => [
-				'rule' => ['notEmpty'],
+			'notBlank' => [
+				'rule' => ['notBlank'],
 				'message' => 'valErrMandatoryField',
 				'last' => true
 			]
@@ -33,15 +33,15 @@ class ContactForm extends ToolsAppModel {
 			],
 		],
 		'subject' => [
-			'notEmpty' => [
-				'rule' => ['notEmpty'],
+			'notBlank' => [
+				'rule' => ['notBlank'],
 				'message' => 'valErrMandatoryField',
 				'last' => true
 			]
 		],
 		'message' => [
-			'notEmpty' => [
-				'rule' => ['notEmpty'],
+			'notBlank' => [
+				'rule' => ['notBlank'],
 				'message' => 'valErrMandatoryField',
 				'last' => true
 			]

+ 4 - 4
Model/KeyValue.php

@@ -13,14 +13,14 @@ class KeyValue extends ToolsAppModel {
 
 	public $validate = [
 		'foreign_id' => [
-			'notEmpty' => [
-				'rule' => ['notEmpty'],
+			'notBlank' => [
+				'rule' => ['notBlank'],
 				'message' => 'valErrMandatoryField',
 			],
 		],
 		'key' => [
-			'notEmpty' => [
-				'rule' => ['notEmpty'],
+			'notBlank' => [
+				'rule' => ['notBlank'],
 				'message' => 'valErrMandatoryField',
 			],
 		],

+ 29 - 4
Model/MyModel.php

@@ -2,6 +2,7 @@
 App::uses('ShimModel', 'Shim.Model');
 App::uses('Utility', 'Tools.Utility');
 App::uses('Hash', 'Utility');
+App::uses('Validation', 'Utility');
 
 /**
  * Model enhancements for Cake2
@@ -1033,9 +1034,7 @@ class MyModel extends ShimModel {
 			// crashed with white screen of death otherwise... (if foreign page is 404)
 			$this->UndisposableEmail->useOnlineList(false);
 		}
-		if (!class_exists('Validation')) {
-			App::uses('Validation', 'Utility');
-		}
+
 		if (!Validation::email($email)) {
 			return false;
 		}
@@ -1204,7 +1203,7 @@ class MyModel extends ShimModel {
 			}
 
 			if (empty($this->validate[$column])) {
-				$this->validate[$column]['notEmpty'] = ['rule' => 'notEmpty', 'required' => true, 'allowEmpty' => $setAllowEmpty, 'message' => 'valErrMandatoryField'];
+				$this->validate[$column]['notBlank'] = ['rule' => 'notBlank', 'required' => true, 'allowEmpty' => $setAllowEmpty, 'message' => 'valErrMandatoryField'];
 			} else {
 				$keys = array_keys($this->validate[$column]);
 				if (!in_array('rule', $keys)) {
@@ -1336,6 +1335,32 @@ class MyModel extends ShimModel {
 	}
 
 	/**
+	 * Shim wrapper for 2.6 to allow 2.7 notBlank validation rule to work already.
+	 * This is only there to avoid the deprecation errors in 2.6 test runs.
+	 *
+	 * @param array $data
+	 * @return bool
+	 */
+	public function notBlank($data) {
+		$value = array_shift($data);
+		if ((float)Configure::version() < 2.7) {
+			return Validation::notEmpty($value);
+		}
+		return Validation::notBlank($value);
+	}
+
+	/**
+	 * Shim wrapper for 2.6 to allow 2.7 notBlank validation rule to work already.
+	 * This is only there to avoid the deprecation errors in 2.6 test runs.
+	 *
+	 * @param array $data
+	 * @return bool
+	 */
+	public function notEmpty($data) {
+		return $this->notBlank($data);
+	}
+
+	/**
 	 * Recursive Dropdown Lists
 	 * NEEDS tree behavior, NEEDS lft, rght, parent_id (!)
 	 * //FIXME

+ 4 - 4
Model/Qlogin.php

@@ -20,8 +20,8 @@ class Qlogin extends ToolsAppModel {
 
 	public $validate = [
 		'url' => [
-			'notEmpty' => [
-				'rule' => ['notEmpty'],
+			'notBlank' => [
+				'rule' => ['notBlank'],
 				'message' => 'valErrMandatoryField',
 				'last' => true
 			],
@@ -32,8 +32,8 @@ class Qlogin extends ToolsAppModel {
 			]
 		],
 		'user_id' => [
-			'notEmpty' => [
-				'rule' => ['notEmpty'],
+			'notBlank' => [
+				'rule' => ['notBlank'],
 				'message' => 'valErrMandatoryField',
 				'last' => true
 			],

+ 4 - 4
Model/Qurl.php

@@ -23,8 +23,8 @@ class Qurl extends ToolsAppModel {
 
 	public $validate = [
 		'key' => [
-			'notEmpty' => [
-				'rule' => ['notEmpty'],
+			'notBlank' => [
+				'rule' => ['notBlank'],
 				'message' => 'valErrMandatoryField',
 				'last' => true,
 			],
@@ -34,8 +34,8 @@ class Qurl extends ToolsAppModel {
 			],
 		],
 		'url' => [
-			'notEmpty' => [
-				'rule' => ['notEmpty'],
+			'notBlank' => [
+				'rule' => ['notBlank'],
 				'message' => 'valErrMandatoryField',
 				'last' => true
 			],

+ 4 - 4
Model/Token.php

@@ -21,14 +21,14 @@ class Token extends ToolsAppModel {
 
 	public $validate = [
 		'type' => [
-			'notEmpty' => [
-				'rule' => ['notEmpty'],
+			'notBlank' => [
+				'rule' => ['notBlank'],
 				'message' => 'valErrMandatoryField',
 			],
 		],
 		'key' => [
-			'notEmpty' => [
-				'rule' => ['notEmpty'],
+			'notBlank' => [
+				'rule' => ['notBlank'],
 				'message' => 'valErrMandatoryField',
 				'last' => true,
 			],

+ 5 - 30
Test/Case/Model/Behavior/BitmaskedBehaviorTest.php

@@ -16,7 +16,11 @@ class BitmaskedBehaviorTest extends MyCakeTestCase {
 	public function setUp() {
 		parent::setUp();
 
-		$this->Comment = new BitmaskedComment();
+		App::build([
+			'Model' => [CakePlugin::path('Tools') . 'Test' . DS . 'test_app' . DS . 'Model' . DS],
+		], App::RESET);
+
+		$this->Comment = ClassRegistry::init('BitmaskedComment');
 		$this->Comment->Behaviors->load('Tools.Bitmasked', ['mappedField' => 'statuses']);
 	}
 
@@ -174,32 +178,3 @@ class BitmaskedBehaviorTest extends MyCakeTestCase {
 	}
 
 }
-
-class BitmaskedComment extends CakeTestModel {
-
-	public $validate = [
-		'status' => [
-			'notEmpty' => [
-				'rule' => 'notEmpty',
-				'last' => true
-			]
-		]
-	];
-
-	public static function statuses($value = null) {
-		$options = [
-			static::STATUS_ACTIVE => __d('tools', 'Active'),
-			static::STATUS_PUBLISHED => __d('tools', 'Published'),
-			static::STATUS_APPROVED => __d('tools', 'Approved'),
-			static::STATUS_FLAGGED => __d('tools', 'Flagged'),
-		];
-
-		return MyModel::enum($value, $options);
-	}
-
-	const STATUS_NONE = 0;
-	const STATUS_ACTIVE = 1;
-	const STATUS_PUBLISHED = 2;
-	const STATUS_APPROVED = 4;
-	const STATUS_FLAGGED = 8;
-}

+ 1 - 1
Test/Case/Model/Behavior/KeyValueBehaviorTest.php

@@ -29,7 +29,7 @@ class KeyValueBehaviorTest extends MyCakeTestCase {
 		$this->assertTrue(!empty($res));
 
 		$this->Model->keyValueValidate = [
-			'User' => ['y' => 'notEmpty'],
+			'User' => ['y' => 'notBlank'],
 		];
 		$res = $this->Model->validateSection(['User' => ['x' => 1, 'y' => '']]);
 		$this->assertFalse($res);

+ 4 - 4
Test/Case/View/Helper/FormExtHelperTest.php

@@ -241,15 +241,15 @@ class ContactExt extends CakeTestModel {
 		'non_existing' => [],
 		'idontexist' => [],
 		'imrequired' => ['rule' => ['between', 5, 30], 'allowEmpty' => false],
-		'imrequiredonupdate' => ['notEmpty' => ['rule' => 'alphaNumeric', 'on' => 'update']],
+		'imrequiredonupdate' => ['notBlank' => ['rule' => 'alphaNumeric', 'on' => 'update']],
 		'imrequiredoncreate' => ['required' => ['rule' => 'alphaNumeric', 'on' => 'create']],
 		'imrequiredonboth' => [
 			'required' => ['rule' => 'alphaNumeric'],
 		],
-		'string_required' => 'notEmpty',
+		'string_required' => 'notBlank',
 		'imalsorequired' => ['rule' => 'alphaNumeric', 'allowEmpty' => false],
-		'imrequiredtoo' => ['rule' => 'notEmpty'],
-		'required_one' => ['required' => ['rule' => ['notEmpty']]],
+		'imrequiredtoo' => ['rule' => 'notBlank'],
+		'required_one' => ['required' => ['rule' => ['notBlank']]],
 		'imnotrequired' => ['required' => false, 'rule' => 'alphaNumeric', 'allowEmpty' => true],
 		'imalsonotrequired' => [
 			'alpha' => ['rule' => 'alphaNumeric', 'allowEmpty' => true],

+ 32 - 0
Test/test_app/Model/BitmaskedComment.php

@@ -0,0 +1,32 @@
+<?php
+App::uses('MyModel', 'Tools.Model');
+
+class BitmaskedComment extends MyModel {
+
+	public $validate = [
+		'status' => [
+			'notBlank' => [
+				'rule' => 'notBlank',
+				'last' => true
+			]
+		]
+	];
+
+	public static function statuses($value = null) {
+		$options = [
+			static::STATUS_ACTIVE => __d('tools', 'Active'),
+			static::STATUS_PUBLISHED => __d('tools', 'Published'),
+			static::STATUS_APPROVED => __d('tools', 'Approved'),
+			static::STATUS_FLAGGED => __d('tools', 'Flagged'),
+		];
+
+		return static::enum($value, $options);
+	}
+
+	const STATUS_NONE = 0;
+	const STATUS_ACTIVE = 1;
+	const STATUS_PUBLISHED = 2;
+	const STATUS_APPROVED = 4;
+	const STATUS_FLAGGED = 8;
+
+}