Permalink
Browse files

Merge branch 'master' into 2.3

  • Loading branch information...
2 parents 374631d + 58de670 commit a7f192c60679ac4e58825126c72380f531ca1f3f @markstory markstory committed Nov 15, 2012
@@ -108,7 +108,7 @@ public function afterSave(Model $Model, $created) {
* @return array
*/
public function beforeFind(Model $Model, $query) {
- if ($Model->findQueryType == 'threaded' && !isset($query['parent'])) {
+ if ($Model->findQueryType === 'threaded' && !isset($query['parent'])) {
$query['parent'] = $this->settings[$Model->alias]['parent'];
}
return $query;
@@ -602,7 +602,7 @@ public function recover(Model $Model, $mode = 'parent', $missingParentAction = n
}
extract($this->settings[$Model->alias]);
$Model->recursive = $recursive;
- if ($mode == 'parent') {
+ if ($mode === 'parent') {
$Model->bindModel(array('belongsTo' => array('VerifyParent' => array(
'className' => $Model->name,
'foreignKey' => $parent,
@@ -616,15 +616,15 @@ public function recover(Model $Model, $mode = 'parent', $missingParentAction = n
));
$Model->unbindModel(array('belongsTo' => array('VerifyParent')));
if ($missingParents) {
- if ($missingParentAction == 'return') {
+ if ($missingParentAction === 'return') {
foreach ($missingParents as $id => $display) {
$this->errors[] = 'cannot find the parent for ' . $Model->alias . ' with id ' . $id . '(' . $display . ')';
}
return false;
- } elseif ($missingParentAction == 'delete') {
- $Model->deleteAll(array($Model->primaryKey => array_flip($missingParents)));
+ } elseif ($missingParentAction === 'delete') {
+ $Model->deleteAll(array($Model->escapeField($Model->primaryKey) => array_flip($missingParents)), false);
} else {
- $Model->updateAll(array($parent => $missingParentAction), array($Model->escapeField($Model->primaryKey) => array_flip($missingParents)));
+ $Model->updateAll(array($Model->escapeField($parent) => $missingParentAction), array($Model->escapeField($Model->primaryKey) => array_flip($missingParents)));
}
}
$count = 1;
@@ -985,14 +985,14 @@ protected function _sync(Model $Model, $shift, $dir = '+', $conditions = array()
extract($this->settings[$Model->alias]);
$Model->recursive = $recursive;
- if ($field == 'both') {
+ if ($field === 'both') {
$this->_sync($Model, $shift, $dir, $conditions, $created, $left);
$field = $right;
}
if (is_string($conditions)) {
$conditions = array($Model->escapeField($field) . " {$conditions}");
}
- if (($scope != '1 = 1' && $scope !== true) && $scope) {
+ if (($scope !== '1 = 1' && $scope !== true) && $scope) {
$conditions[] = $scope;
}
if ($created) {
@@ -192,7 +192,7 @@ public function getRules() {
* @return CakeValidationSet this instance
*/
public function setRule($name, $rule) {
- if (!$rule instanceof CakeValidationRule) {
+ if (!($rule instanceof CakeValidationRule)) {
$rule = new CakeValidationRule($rule);
}
$this->_rules[$name] = $rule;
@@ -236,9 +236,10 @@ public function removeRule($name) {
*/
public function setRules($rules = array(), $mergeVars = true) {
if ($mergeVars === false) {
- $this->_rules = $rules;
- } else {
- $this->_rules = array_merge($this->_rules, $rules);
+ $this->_rules = array();
+ }
+ foreach ($rules as $name => $rule) {
+ $this->setRule($name, $rule);
}
return $this;
}
@@ -183,19 +183,19 @@ public function testRecoverUsingParentMode() {
$this->Tree = new $modelClass();
$this->Tree->Behaviors->disable('Tree');
- $this->Tree->save(array('parent_id' => null, 'name' => 'Main', $parentField => null, $leftField => 0, $rightField => 0));
- $node1 = $this->Tree->id;
+ $this->Tree->save(array('name' => 'Main', $parentField => null, $leftField => 0, $rightField => 0));
+ $node1 = $this->Tree->id;
$this->Tree->create();
- $this->Tree->save(array('parent_id' => null, 'name' => 'About Us', $parentField => $node1, $leftField => 0, $rightField => 0));
- $node11 = $this->Tree->id;
+ $this->Tree->save(array('name' => 'About Us', $parentField => $node1, $leftField => 0, $rightField => 0));
+ $node11 = $this->Tree->id;
$this->Tree->create();
- $this->Tree->save(array('parent_id' => null, 'name' => 'Programs', $parentField => $node1, $leftField => 0, $rightField => 0));
- $node12 = $this->Tree->id;
+ $this->Tree->save(array('name' => 'Programs', $parentField => $node1, $leftField => 0, $rightField => 0));
+ $node12 = $this->Tree->id;
$this->Tree->create();
- $this->Tree->save(array('parent_id' => null, 'name' => 'Mission and History', $parentField => $node11, $leftField => 0, $rightField => 0));
+ $this->Tree->save(array('name' => 'Mission and History', $parentField => $node11, $leftField => 0, $rightField => 0));
$this->Tree->create();
- $this->Tree->save(array('parent_id' => null, 'name' => 'Overview', $parentField => $node12, $leftField => 0, $rightField => 0));
+ $this->Tree->save(array('name' => 'Overview', $parentField => $node12, $leftField => 0, $rightField => 0));
$this->Tree->Behaviors->enable('Tree');
@@ -224,6 +224,74 @@ public function testRecoverUsingParentMode() {
$this->assertEquals($expected, $result);
}
+/**
+ * testRecoverUsingParentModeAndDelete method
+ *
+ * @return void
+ */
+ public function testRecoverUsingParentModeAndDelete() {
+ extract($this->settings);
+ $this->Tree = new $modelClass();
+ $this->Tree->Behaviors->disable('Tree');
+
+ $this->Tree->save(array('name' => 'Main', $parentField => null, $leftField => 0, $rightField => 0));
+ $node1 = $this->Tree->id;
+
+ $this->Tree->create();
+ $this->Tree->save(array('name' => 'About Us', $parentField => $node1, $leftField => 0, $rightField => 0));
+ $node11 = $this->Tree->id;
+ $this->Tree->create();
+ $this->Tree->save(array('name' => 'Programs', $parentField => $node1, $leftField => 0, $rightField => 0));
+ $node12 = $this->Tree->id;
+ $this->Tree->create();
+ $this->Tree->save(array('name' => 'Mission and History', $parentField => $node11, $leftField => 0, $rightField => 0));
+ $this->Tree->create();
+ $this->Tree->save(array('name' => 'Overview', $parentField => $node12, $leftField => 0, $rightField => 0));
+ $this->Tree->create();
+ $this->Tree->save(array('name' => 'Lost', $parentField => 9, $leftField => 0, $rightField => 0));
+
+ $this->Tree->Behaviors->enable('Tree');
+
+ $this->Tree->bindModel(array('belongsTo' => array('Parent' => array(
+ 'className' => $this->Tree->name,
+ 'foreignKey' => $parentField
+ ))));
+ $this->Tree->bindModel(array('hasMany' => array('Child' => array(
+ 'className' => $this->Tree->name,
+ 'foreignKey' => $parentField
+ ))));
+
+ $result = $this->Tree->verify();
+ $this->assertNotSame($result, true);
+
+ $count = $this->Tree->find('count');
+ $this->assertEquals(6, $count);
+
+ $result = $this->Tree->recover('parent', 'delete');
+ $this->assertTrue($result);
+
+ $result = $this->Tree->verify();
+ $this->assertTrue($result);
+
+ $count = $this->Tree->find('count');
+ $this->assertEquals(5, $count);
+
+ $result = $this->Tree->find('first', array(
+ 'fields' => array('name', $parentField, $leftField, $rightField),
+ 'conditions' => array('name' => 'Main'),
+ 'recursive' => -1
+ ));
+ $expected = array(
+ $modelClass => array(
+ 'name' => 'Main',
+ $parentField => null,
+ $leftField => 1,
+ $rightField => 10
+ )
+ );
+ $this->assertEquals($expected, $result);
+ }
+
/**
* testRecoverFromMissingParent method
*
@@ -766,21 +766,22 @@ public function testBehaviorHasOneFindCallbacks() {
public function testBehaviorBelongsToFindCallbacks() {
$this->skipIf($this->db instanceof Sqlserver, 'This test is not compatible with SQL Server.');
+ $conditions = array('order' => 'Apple.id ASC');
$Apple = new Apple();
$Apple->unbindModel(array('hasMany' => array('Child'), 'hasOne' => array('Sample')), false);
- $expected = $Apple->find('all');
+ $expected = $Apple->find('all', $conditions);
$Apple->unbindModel(array('belongsTo' => array('Parent')));
- $wellBehaved = $Apple->find('all');
+ $wellBehaved = $Apple->find('all', $conditions);
$Apple->Parent->Behaviors->attach('Test');
$Apple->unbindModel(array('belongsTo' => array('Parent')));
- $this->assertSame($Apple->find('all'), $wellBehaved);
+ $this->assertSame($Apple->find('all', $conditions), $wellBehaved);
$Apple->Parent->Behaviors->attach('Test', array('before' => 'off'));
- $this->assertSame($expected, $Apple->find('all'));
+ $this->assertSame($expected, $Apple->find('all', $conditions));
$Apple->Parent->Behaviors->attach('Test', array('before' => 'test'));
- $this->assertSame($expected, $Apple->find('all'));
+ $this->assertSame($expected, $Apple->find('all', $conditions));
$Apple->Parent->Behaviors->attach('Test', array('before' => 'modify'));
$expected2 = array(
@@ -796,22 +797,23 @@ public function testBehaviorBelongsToFindCallbacks() {
);
$result2 = $Apple->find('all', array(
'fields' => array('Apple.id', 'Parent.id', 'Parent.name', 'Parent.mytime'),
- 'conditions' => array('Apple.id <' => '4')
+ 'conditions' => array('Apple.id <' => '4'),
+ 'order' => 'Apple.id ASC',
));
$this->assertEquals($expected2, $result2);
$Apple->Parent->Behaviors->disable('Test');
- $result = $Apple->find('all');
+ $result = $Apple->find('all', $conditions);
$this->assertEquals($expected, $result);
$Apple->Parent->Behaviors->attach('Test', array('after' => 'off'));
- $this->assertEquals($expected, $Apple->find('all'));
+ $this->assertEquals($expected, $Apple->find('all', $conditions));
$Apple->Parent->Behaviors->attach('Test', array('after' => 'test'));
- $this->assertEquals($expected, $Apple->find('all'));
+ $this->assertEquals($expected, $Apple->find('all', $conditions));
$Apple->Parent->Behaviors->attach('Test', array('after' => 'test2'));
- $this->assertEquals($expected, $Apple->find('all'));
+ $this->assertEquals($expected, $Apple->find('all', $conditions));
}
/**
@@ -156,10 +156,22 @@ public function testSetRules() {
$result = $Field->getRules();
$this->assertEquals(array('validEmail'), array_keys($result));
+ $Field->setRules(array('validEmail' => $rule), false);
+ $result = $Field->getRules();
+ $this->assertEquals(array('validEmail'), array_keys($result));
+ $this->assertTrue(array_pop($result) instanceof CakeValidationRule);
+
$rules = array('notEmpty' => $RuleEmpty);
$Field->setRules($rules, true);
$result = $Field->getRules();
$this->assertEquals(array('validEmail', 'notEmpty'), array_keys($result));
+
+ $rules = array('notEmpty' => array('rule' => 'notEmpty'));
+ $Field->setRules($rules, true);
+ $result = $Field->getRules();
+ $this->assertEquals(array('validEmail', 'notEmpty'), array_keys($result));
+ $this->assertTrue(array_pop($result) instanceof CakeValidationRule);
+ $this->assertTrue(array_pop($result) instanceof CakeValidationRule);
}
/**
@@ -2171,6 +2171,23 @@ public function testInput() {
$this->assertTags($result, $expected);
}
+/**
+ * Test that inputs with 0 can be created.
+ *
+ * @return void
+ */
+ public function testInputZero() {
+ $this->Form->create('User');
+ $result = $this->Form->input('0');
+ $expected = array(
+ 'div' => array('class' => 'input text'),
+ 'label' => array('for' => 'User0'), '/label',
+ 'input' => array('type' => 'text', 'name' => 'data[User][0]', 'id' => 'User0'),
+ '/div'
+ );
+ $this->assertTags($result, $expected);
+ }
+
/**
* test input() with checkbox creation
*
@@ -199,7 +199,7 @@ protected function _introspectModel($model, $key, $field = null) {
$this->fieldset[$object->alias]['fields'][$alias] = array('type' => 'multiple');
}
}
- if (empty($field)) {
+ if ($field === null || $field === false) {
return $this->fieldset[$model]['fields'];
} elseif (isset($this->fieldset[$model]['fields'][$field])) {
return $this->fieldset[$model]['fields'][$field];
@@ -773,7 +773,7 @@ public function error($field, $text = null, $options = array()) {
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::label
*/
public function label($fieldName = null, $text = null, $options = array()) {
- if (empty($fieldName)) {
+ if ($fieldName === null) {
$fieldName = implode('.', $this->entity());
}

0 comments on commit a7f192c

Please sign in to comment.