diff --git a/lib/Cake/Console/Command/Task/ModelTask.php b/lib/Cake/Console/Command/Task/ModelTask.php index 1ae4fcca9..27e1a0960 100644 --- a/lib/Cake/Console/Command/Task/ModelTask.php +++ b/lib/Cake/Console/Command/Task/ModelTask.php @@ -380,7 +380,7 @@ class ModelTask extends BakeTask { $default = 1; foreach ($options as $option) { if ($option{0} !== '_') { - $choices[$default] = strtolower($option); + $choices[$default] = $option; $default++; } } @@ -433,9 +433,9 @@ class ModelTask extends BakeTask { } elseif ($metaData['type'] === 'string' && $metaData['length'] == 36) { $guess = $methods['uuid']; } elseif ($metaData['type'] === 'string') { - $guess = $methods['notempty']; + $guess = $methods['notEmpty']; } elseif ($metaData['type'] === 'text') { - $guess = $methods['notempty']; + $guess = $methods['notEmpty']; } elseif ($metaData['type'] === 'integer') { $guess = $methods['numeric']; } elseif ($metaData['type'] === 'boolean') { diff --git a/lib/Cake/Model/Behavior/TreeBehavior.php b/lib/Cake/Model/Behavior/TreeBehavior.php index 9eb44d60a..e87abedc3 100644 --- a/lib/Cake/Model/Behavior/TreeBehavior.php +++ b/lib/Cake/Model/Behavior/TreeBehavior.php @@ -676,7 +676,7 @@ class TreeBehavior extends ModelBehavior { $scope = $this->settings[$Model->alias]['scope']; if ($scope && ($scope !== '1 = 1' && $scope !== true)) { - $conditions[] = $scope; + $params['conditions'][] = $scope; } $children = $Model->find('all', $params); diff --git a/lib/Cake/Network/Http/HttpSocket.php b/lib/Cake/Network/Http/HttpSocket.php index 07552a57f..d829ad80f 100644 --- a/lib/Cake/Network/Http/HttpSocket.php +++ b/lib/Cake/Network/Http/HttpSocket.php @@ -474,7 +474,7 @@ class HttpSocket extends CakeSocket { * }}} * * @param string|array $uri URI to request. See HttpSocket::_parseUri() - * @param array $data Array of POST data keys and values. + * @param array $data Array of request body data keys and values. * @param array $request An indexed array with indexes such as 'method' or uri * @return mixed Result of request, either false on failure or the response to the request. */ @@ -487,7 +487,7 @@ class HttpSocket extends CakeSocket { * Issues a PUT request to the specified URI, query, and request. * * @param string|array $uri URI to request, See HttpSocket::_parseUri() - * @param array $data Array of PUT data keys and values. + * @param array $data Array of request body data keys and values. * @param array $request An indexed array with indexes such as 'method' or uri * @return mixed Result of request */ @@ -500,7 +500,7 @@ class HttpSocket extends CakeSocket { * Issues a PATCH request to the specified URI, query, and request. * * @param string|array $uri URI to request, See HttpSocket::_parseUri() - * @param array $data Array of PATCH data keys and values. + * @param array $data Array of request body data keys and values. * @param array $request An indexed array with indexes such as 'method' or uri * @return mixed Result of request */ @@ -513,7 +513,7 @@ class HttpSocket extends CakeSocket { * Issues a DELETE request to the specified URI, query, and request. * * @param string|array $uri URI to request (see {@link _parseUri()}) - * @param array $data Query to append to URI + * @param array $data Array of request body data keys and values. * @param array $request An indexed array with indexes such as 'method' or uri * @return mixed Result of request */ diff --git a/lib/Cake/Test/Case/Cache/CacheTest.php b/lib/Cake/Test/Case/Cache/CacheTest.php index 13116c2f7..9b4279551 100644 --- a/lib/Cake/Test/Case/Cache/CacheTest.php +++ b/lib/Cake/Test/Case/Cache/CacheTest.php @@ -372,13 +372,13 @@ class CacheTest extends CakeTestCase { */ public function testWriteEmptyValues() { Cache::write('App.falseTest', false); - $this->assertSame(Cache::read('App.falseTest'), false); + $this->assertFalse(Cache::read('App.falseTest')); Cache::write('App.trueTest', true); - $this->assertSame(Cache::read('App.trueTest'), true); + $this->assertTrue(Cache::read('App.trueTest')); Cache::write('App.nullTest', null); - $this->assertSame(Cache::read('App.nullTest'), null); + $this->assertNull(Cache::read('App.nullTest')); Cache::write('App.zeroTest', 0); $this->assertSame(Cache::read('App.zeroTest'), 0); diff --git a/lib/Cake/Test/Case/Console/Command/Task/ModelTaskTest.php b/lib/Cake/Test/Case/Console/Command/Task/ModelTaskTest.php index 533afac36..0aa640124 100644 --- a/lib/Cake/Test/Case/Console/Command/Task/ModelTaskTest.php +++ b/lib/Cake/Test/Case/Console/Command/Task/ModelTaskTest.php @@ -269,7 +269,7 @@ class ModelTaskTest extends CakeTestCase { */ public function testInitValidations() { $result = $this->Task->initValidations(); - $this->assertTrue(in_array('notempty', $result)); + $this->assertTrue(in_array('notEmpty', $result)); } /** @@ -283,7 +283,7 @@ class ModelTaskTest extends CakeTestCase { $this->Task->initValidations(); $result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false)); - $expected = array('notempty' => 'notempty'); + $expected = array('notEmpty' => 'notEmpty'); $this->assertEquals($expected, $result); $result = $this->Task->fieldValidation('text', array('type' => 'date', 'length' => 10, 'null' => false)); @@ -319,7 +319,7 @@ class ModelTaskTest extends CakeTestCase { ->will($this->onConsecutiveCalls('24', 'y', '18', 'n')); $result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false)); - $expected = array('notempty' => 'notempty', 'maxlength' => 'maxlength'); + $expected = array('notEmpty' => 'notEmpty', 'maxLength' => 'maxLength'); $this->assertEquals($expected, $result); } @@ -340,7 +340,7 @@ class ModelTaskTest extends CakeTestCase { ->with($this->stringContains('make a valid')); $result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false)); - $expected = array('notempty' => 'notempty'); + $expected = array('notEmpty' => 'notEmpty'); $this->assertEquals($expected, $result); } @@ -406,7 +406,7 @@ class ModelTaskTest extends CakeTestCase { $result = $this->Task->doValidation($Model); $expected = array( 'name' => array( - 'notempty' => 'notempty' + 'notEmpty' => 'notEmpty' ), 'email' => array( 'email' => 'email', @@ -742,7 +742,7 @@ class ModelTaskTest extends CakeTestCase { public function testBakeValidation() { $validate = array( 'name' => array( - 'notempty' => 'notempty' + 'notempty' => 'notEmpty' ), 'email' => array( 'email' => 'email', @@ -760,7 +760,7 @@ class ModelTaskTest extends CakeTestCase { $expected = <<< STRINGEND array( 'notempty' => array( - 'rule' => array('notempty'), + 'rule' => array('notEmpty'), //'message' => 'Your custom message here', //'allowEmpty' => false, //'required' => false, diff --git a/lib/Cake/Test/Case/Controller/Component/PaginatorComponentTest.php b/lib/Cake/Test/Case/Controller/Component/PaginatorComponentTest.php index 883faff6c..fa866ade5 100644 --- a/lib/Cake/Test/Case/Controller/Component/PaginatorComponentTest.php +++ b/lib/Cake/Test/Case/Controller/Component/PaginatorComponentTest.php @@ -377,16 +377,16 @@ class PaginatorComponentTest extends CakeTestCase { $Controller->Paginator->paginate('PaginatorControllerPost'); $this->assertSame(1, $Controller->params['paging']['PaginatorControllerPost']['page']); $this->assertSame($Controller->params['paging']['PaginatorControllerPost']['pageCount'], 3); - $this->assertSame($Controller->params['paging']['PaginatorControllerPost']['prevPage'], false); - $this->assertSame($Controller->params['paging']['PaginatorControllerPost']['nextPage'], true); + $this->assertFalse($Controller->params['paging']['PaginatorControllerPost']['prevPage']); + $this->assertTrue($Controller->params['paging']['PaginatorControllerPost']['nextPage']); $Controller->request->params['named'] = array(); $Controller->Paginator->settings = array('limit' => 'garbage!', 'maxLimit' => 10, 'paramType' => 'named'); $Controller->Paginator->paginate('PaginatorControllerPost'); $this->assertSame(1, $Controller->params['paging']['PaginatorControllerPost']['page']); $this->assertSame($Controller->params['paging']['PaginatorControllerPost']['pageCount'], 3); - $this->assertSame($Controller->params['paging']['PaginatorControllerPost']['prevPage'], false); - $this->assertSame($Controller->params['paging']['PaginatorControllerPost']['nextPage'], true); + $this->assertFalse($Controller->params['paging']['PaginatorControllerPost']['prevPage']); + $this->assertTrue($Controller->params['paging']['PaginatorControllerPost']['nextPage']); $Controller->request->params['named'] = array(); $Controller->Paginator->settings = array('limit' => '-1', 'maxLimit' => 10, 'paramType' => 'named'); @@ -395,8 +395,8 @@ class PaginatorComponentTest extends CakeTestCase { $this->assertSame($Controller->params['paging']['PaginatorControllerPost']['limit'], 1); $this->assertSame(1, $Controller->params['paging']['PaginatorControllerPost']['page']); $this->assertSame($Controller->params['paging']['PaginatorControllerPost']['pageCount'], 3); - $this->assertSame($Controller->params['paging']['PaginatorControllerPost']['prevPage'], false); - $this->assertSame($Controller->params['paging']['PaginatorControllerPost']['nextPage'], true); + $this->assertFalse($Controller->params['paging']['PaginatorControllerPost']['prevPage']); + $this->assertTrue($Controller->params['paging']['PaginatorControllerPost']['nextPage']); $Controller->Paginator->settings = array('conditions' => array('PaginatorAuthor.user' => 'mariano')); $Controller->Paginator->paginate('PaginatorControllerPost'); diff --git a/lib/Cake/Test/Case/Controller/ControllerTest.php b/lib/Cake/Test/Case/Controller/ControllerTest.php index d37f8b359..18fccf49e 100644 --- a/lib/Cake/Test/Case/Controller/ControllerTest.php +++ b/lib/Cake/Test/Case/Controller/ControllerTest.php @@ -1321,8 +1321,8 @@ class ControllerTest extends CakeTestCase { $Controller->paginate('ControllerPost'); $this->assertSame($Controller->params['paging']['ControllerPost']['page'], 1); $this->assertSame($Controller->params['paging']['ControllerPost']['pageCount'], 3); - $this->assertSame($Controller->params['paging']['ControllerPost']['prevPage'], false); - $this->assertSame($Controller->params['paging']['ControllerPost']['nextPage'], true); + $this->assertFalse($Controller->params['paging']['ControllerPost']['prevPage']); + $this->assertTrue($Controller->params['paging']['ControllerPost']['nextPage']); } /** diff --git a/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorNumberTest.php b/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorNumberTest.php index 2e1bc3c83..f8676835a 100644 --- a/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorNumberTest.php +++ b/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorNumberTest.php @@ -72,7 +72,7 @@ class TreeBehaviorNumberTest extends CakeTestCase { $this->assertEquals(7, $result); $validTree = $this->Tree->verify(); - $this->assertSame($validTree, true); + $this->assertTrue($validTree); } /** @@ -91,15 +91,16 @@ class TreeBehaviorNumberTest extends CakeTestCase { $save[$modelClass]['id'] = $result[$modelClass]['id']; $save[$modelClass][$leftField] = 0; + $this->Tree->create(); $this->Tree->save($save); $result = $this->Tree->verify(); $this->assertNotSame($result, true); $result = $this->Tree->recover(); - $this->assertSame($result, true); + $this->assertTrue($result); $result = $this->Tree->verify(); - $this->assertSame($result, true); + $this->assertTrue($result); } /** @@ -118,15 +119,16 @@ class TreeBehaviorNumberTest extends CakeTestCase { $save[$modelClass]['id'] = $result[$modelClass]['id']; $save[$modelClass][$rightField] = 0; + $this->Tree->create(); $this->Tree->save($save); $result = $this->Tree->verify(); $this->assertNotSame($result, true); $result = $this->Tree->recover(); - $this->assertSame($result, true); + $this->assertTrue($result); $result = $this->Tree->verify(); - $this->assertSame($result, true); + $this->assertTrue($result); } /** @@ -149,10 +151,10 @@ class TreeBehaviorNumberTest extends CakeTestCase { $this->assertNotSame($result, true); $result = $this->Tree->recover(); - $this->assertSame($result, true); + $this->assertTrue($result); $result = $this->Tree->verify(); - $this->assertSame($result, true); + $this->assertTrue($result); } /** @@ -173,10 +175,10 @@ class TreeBehaviorNumberTest extends CakeTestCase { $this->assertNotSame($result, true); $result = $this->Tree->recover('MPTT'); - $this->assertSame($result, true); + $this->assertTrue($result); $result = $this->Tree->verify(); - $this->assertSame($result, true); + $this->assertTrue($result); } /** @@ -190,17 +192,21 @@ class TreeBehaviorNumberTest extends CakeTestCase { $this->Tree->order = null; $this->Tree->Behaviors->disable('Tree'); + $this->Tree->create(); $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)); @@ -242,19 +248,24 @@ class TreeBehaviorNumberTest extends CakeTestCase { $this->Tree->order = null; $this->Tree->Behaviors->disable('Tree'); + $this->Tree->create(); $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)); @@ -318,10 +329,10 @@ class TreeBehaviorNumberTest extends CakeTestCase { $this->assertNotSame($result, true); $result = $this->Tree->recover(); - $this->assertSame($result, true); + $this->assertTrue($result); $result = $this->Tree->verify(); - $this->assertSame($result, true); + $this->assertTrue($result); } /** @@ -341,10 +352,10 @@ class TreeBehaviorNumberTest extends CakeTestCase { $this->assertNotSame($result, true); $result = $this->Tree->recover(); - $this->assertSame($result, true); + $this->assertTrue($result); $result = $this->Tree->verify(); - $this->assertSame($result, true); + $this->assertTrue($result); } /** @@ -366,7 +377,7 @@ class TreeBehaviorNumberTest extends CakeTestCase { $this->Tree->recover(); $result = $this->Tree->verify(); - $this->assertSame($result, true); + $this->assertTrue($result); } /** @@ -408,13 +419,14 @@ class TreeBehaviorNumberTest extends CakeTestCase { $this->Tree->order = null; $this->Tree->initialize(2, 2); + $this->Tree->create(); $this->Tree->save(array($modelClass => array('name' => 'testAddOrphan', $parentField => null))); $result = $this->Tree->find('first', array('fields' => array('name', $parentField), 'order' => $modelClass . '.' . $leftField . ' desc')); $expected = array($modelClass => array('name' => 'testAddOrphan', $parentField => null)); $this->assertEquals($expected, $result); $validTree = $this->Tree->verify(); - $this->assertSame($validTree, true); + $this->assertTrue($validTree); } /** @@ -446,7 +458,7 @@ class TreeBehaviorNumberTest extends CakeTestCase { $this->assertSame($children, $expects); $validTree = $this->Tree->verify(); - $this->assertSame($validTree, true); + $this->assertTrue($validTree); } /** @@ -495,14 +507,15 @@ class TreeBehaviorNumberTest extends CakeTestCase { $initialCount = $this->Tree->find('count'); //$this->expectError('Trying to save a node under a none-existant node in TreeBehavior::beforeSave'); + $this->Tree->create(); $saveSuccess = $this->Tree->save(array($modelClass => array('name' => 'testAddInvalid', $parentField => 99999))); - $this->assertSame($saveSuccess, false); + $this->assertFalse($saveSuccess); $laterCount = $this->Tree->find('count'); $this->assertSame($initialCount, $laterCount); $validTree = $this->Tree->verify(); - $this->assertSame($validTree, true); + $this->assertTrue($validTree); } /** @@ -516,13 +529,14 @@ class TreeBehaviorNumberTest extends CakeTestCase { $this->Tree->order = null; $this->Tree->initialize(2, 2); + $this->Tree->create(); $this->Tree->save(array('name' => 'testAddNotIndexed', $parentField => null)); $result = $this->Tree->find('first', array('fields' => array('name', $parentField), 'order' => $modelClass . '.' . $leftField . ' desc')); $expected = array($modelClass => array('name' => 'testAddNotIndexed', $parentField => null)); $this->assertEquals($expected, $result); $validTree = $this->Tree->verify(); - $this->assertSame($validTree, true); + $this->assertTrue($validTree); } /** @@ -549,7 +563,7 @@ class TreeBehaviorNumberTest extends CakeTestCase { array($modelClass => array('id' => 3, 'name' => '1.1.1', $parentField => 1, $leftField => 12, $rightField => 13))); $this->assertEquals($direct, $expects); $validTree = $this->Tree->verify(); - $this->assertSame($validTree, true); + $this->assertTrue($validTree); } /** @@ -592,11 +606,12 @@ class TreeBehaviorNumberTest extends CakeTestCase { $this->Tree->initialize(2, 2); $this->Tree->whitelist = array('name', $parentField); + $this->Tree->create(); $this->Tree->save(array($modelClass => array('name' => 'testAddOrphan', $parentField => null))); $result = $this->Tree->findByName('testAddOrphan', array('name', $parentField, $leftField, $rightField)); $expected = array('name' => 'testAddOrphan', $parentField => null, $leftField => '15', $rightField => 16); $this->assertEquals($expected, $result[$modelClass]); - $this->assertSame($this->Tree->verify(), true); + $this->assertTrue($this->Tree->verify()); } /** @@ -625,7 +640,7 @@ class TreeBehaviorNumberTest extends CakeTestCase { $this->assertEquals($expects, $result); $validTree = $this->Tree->verify(); - $this->assertSame($validTree, true); + $this->assertTrue($validTree); } /** @@ -654,7 +669,7 @@ class TreeBehaviorNumberTest extends CakeTestCase { $this->assertEquals($expects, $result); $validTree = $this->Tree->verify(); - $this->assertSame($validTree, true); + $this->assertTrue($validTree); } /** @@ -687,7 +702,7 @@ class TreeBehaviorNumberTest extends CakeTestCase { $this->assertEquals($before, $after); $validTree = $this->Tree->verify(); - $this->assertSame($validTree, true); + $this->assertTrue($validTree); } /** @@ -712,7 +727,7 @@ class TreeBehaviorNumberTest extends CakeTestCase { $this->assertSame($initialCount, $laterCount); $validTree = $this->Tree->verify(); - $this->assertSame($validTree, true); + $this->assertTrue($validTree); } /** @@ -733,12 +748,12 @@ class TreeBehaviorNumberTest extends CakeTestCase { $this->Tree->id = $data[$modelClass]['id']; $saveSuccess = $this->Tree->saveField($parentField, $this->Tree->id); - $this->assertSame($saveSuccess, false); + $this->assertFalse($saveSuccess); $laterCount = $this->Tree->find('count'); $this->assertSame($initialCount, $laterCount); $validTree = $this->Tree->verify(); - $this->assertSame($validTree, true); + $this->assertTrue($validTree); } /** @@ -1000,7 +1015,7 @@ class TreeBehaviorNumberTest extends CakeTestCase { $this->Tree->save(array($parentField => null)); $result = $this->Tree->verify(); - $this->assertSame($result, true); + $this->assertTrue($result); $this->Tree->moveUp(); @@ -1031,7 +1046,7 @@ class TreeBehaviorNumberTest extends CakeTestCase { $this->assertEquals($initialCount - 1, $laterCount); $validTree = $this->Tree->verify(); - $this->assertSame($validTree, true); + $this->assertTrue($validTree); $initialCount = $this->Tree->find('count'); $result = $this->Tree->findByName('1.1'); @@ -1043,7 +1058,7 @@ class TreeBehaviorNumberTest extends CakeTestCase { $this->assertEquals($initialCount - 2, $laterCount); $validTree = $this->Tree->verify(); - $this->assertSame($validTree, true); + $this->assertTrue($validTree); } /** @@ -1089,7 +1104,7 @@ class TreeBehaviorNumberTest extends CakeTestCase { $this->assertEquals($topNodes, $expects); $validTree = $this->Tree->verify(); - $this->assertSame($validTree, true); + $this->assertTrue($validTree); } /** @@ -1123,7 +1138,7 @@ class TreeBehaviorNumberTest extends CakeTestCase { $this->assertEquals($topNodes, $expects); $validTree = $this->Tree->verify(); - $this->assertSame($validTree, true); + $this->assertTrue($validTree); } /** @@ -1158,7 +1173,7 @@ class TreeBehaviorNumberTest extends CakeTestCase { $this->assertEquals($nodes, $expects); $validTree = $this->Tree->verify(); - $this->assertSame($validTree, true); + $this->assertTrue($validTree); } /** @@ -1193,7 +1208,7 @@ class TreeBehaviorNumberTest extends CakeTestCase { $this->assertEquals($topNodes, $expects); $validTree = $this->Tree->verify(); - $this->assertSame($validTree, true); + $this->assertTrue($validTree); } /** @@ -1226,7 +1241,7 @@ class TreeBehaviorNumberTest extends CakeTestCase { $this->assertEquals($nodes, $expects); $validTree = $this->Tree->verify(); - $this->assertSame($validTree, true); + $this->assertTrue($validTree); } /** diff --git a/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorScopedTest.php b/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorScopedTest.php index d617aa70e..530e6825c 100644 --- a/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorScopedTest.php +++ b/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorScopedTest.php @@ -178,6 +178,7 @@ class TreeBehaviorScopedTest extends CakeTestCase { $this->Tree->Behaviors->attach('Translate', array('title')); //Save + $this->Tree->create(); $this->Tree->locale = 'eng'; $data = array('FlagTree' => array( 'title' => 'name #1', @@ -380,4 +381,189 @@ class TreeBehaviorScopedTest extends CakeTestCase { $this->assertEquals($expected, $result); } +/** + * testRecoverUsingParentMode method + * + * @return void + */ + public function testRecoverUsingParentMode() { + extract($this->settings); + $this->Tree = new $modelClass(); + $this->Tree->order = null; + $this->Tree->initialize(2, 3); + + $this->Tree->Behaviors->attach('Tree', array('scope' => 'FlagTree.flag = 1')); + $this->Tree->Behaviors->disable('Tree'); + + $this->Tree->create(); + $this->Tree->save(array('name' => 'Main', $parentField => null, $leftField => 0, $rightField => 0, 'flag' => 1)); + $node1 = $this->Tree->id; + + $this->Tree->create(); + $this->Tree->save(array('name' => 'About Us', $parentField => $node1, $leftField => 0, $rightField => 0, 'flag' => 1)); + $node11 = $this->Tree->id; + + $this->Tree->create(); + $this->Tree->save(array('name' => 'Programs', $parentField => $node1, $leftField => 0, $rightField => 0, 'flag' => 1)); + $node12 = $this->Tree->id; + + $this->Tree->create(); + $this->Tree->save(array('name' => 'Mission and History', $parentField => $node11, $leftField => 0, $rightField => 0, 'flag' => 1)); + + $this->Tree->create(); + $this->Tree->save(array('name' => 'Overview', $parentField => $node12, $leftField => 0, $rightField => 0, 'flag' => 1)); + + $this->Tree->Behaviors->enable('Tree'); + + $result = $this->Tree->verify(); + $this->assertNotSame($result, true); + + $result = $this->Tree->recover(); + $this->assertTrue($result); + + $result = $this->Tree->verify(); + $this->assertTrue($result); + + $result = $this->Tree->find('first', array( + 'fields' => array('name', $parentField, $leftField, $rightField, 'flag'), + 'conditions' => array('name' => 'Main'), + 'recursive' => -1 + )); + $expected = array( + $modelClass => array( + 'name' => 'Main', + $parentField => null, + $leftField => 1, + $rightField => 10, + 'flag' => 1 + ) + ); + $this->assertEquals($expected, $result); + } + +/** + * testRecoverFromMissingParent method + * + * @return void + */ + public function testRecoverFromMissingParent() { + extract($this->settings); + $this->Tree = new $modelClass(); + $this->Tree->order = null; + $this->Tree->initialize(2, 2); + + $this->Tree->id = 1; + $this->Tree->saveField('flag', 1); + $this->Tree->id = 2; + $this->Tree->saveField('flag', 1); + + $this->Tree->Behaviors->attach('Tree', array('scope' => array('FlagTree.flag' => 1))); + + $result = $this->Tree->findByName('1.1'); + $this->Tree->updateAll(array($parentField => 999999), array('id' => $result[$modelClass]['id'])); + + $result = $this->Tree->verify(); + $this->assertNotSame($result, true); + + $result = $this->Tree->recover(); + $this->assertTrue($result); + + $result = $this->Tree->verify(); + $this->assertTrue($result); + } + +/** + * testDetectInvalidParents method + * + * @return void + */ + public function testDetectInvalidParents() { + extract($this->settings); + $this->Tree = new $modelClass(); + $this->Tree->order = null; + $this->Tree->initialize(2, 2); + + $this->Tree->id = 1; + $this->Tree->saveField('flag', 1); + $this->Tree->id = 2; + $this->Tree->saveField('flag', 1); + + $this->Tree->Behaviors->attach('Tree', array('scope' => array('FlagTree.flag' => 1))); + + $this->Tree->updateAll(array($parentField => null)); + + $result = $this->Tree->verify(); + $this->assertNotSame($result, true); + + $result = $this->Tree->recover(); + $this->assertTrue($result); + + $result = $this->Tree->verify(); + $this->assertTrue($result); + } + +/** + * testDetectInvalidLftsRghts method + * + * @return void + */ + public function testDetectInvalidLftsRghts() { + extract($this->settings); + $this->Tree = new $modelClass(); + $this->Tree->order = null; + $this->Tree->initialize(2, 2); + + $this->Tree->id = 1; + $this->Tree->saveField('flag', 1); + $this->Tree->id = 2; + $this->Tree->saveField('flag', 1); + + $this->Tree->Behaviors->attach('Tree', array('scope' => array('FlagTree.flag' => 1))); + + $this->Tree->updateAll(array($leftField => 0, $rightField => 0)); + + $result = $this->Tree->verify(); + $this->assertNotSame($result, true); + + $this->Tree->recover(); + + $result = $this->Tree->verify(); + $this->assertTrue($result); + } + +/** + * Reproduces a situation where a single node has lft= rght, and all other lft and rght fields follow sequentially + * + * @return void + */ + public function testDetectEqualLftsRghts() { + extract($this->settings); + $this->Tree = new $modelClass(); + $this->Tree->order = null; + $this->Tree->initialize(1, 3); + + $this->Tree->id = 1; + $this->Tree->saveField('flag', 1); + $this->Tree->id = 2; + $this->Tree->saveField('flag', 1); + + $this->Tree->Behaviors->attach('Tree', array('scope' => array('FlagTree.flag' => 1))); + + $result = $this->Tree->findByName('1.1'); + $this->Tree->updateAll(array($rightField => $result[$modelClass][$leftField]), array('id' => $result[$modelClass]['id'])); + $this->Tree->updateAll(array($leftField => $this->Tree->escapeField($leftField) . ' -1'), + array($leftField . ' >' => $result[$modelClass][$leftField])); + $this->Tree->updateAll(array($rightField => $this->Tree->escapeField($rightField) . ' -1'), + array($rightField . ' >' => $result[$modelClass][$leftField])); + + $result = $this->Tree->verify(); + $this->assertNotSame($result, true); + + $result = $this->Tree->recover(); + $this->assertTrue($result); + + $result = $this->Tree->verify(); + $this->assertTrue($result); + } + } diff --git a/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorUuidTest.php b/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorUuidTest.php index 4a7a36763..63d7f6875 100644 --- a/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorUuidTest.php +++ b/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorUuidTest.php @@ -114,7 +114,7 @@ class TreeBehaviorUuidTest extends CakeTestCase { array($modelClass => array('name' => '1.1.1', $leftField => 12, $rightField => 13))); $this->assertEquals($direct, $expects); $validTree = $this->Tree->verify(); - $this->assertSame($validTree, true); + $this->assertTrue($validTree); } /** @@ -177,7 +177,7 @@ class TreeBehaviorUuidTest extends CakeTestCase { $this->assertEquals(array_values($nodes), $expects); $validTree = $this->Tree->verify(); - $this->assertSame($validTree, true); + $this->assertTrue($validTree); } /** @@ -210,7 +210,7 @@ class TreeBehaviorUuidTest extends CakeTestCase { $this->assertEquals(array_values($nodes), $expects); $validTree = $this->Tree->verify(); - $this->assertSame($validTree, true); + $this->assertTrue($validTree); } /** diff --git a/lib/Cake/Test/Case/Model/BehaviorCollectionTest.php b/lib/Cake/Test/Case/Model/BehaviorCollectionTest.php index 5454556a5..a506c28f9 100644 --- a/lib/Cake/Test/Case/Model/BehaviorCollectionTest.php +++ b/lib/Cake/Test/Case/Model/BehaviorCollectionTest.php @@ -629,11 +629,11 @@ class BehaviorCollectionTest extends CakeTestCase { $this->assertSame($Apple->Behaviors->enabled(), array()); $Apple->Sample->Behaviors->attach('Test'); - $this->assertSame($Apple->Sample->Behaviors->enabled('Test'), true); + $this->assertTrue($Apple->Sample->Behaviors->enabled('Test')); $this->assertSame($Apple->Behaviors->enabled(), array()); $Apple->Behaviors->enable('Test'); - $this->assertSame($Apple->Behaviors->loaded('Test'), true); + $this->assertTrue($Apple->Behaviors->loaded('Test')); $this->assertSame($Apple->Behaviors->enabled(), array('Test')); $Apple->Behaviors->disable('Test'); @@ -658,7 +658,7 @@ class BehaviorCollectionTest extends CakeTestCase { $expected = $Apple->find('all'); $Apple->Behaviors->attach('Test'); - $this->assertSame($Apple->find('all'), null); + $this->assertNull($Apple->find('all')); $Apple->Behaviors->attach('Test', array('beforeFind' => 'off')); $this->assertSame($expected, $Apple->find('all')); @@ -929,28 +929,28 @@ class BehaviorCollectionTest extends CakeTestCase { $Apple = new Apple(); $Apple->Behaviors->attach('Test', array('beforeFind' => 'off', 'beforeDelete' => 'off')); - $this->assertSame($Apple->delete(6), true); + $this->assertTrue($Apple->delete(6)); $Apple->Behaviors->attach('Test', array('beforeDelete' => 'on')); - $this->assertSame($Apple->delete(4), false); + $this->assertFalse($Apple->delete(4)); $Apple->Behaviors->attach('Test', array('beforeDelete' => 'test2')); ob_start(); $results = $Apple->delete(4); $this->assertSame(trim(ob_get_clean()), 'beforeDelete success (cascading)'); - $this->assertSame($results, true); + $this->assertTrue($results); ob_start(); $results = $Apple->delete(3, false); $this->assertSame(trim(ob_get_clean()), 'beforeDelete success'); - $this->assertSame($results, true); + $this->assertTrue($results); $Apple->Behaviors->attach('Test', array('beforeDelete' => 'off', 'afterDelete' => 'on')); ob_start(); $results = $Apple->delete(2, false); $this->assertSame(trim(ob_get_clean()), 'afterDelete success'); - $this->assertSame($results, true); + $this->assertTrue($results); } /** @@ -976,14 +976,14 @@ class BehaviorCollectionTest extends CakeTestCase { $Apple = new Apple(); $Apple->Behaviors->attach('Test'); - $this->assertSame($Apple->validates(), true); + $this->assertTrue($Apple->validates()); $Apple->Behaviors->attach('Test', array('validate' => 'on')); - $this->assertSame($Apple->validates(), false); + $this->assertFalse($Apple->validates()); $this->assertSame($Apple->validationErrors, array('name' => array(true))); $Apple->Behaviors->attach('Test', array('validate' => 'stop')); - $this->assertSame($Apple->validates(), false); + $this->assertFalse($Apple->validates()); $this->assertSame($Apple->validationErrors, array('name' => array(true, true))); $Apple->Behaviors->attach('Test', array('validate' => 'whitelist')); @@ -1004,10 +1004,10 @@ class BehaviorCollectionTest extends CakeTestCase { $Apple = new Apple(); $Apple->Behaviors->attach('Test'); - $this->assertSame($Apple->validates(), true); + $this->assertTrue($Apple->validates()); $Apple->Behaviors->attach('Test', array('afterValidate' => 'on')); - $this->assertSame($Apple->validates(), true); + $this->assertTrue($Apple->validates()); $this->assertSame($Apple->validationErrors, array()); $Apple->Behaviors->attach('Test', array('afterValidate' => 'test')); diff --git a/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php b/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php index 8db344ad1..09c7d221c 100644 --- a/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php @@ -213,19 +213,19 @@ class MysqlTest extends CakeTestCase { $this->assertTrue((bool)$this->model->save(array('bool' => 5, 'small_int' => 5))); $result = $this->model->find('first'); - $this->assertSame($result['Tinyint']['bool'], true); + $this->assertTrue($result['Tinyint']['bool']); $this->assertSame($result['Tinyint']['small_int'], '5'); $this->model->deleteAll(true); $this->assertTrue((bool)$this->model->save(array('bool' => 0, 'small_int' => 100))); $result = $this->model->find('first'); - $this->assertSame($result['Tinyint']['bool'], false); + $this->assertFalse($result['Tinyint']['bool']); $this->assertSame($result['Tinyint']['small_int'], '100'); $this->model->deleteAll(true); $this->assertTrue((bool)$this->model->save(array('bool' => true, 'small_int' => 0))); $result = $this->model->find('first'); - $this->assertSame($result['Tinyint']['bool'], true); + $this->assertTrue($result['Tinyint']['bool']); $this->assertSame($result['Tinyint']['small_int'], '0'); $this->model->deleteAll(true); diff --git a/lib/Cake/Test/Case/Model/ModelDeleteTest.php b/lib/Cake/Test/Case/Model/ModelDeleteTest.php index 63853920e..8d30421c7 100644 --- a/lib/Cake/Test/Case/Model/ModelDeleteTest.php +++ b/lib/Cake/Test/Case/Model/ModelDeleteTest.php @@ -661,7 +661,7 @@ class ModelDeleteTest extends BaseModelTest { $this->assertEquals(4, $result); $result = $Article->delete(1, true); - $this->assertSame($result, true); + $this->assertTrue($result); $result = $Article->Comment->find('count', array( 'conditions' => array('Comment.article_id' => 1) diff --git a/lib/Cake/Test/Case/Model/ModelWriteTest.php b/lib/Cake/Test/Case/Model/ModelWriteTest.php index ae8d71cfb..c3e92f86b 100644 --- a/lib/Cake/Test/Case/Model/ModelWriteTest.php +++ b/lib/Cake/Test/Case/Model/ModelWriteTest.php @@ -318,7 +318,7 @@ class ModelWriteTest extends BaseModelTest { $TestModel2 = new Item(); $result = $TestModel->findById(1); - $this->assertSame($result['Syfile']['item_count'], null); + $this->assertNull($result['Syfile']['item_count']); $TestModel2->save(array( 'name' => 'Item 7', @@ -480,7 +480,7 @@ class ModelWriteTest extends BaseModelTest { $TestModel2->belongsTo['Syfile']['counterScope'] = array('published' => true); $result = $TestModel->findById(1); - $this->assertSame($result['Syfile']['item_count'], null); + $this->assertNull($result['Syfile']['item_count']); $TestModel2->save(array( 'name' => 'Item 7', @@ -4629,7 +4629,7 @@ class ModelWriteTest extends BaseModelTest { array('validate' => 'first') ); - $this->assertSame($result, true); + $this->assertTrue($result); $result = $model->Comment->find('all'); $this->assertSame(count($result), 1); @@ -6033,7 +6033,7 @@ class ModelWriteTest extends BaseModelTest { array('validate' => 'first') ); - $this->assertSame($result, true); + $this->assertTrue($result); $result = $model->Comment->find('all'); $this->assertSame(count($result), 1); diff --git a/lib/Cake/Test/Case/Network/CakeRequestTest.php b/lib/Cake/Test/Case/Network/CakeRequestTest.php index 5114ae354..fe45ed922 100644 --- a/lib/Cake/Test/Case/Network/CakeRequestTest.php +++ b/lib/Cake/Test/Case/Network/CakeRequestTest.php @@ -937,7 +937,7 @@ class CakeRequestTest extends CakeTestCase { $this->assertEquals('posts', $request->controller); $this->assertEquals('view', $request->action); $this->assertEquals('blogs', $request->plugin); - $this->assertSame($request->banana, null); + $this->assertNull($request->banana); } /** diff --git a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php index 6e7f0396b..025d96530 100644 --- a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php +++ b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php @@ -211,7 +211,7 @@ class CakeEmailTest extends CakeTestCase { $this->assertSame($this->CakeEmail->sender(), $expected); $headers = $this->CakeEmail->getHeaders(array('from' => true, 'sender' => true)); - $this->assertSame($headers['From'], false); + $this->assertFalse($headers['From']); $this->assertSame($headers['Sender'], 'Name '); $this->CakeEmail->from('cake@cakephp.org', 'CakePHP'); diff --git a/lib/Cake/Test/Case/Network/Http/HttpResponseTest.php b/lib/Cake/Test/Case/Network/Http/HttpResponseTest.php index 1273bf1ff..649ac3c01 100644 --- a/lib/Cake/Test/Case/Network/Http/HttpResponseTest.php +++ b/lib/Cake/Test/Case/Network/Http/HttpResponseTest.php @@ -143,7 +143,7 @@ class HttpResponseTest extends CakeTestCase { $this->assertEquals('Bar', $this->HttpResponse->getHeader('FOO')); $this->assertEquals('value', $this->HttpResponse->getHeader('header')); $this->assertEquals('text/plain', $this->HttpResponse->getHeader('Content-Type')); - $this->assertSame($this->HttpResponse->getHeader(0), null); + $this->assertNull($this->HttpResponse->getHeader(0)); $this->assertEquals('Bar', $this->HttpResponse->getHeader('foo', false)); $this->assertEquals('not from class', $this->HttpResponse->getHeader('foo', array('foo' => 'not from class'))); @@ -578,7 +578,7 @@ class HttpResponseTest extends CakeTestCase { $this->assertEquals($expected, $this->HttpResponse['cookies']); $this->HttpResponse->raw = "HTTP/1.1 200 OK\r\n\r\nThis is a test!"; - $this->assertSame($this->HttpResponse['raw']['header'], null); + $this->assertNull($this->HttpResponse['raw']['header']); } } diff --git a/lib/Cake/Test/Case/Utility/FileTest.php b/lib/Cake/Test/Case/Utility/FileTest.php index 5e72c1b91..85a759e00 100644 --- a/lib/Cake/Test/Case/Utility/FileTest.php +++ b/lib/Cake/Test/Case/Utility/FileTest.php @@ -310,11 +310,11 @@ class FileTest extends CakeTestCase { } else { $expected = "some\nvery\ncool\nteststring here\n\n\nfor\n\n\n\n\nhere"; } - $this->assertSame(File::prepare($string), $expected); + $this->assertSame($expected, File::prepare($string)); $expected = "some\r\nvery\r\ncool\r\nteststring here\r\n\r\n\r\n"; $expected .= "for\r\n\r\n\r\n\r\n\r\nhere"; - $this->assertSame(File::prepare($string, true), $expected); + $this->assertSame($expected, File::prepare($string, true)); } /** diff --git a/lib/Cake/Test/Case/Utility/HashTest.php b/lib/Cake/Test/Case/Utility/HashTest.php index 7f28223e6..c14efc8c5 100644 --- a/lib/Cake/Test/Case/Utility/HashTest.php +++ b/lib/Cake/Test/Case/Utility/HashTest.php @@ -593,6 +593,12 @@ class HashTest extends CakeTestCase { ); $this->assertTrue(Hash::contains($b, $a)); $this->assertFalse(Hash::contains($a, $b)); + + $a = array(0 => 'test', 'string' => null); + $this->assertTrue(Hash::contains($a, array('string' => null))); + + $a = array(0 => 'test', 'string' => null); + $this->assertTrue(Hash::contains($a, array('test'))); } /** diff --git a/lib/Cake/Test/Case/View/Helper/PaginatorHelperTest.php b/lib/Cake/Test/Case/View/Helper/PaginatorHelperTest.php index 294c81367..5e63a3fe5 100644 --- a/lib/Cake/Test/Case/View/Helper/PaginatorHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/PaginatorHelperTest.php @@ -89,9 +89,9 @@ class PaginatorHelperTest extends CakeTestCase { * @return void */ public function testHasPrevious() { - $this->assertSame($this->Paginator->hasPrev(), false); + $this->assertFalse($this->Paginator->hasPrev()); $this->Paginator->request->params['paging']['Article']['prevPage'] = true; - $this->assertSame($this->Paginator->hasPrev(), true); + $this->assertTrue($this->Paginator->hasPrev()); $this->Paginator->request->params['paging']['Article']['prevPage'] = false; } @@ -101,9 +101,9 @@ class PaginatorHelperTest extends CakeTestCase { * @return void */ public function testHasNext() { - $this->assertSame($this->Paginator->hasNext(), true); + $this->assertTrue($this->Paginator->hasNext()); $this->Paginator->request->params['paging']['Article']['nextPage'] = false; - $this->assertSame($this->Paginator->hasNext(), false); + $this->assertFalse($this->Paginator->hasNext()); $this->Paginator->request->params['paging']['Article']['nextPage'] = true; } diff --git a/lib/Cake/Utility/CakeTime.php b/lib/Cake/Utility/CakeTime.php index 610e62368..1c6de7cd0 100644 --- a/lib/Cake/Utility/CakeTime.php +++ b/lib/Cake/Utility/CakeTime.php @@ -1041,7 +1041,7 @@ class CakeTime { /** * Returns a formatted date string, given either a UNIX timestamp or a valid strtotime() date string. - * It take in account the default date format for the current language if a LC_TIME file is used. + * It takes into account the default date format for the current language if a LC_TIME file is used. * * @param integer|string|DateTime $date UNIX timestamp, strtotime() valid string or DateTime object * @param string $format strftime format string. diff --git a/lib/Cake/Utility/Hash.php b/lib/Cake/Utility/Hash.php index baa268ba6..ea47eb777 100644 --- a/lib/Cake/Utility/Hash.php +++ b/lib/Cake/Utility/Hash.php @@ -482,14 +482,14 @@ class Hash { $val = $needle[$key]; unset($needle[$key]); - if (isset($data[$key]) && is_array($val)) { + if (array_key_exists($key, $data) && is_array($val)) { $next = $data[$key]; unset($data[$key]); if (!empty($val)) { $stack[] = array($val, $next); } - } elseif (!isset($data[$key]) || $data[$key] != $val) { + } elseif (!array_key_exists($key, $data) || $data[$key] != $val) { return false; } diff --git a/lib/Cake/View/JsonView.php b/lib/Cake/View/JsonView.php index d72c7de85..2fc34976b 100644 --- a/lib/Cake/View/JsonView.php +++ b/lib/Cake/View/JsonView.php @@ -19,7 +19,7 @@ App::uses('View', 'View'); * * By setting the '_serialize' key in your controller, you can specify a view variable * that should be serialized to JSON and used as the response for the request. - * This allows you to omit views + layouts, if your just need to emit a single view + * This allows you to omit views and layouts if you just need to emit a single view * variable as the JSON response. * * In your controller, you could do the following: @@ -42,7 +42,7 @@ App::uses('View', 'View'); * `{"posts": [...], "users": [...]}` * * If you don't use the `_serialize` key, you will need a view. You can use extended - * views to provide layout like functionality. + * views to provide layout-like functionality. * * You can also enable JSONP support by setting parameter `_jsonp` to true or a string to specify * custom query string paramater name which will contain the callback function name. @@ -53,8 +53,8 @@ App::uses('View', 'View'); class JsonView extends View { /** - * JSON views are always located in the 'json' sub directory for a - * controllers views. + * JSON views are always located in the 'json' sub directory for + * controllers' views. * * @var string */ @@ -89,7 +89,7 @@ class JsonView extends View { * * ### Special parameters * `_serialize` To convert a set of view variables into a JSON response. - * It's value can be a string for single variable name or array for multiple names. + * Its value can be a string for single variable name or array for multiple names. * You can omit the`_serialize` parameter, and use a normal view + layout as well. * `_jsonp` Enables JSONP support and wraps response in callback function provided in query string. * - Setting it to true enables the default query string parameter "callback".