|
|
@@ -32,6 +32,7 @@ App::uses('ModelTask', 'Console/Command/Task');
|
|
|
* ModelTaskTest class
|
|
|
*
|
|
|
* @package Cake.Test.Case.Console.Command.Task
|
|
|
+ * @property ModelTask $Task
|
|
|
*/
|
|
|
class ModelTaskTest extends CakeTestCase {
|
|
|
|
|
|
@@ -361,46 +362,143 @@ class ModelTaskTest extends CakeTestCase {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * test the validation Generation routine
|
|
|
+ * Test that skipping fields during rule choice works when doing interactive field validation.
|
|
|
*
|
|
|
* @return void
|
|
|
*/
|
|
|
- public function testNonInteractiveDoValidation() {
|
|
|
+ public function testSkippingChoiceInteractiveFieldValidation() {
|
|
|
+ $this->Task->initValidations();
|
|
|
+ $this->Task->interactive = true;
|
|
|
+ $this->Task->expects($this->any())->method('in')
|
|
|
+ ->will($this->onConsecutiveCalls('24', 'y', 's'));
|
|
|
+
|
|
|
+ $result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
|
|
|
+ $expected = array('notEmpty' => 'notEmpty', '_skipFields' => true);
|
|
|
+ $this->assertEquals($expected, $result);
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * Test that skipping fields after rule choice works when doing interactive field validation.
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testSkippingAnotherInteractiveFieldValidation() {
|
|
|
+ $this->Task->initValidations();
|
|
|
+ $this->Task->interactive = true;
|
|
|
+ $this->Task->expects($this->any())->method('in')
|
|
|
+ ->will($this->onConsecutiveCalls('24', 's'));
|
|
|
+
|
|
|
+ $result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
|
|
|
+ $expected = array('notEmpty' => 'notEmpty', '_skipFields' => true);
|
|
|
+ $this->assertEquals($expected, $result);
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * Test the validation generation routine with skipping the rest of the fields
|
|
|
+ * when doing interactive field validation.
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testInteractiveDoValidationWithSkipping() {
|
|
|
+ $this->Task->expects($this->any())
|
|
|
+ ->method('in')
|
|
|
+ ->will($this->onConsecutiveCalls('35', '24', 'n', '11', 's'));
|
|
|
+ $this->Task->interactive = true;
|
|
|
$Model = $this->getMock('Model');
|
|
|
$Model->primaryKey = 'id';
|
|
|
- $Model->expects($this->any())->method('schema')->will($this->returnValue(array(
|
|
|
- 'id' => array(
|
|
|
- 'type' => 'integer',
|
|
|
- 'length' => 11,
|
|
|
- 'null' => false,
|
|
|
- 'key' => 'primary',
|
|
|
- ),
|
|
|
+ $Model->expects($this->any())
|
|
|
+ ->method('schema')
|
|
|
+ ->will($this->returnValue(array(
|
|
|
+ 'id' => array(
|
|
|
+ 'type' => 'integer',
|
|
|
+ 'length' => 11,
|
|
|
+ 'null' => false,
|
|
|
+ 'key' => 'primary',
|
|
|
+ ),
|
|
|
+ 'name' => array(
|
|
|
+ 'type' => 'string',
|
|
|
+ 'length' => 20,
|
|
|
+ 'null' => false,
|
|
|
+ ),
|
|
|
+ 'email' => array(
|
|
|
+ 'type' => 'string',
|
|
|
+ 'length' => 255,
|
|
|
+ 'null' => false,
|
|
|
+ ),
|
|
|
+ 'some_date' => array(
|
|
|
+ 'type' => 'date',
|
|
|
+ 'length' => '',
|
|
|
+ 'null' => false,
|
|
|
+ ),
|
|
|
+ 'some_time' => array(
|
|
|
+ 'type' => 'time',
|
|
|
+ 'length' => '',
|
|
|
+ 'null' => false,
|
|
|
+ ),
|
|
|
+ 'created' => array(
|
|
|
+ 'type' => 'datetime',
|
|
|
+ 'length' => '',
|
|
|
+ 'null' => false,
|
|
|
+ )
|
|
|
+ )
|
|
|
+ ));
|
|
|
+
|
|
|
+ $result = $this->Task->doValidation($Model);
|
|
|
+ $expected = array(
|
|
|
'name' => array(
|
|
|
- 'type' => 'string',
|
|
|
- 'length' => 20,
|
|
|
- 'null' => false,
|
|
|
+ 'notEmpty' => 'notEmpty'
|
|
|
),
|
|
|
'email' => array(
|
|
|
- 'type' => 'string',
|
|
|
- 'length' => 255,
|
|
|
- 'null' => false,
|
|
|
- ),
|
|
|
- 'some_date' => array(
|
|
|
- 'type' => 'date',
|
|
|
- 'length' => '',
|
|
|
- 'null' => false,
|
|
|
- ),
|
|
|
- 'some_time' => array(
|
|
|
- 'type' => 'time',
|
|
|
- 'length' => '',
|
|
|
- 'null' => false,
|
|
|
+ 'email' => 'email',
|
|
|
),
|
|
|
- 'created' => array(
|
|
|
- 'type' => 'datetime',
|
|
|
- 'length' => '',
|
|
|
- 'null' => false,
|
|
|
+ );
|
|
|
+ $this->assertEquals($expected, $result);
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * test the validation Generation routine
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testNonInteractiveDoValidation() {
|
|
|
+ $Model = $this->getMock('Model');
|
|
|
+ $Model->primaryKey = 'id';
|
|
|
+ $Model->expects($this->any())
|
|
|
+ ->method('schema')
|
|
|
+ ->will($this->returnValue(array(
|
|
|
+ 'id' => array(
|
|
|
+ 'type' => 'integer',
|
|
|
+ 'length' => 11,
|
|
|
+ 'null' => false,
|
|
|
+ 'key' => 'primary',
|
|
|
+ ),
|
|
|
+ 'name' => array(
|
|
|
+ 'type' => 'string',
|
|
|
+ 'length' => 20,
|
|
|
+ 'null' => false,
|
|
|
+ ),
|
|
|
+ 'email' => array(
|
|
|
+ 'type' => 'string',
|
|
|
+ 'length' => 255,
|
|
|
+ 'null' => false,
|
|
|
+ ),
|
|
|
+ 'some_date' => array(
|
|
|
+ 'type' => 'date',
|
|
|
+ 'length' => '',
|
|
|
+ 'null' => false,
|
|
|
+ ),
|
|
|
+ 'some_time' => array(
|
|
|
+ 'type' => 'time',
|
|
|
+ 'length' => '',
|
|
|
+ 'null' => false,
|
|
|
+ ),
|
|
|
+ 'created' => array(
|
|
|
+ 'type' => 'datetime',
|
|
|
+ 'length' => '',
|
|
|
+ 'null' => false,
|
|
|
+ )
|
|
|
)
|
|
|
- )));
|
|
|
+ ));
|
|
|
$this->Task->interactive = false;
|
|
|
|
|
|
$result = $this->Task->doValidation($Model);
|