Browse Source

Adding test for generating unique validaiton rule for a username field

Jose Lorenzo Rodriguez 11 years ago
parent
commit
cdb015b12a
1 changed files with 25 additions and 0 deletions
  1. 25 0
      tests/TestCase/Console/Command/Task/ModelTaskTest.php

+ 25 - 0
tests/TestCase/Console/Command/Task/ModelTaskTest.php

@@ -444,6 +444,31 @@ class ModelTaskTest extends TestCase {
 	}
 
 /**
+ * Tests that a username column will get a validateUnique rule applied
+ *
+ * @return void
+ */
+	public function testGetValidationWithUnique() {
+		$model = TableRegistry::get('Users');
+		$result = $this->Task->getValidation($model);
+		$expected = [
+			'password' => ['valid' => ['rule' => false, 'allowEmpty' => true]],
+			'id' => ['valid' => ['rule' => 'numeric', 'allowEmpty' => 'create']],
+			'username' => [
+				'valid' => [
+					'rule' => false,
+					'allowEmpty' => true
+				],
+				'unique' => [
+					'rule' => 'validateUnique',
+					'provider' => 'table'
+				]
+			]
+		];
+		$this->assertEquals($expected, $result);
+	}
+
+/**
  * test non interactive doActsAs
  *
  * @return void