diff --git a/lib/Cake/Model/Permission.php b/lib/Cake/Model/Permission.php index 56122d325..8e66da4d6 100644 --- a/lib/Cake/Model/Permission.php +++ b/lib/Cake/Model/Permission.php @@ -105,7 +105,7 @@ class Permission extends AppModel { } $inherited = array(); - $acoIDs = Set::extract($acoPath, '{n}.' . $this->Aco->alias . '.id'); + $acoIDs = Hash::extract($acoPath, '{n}.' . $this->Aco->alias . '.id'); $count = count($aroPath); for ($i = 0 ; $i < $count; $i++) { @@ -123,7 +123,7 @@ class Permission extends AppModel { if (empty($perms)) { continue; } else { - $perms = Set::extract($perms, '{n}.' . $this->alias); + $perms = Hash::extract($perms, '{n}.' . $this->alias); foreach ($perms as $perm) { if ($action == '*') { @@ -225,11 +225,11 @@ class Permission extends AppModel { } return array( - 'aro' => Set::extract($obj, 'Aro.0.' . $this->Aro->alias . '.id'), - 'aco' => Set::extract($obj, 'Aco.0.' . $this->Aco->alias . '.id'), + 'aro' => current(Hash::extract($obj, 'Aro.0.' . $this->Aro->alias . '.id')), + 'aco' => current(Hash::extract($obj, 'Aco.0.' . $this->Aco->alias . '.id')), 'link' => $this->find('all', array('conditions' => array( - $this->alias . '.aro_id' => Set::extract($obj, 'Aro.0.' . $this->Aro->alias . '.id'), - $this->alias . '.aco_id' => Set::extract($obj, 'Aco.0.' . $this->Aco->alias . '.id') + $this->alias . '.aro_id' => current(Hash::extract($obj, 'Aro.0.' . $this->Aro->alias . '.id')), + $this->alias . '.aco_id' => current(Hash::extract($obj, 'Aco.0.' . $this->Aco->alias . '.id')) ))) ); } diff --git a/lib/Cake/Test/Case/Controller/Component/PaginatorComponentTest.php b/lib/Cake/Test/Case/Controller/Component/PaginatorComponentTest.php index 11da7bb9f..dfb64d541 100644 --- a/lib/Cake/Test/Case/Controller/Component/PaginatorComponentTest.php +++ b/lib/Cake/Test/Case/Controller/Component/PaginatorComponentTest.php @@ -619,7 +619,7 @@ class PaginatorComponentTest extends CakeTestCase { $Controller->request->params['named'] = array('sort' => 'offset_test', 'direction' => 'asc'); $result = $Controller->Paginator->paginate('PaginatorControllerPost'); - $this->assertEquals(array(2, 3, 4), Set::extract($result, '{n}.PaginatorControllerPost.offset_test')); + $this->assertEquals(array(2, 3, 4), Hash::extract($result, '{n}.PaginatorControllerPost.offset_test')); } /** @@ -986,7 +986,7 @@ class PaginatorComponentTest extends CakeTestCase { $this->assertTrue(!empty($result)); $result = $Controller->paginate(); - $this->assertEquals(Set::extract($result, '{n}.PaginatorCustomPost.id'), array(1, 2, 3, 4)); + $this->assertEquals(array(1, 2, 3, 4), Hash::extract($result, '{n}.PaginatorCustomPost.id')); $result = $Controller->params['paging']['PaginatorCustomPost']; $this->assertEquals(4, $result['current']); @@ -994,7 +994,7 @@ class PaginatorComponentTest extends CakeTestCase { $Controller->paginate = array('published'); $result = $Controller->paginate(); - $this->assertEquals(Set::extract($result, '{n}.PaginatorCustomPost.id'), array(1, 2, 3)); + $this->assertEquals(array(1, 2, 3), Hash::extract($result, '{n}.PaginatorCustomPost.id')); $result = $Controller->params['paging']['PaginatorCustomPost']; $this->assertEquals(3, $result['current']); @@ -1002,7 +1002,7 @@ class PaginatorComponentTest extends CakeTestCase { $Controller->paginate = array('published', 'limit' => 2); $result = $Controller->paginate(); - $this->assertEquals(Set::extract($result, '{n}.PaginatorCustomPost.id'), array(1, 2)); + $this->assertEquals(array(1, 2), Hash::extract($result, '{n}.PaginatorCustomPost.id')); $result = $Controller->params['paging']['PaginatorCustomPost']; $this->assertEquals(2, $result['current']); diff --git a/lib/Cake/Test/Case/Model/Behavior/ContainableBehaviorTest.php b/lib/Cake/Test/Case/Model/Behavior/ContainableBehaviorTest.php index 1dbf1abac..360094fa8 100644 --- a/lib/Cake/Test/Case/Model/Behavior/ContainableBehaviorTest.php +++ b/lib/Cake/Test/Case/Model/Behavior/ContainableBehaviorTest.php @@ -92,7 +92,7 @@ class ContainableBehaviorTest extends CakeTestCase { 'Category' => 'name' ) ))); - $this->assertEquals(array('id'), Set::extract('/ArticleFeatured/keep/Featured/fields', $r)); + $this->assertEquals(array('id'), Hash::extract($r, 'ArticleFeatured.keep.Featured.fields')); $r = $this->_containments($this->Article, array( 'Comment' => array( @@ -109,29 +109,29 @@ class ContainableBehaviorTest extends CakeTestCase { $this->assertTrue(Set::matches('/User', $r)); $this->assertTrue(Set::matches('/Article/keep/Comment', $r)); $this->assertTrue(Set::matches('/Article/keep/User', $r)); - $this->assertEquals(array('comment', 'published'), Set::extract('/Article/keep/Comment/fields', $r)); - $this->assertEquals(array('user'), Set::extract('/Article/keep/User/fields', $r)); + $this->assertEquals(array('comment', 'published'), Hash::extract($r, 'Article.keep.Comment.fields')); + $this->assertEquals(array('user'), Hash::extract($r, 'Article.keep.User.fields')); $this->assertTrue(Set::matches('/Comment/keep/Attachment', $r)); - $this->assertEquals(array('attachment'), Set::extract('/Comment/keep/Attachment/fields', $r)); + $this->assertEquals(array('attachment'), Hash::extract($r, 'Comment.keep.Attachment.fields')); $r = $this->_containments($this->Article, array('Comment' => array('limit' => 1))); $this->assertEquals(array('Comment', 'Article'), array_keys($r)); - $result = Set::extract('/Comment/keep', $r); + $result = Hash::extract($r, 'Comment[keep]'); $this->assertEquals(array('keep' => array()), array_shift($result)); $this->assertTrue(Set::matches('/Article/keep/Comment', $r)); - $result = Set::extract('/Article/keep/Comment/.', $r); + $result = Hash::extract($r, 'Article.keep'); $this->assertEquals(array('limit' => 1), array_shift($result)); $r = $this->_containments($this->Article, array('Comment.User')); $this->assertEquals(array('User', 'Comment', 'Article'), array_keys($r)); - $result = Set::extract('/User/keep', $r); + $result = Hash::extract($r, 'User[keep]'); $this->assertEquals(array('keep' => array()), array_shift($result)); - $result = Set::extract('/Comment/keep', $r); + $result = Hash::extract($r, 'Comment[keep]'); $this->assertEquals(array('keep' => array('User' => array())), array_shift($result)); - $result = Set::extract('/Article/keep', $r); + $result = Hash::extract($r, 'Article[keep]'); $this->assertEquals(array('keep' => array('Comment' => array())), array_shift($result)); $r = $this->_containments($this->Tag, array('Article' => array('User' => array('Comment' => array( @@ -192,7 +192,7 @@ class ContainableBehaviorTest extends CakeTestCase { $this->assertFalse(Set::matches('/Comment[user_id!=2]', $r)); $r = $this->Article->find('all', array('contain' => 'Comment.id DESC')); - $ids = $descIds = Set::extract('/Comment[1]/id', $r); + $ids = $descIds = Hash::extract($r, 'Comment[1].id'); rsort($descIds); $this->assertEquals($ids, $descIds); diff --git a/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorScopedTest.php b/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorScopedTest.php index 6f9163a04..bb0d1704a 100644 --- a/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorScopedTest.php +++ b/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorScopedTest.php @@ -140,8 +140,8 @@ class TreeBehaviorScopedTest extends CakeTestCase { $this->Ad->id = 4; $result = $this->Ad->children(); - $this->assertEquals(array(6, 5), Set::extract('/Ad/id', $result)); - $this->assertEquals(array(2, 2), Set::extract('/Campaign/id', $result)); + $this->assertEquals(array(6, 5), Hash::extract($result, '{n}.Ad.id')); + $this->assertEquals(array(2, 2), Hash::extract($result, '{n}.Campaign.id')); } /** @@ -156,8 +156,8 @@ class TreeBehaviorScopedTest extends CakeTestCase { $this->Ad->id = 4; $result = $this->Ad->children(); - $this->assertEquals(array(5, 6), Set::extract('/Ad/id', $result)); - $this->assertEquals(array(2, 2), Set::extract('/Campaign/id', $result)); + $this->assertEquals(array(5, 6), Hash::extract($result, '{n}.Ad.id')); + $this->assertEquals(array(2, 2), Hash::extract($result, '{n}.Campaign.id')); } /** diff --git a/lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php b/lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php index 2a006d12d..8a63d603b 100644 --- a/lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php @@ -617,7 +617,7 @@ class DboSourceTest extends CakeTestCase { $this->testDb->logQuery('Query 2'); $log = $this->testDb->getLog(false, false); - $result = Set::extract($log['log'], '/query'); + $result = Hash::extract($log['log'], '{n}.query'); $expected = array('Query 1', 'Query 2'); $this->assertEquals($expected, $result); @@ -836,10 +836,10 @@ class DboSourceTest extends CakeTestCase { $log = $db->getLog(); $this->assertEquals($expected, $log['log'][0]); } - + /** - * Test build statement with some fields missing - * + * Test build statement with some fields missing + * * @return void */ public function testBuildStatementDefaults() { @@ -850,13 +850,13 @@ class DboSourceTest extends CakeTestCase { array( 'fields' => array('DISTINCT(AssetsTag.asset_id)'), 'table' => "assets_tags", - 'alias'=>"AssetsTag", + 'alias'=>"AssetsTag", 'conditions' => array("Tag.name"=>'foo bar'), - 'limit' => null, + 'limit' => null, 'group' => "AssetsTag.asset_id" ), $this->Model ); } - + } diff --git a/lib/Cake/Test/Case/Model/ModelCrossSchemaHabtmTest.php b/lib/Cake/Test/Case/Model/ModelCrossSchemaHabtmTest.php index 2e19f9ca7..0bf7ecd06 100644 --- a/lib/Cake/Test/Case/Model/ModelCrossSchemaHabtmTest.php +++ b/lib/Cake/Test/Case/Model/ModelCrossSchemaHabtmTest.php @@ -110,7 +110,7 @@ class ModelCrossSchemaHabtmTest extends BaseModelTest { ), )); $this->assertEquals(4, count($players)); - $wizards = Set::extract('/Guild[name=Wizards]', $players); + $wizards = Hash::extract($players, '{n}.Guild.{n}[name=Wizards]'); $this->assertEquals(1, count($wizards)); $players = $Player->find('all', array( @@ -120,7 +120,7 @@ class ModelCrossSchemaHabtmTest extends BaseModelTest { ), )); $this->assertEquals(1, count($players)); - $wizards = Set::extract('/Guild', $players); + $wizards = Hash::extract($players, '{n}.Guild.{n}'); $this->assertEquals(2, count($wizards)); } @@ -163,8 +163,7 @@ class ModelCrossSchemaHabtmTest extends BaseModelTest { ), ), )); - - $rangers = Set::extract('/Guild[name=Rangers]', $players); + $rangers = Hash::extract($players, '{n}.Guild.{n}[name=Rangers]'); $this->assertEquals(2, count($rangers)); } @@ -227,7 +226,7 @@ class ModelCrossSchemaHabtmTest extends BaseModelTest { 'Player.id' => 10, ) )); - $spongeBobsArmors = Set::extract('/Armor', $spongebob); + $spongeBobsArmors = Hash::extract($spongebob, '{n}.Armor.{n}'); $this->assertEquals(4, count($spongeBobsArmors)); } } diff --git a/lib/Cake/Test/Case/Model/ModelIntegrationTest.php b/lib/Cake/Test/Case/Model/ModelIntegrationTest.php index 05afa857a..080b55882 100644 --- a/lib/Cake/Test/Case/Model/ModelIntegrationTest.php +++ b/lib/Cake/Test/Case/Model/ModelIntegrationTest.php @@ -456,7 +456,7 @@ class ModelIntegrationTest extends BaseModelTest { $result = $TestModel->find('all'); $this->assertEquals($expected, $result); - $result = Set::extract($TestModel->User->find('all'), '{n}.User.id'); + $result = Hash::extract($TestModel->User->find('all'), '{n}.User.id'); $this->assertEquals(array('1', '2', '3', '4'), $result); $this->assertEquals($expected, $TestModel->find('all')); @@ -836,14 +836,14 @@ class ModelIntegrationTest extends BaseModelTest { $players = $Player->find('all'); $this->assertEquals(4 , count($players)); - $playersGuilds = Set::extract('/Guild/GuildsPlayer', $players); + $playersGuilds = Hash::extract($players, '{n}.Guild.{n}.GuildsPlayer'); $this->assertEquals(3 , count($playersGuilds)); - $playersArmors = Set::extract('/Armor/ArmorsPlayer', $players); + $playersArmors = Hash::extract($players, '{n}.Armor.{n}.ArmorsPlayer'); $this->assertEquals(3 , count($playersArmors)); unset($players); $larry = $Player->findByName('larry'); - $larrysArmor = Set::extract('/Armor/ArmorsPlayer', $larry); + $larrysArmor = Hash::extract($larry, 'Armor.{n}.ArmorsPlayer'); $this->assertEquals(1 , count($larrysArmor)); $larry['Guild']['Guild'] = array(1, 3); // larry joins another guild @@ -852,21 +852,20 @@ class ModelIntegrationTest extends BaseModelTest { unset($larry); $larry = $Player->findByName('larry'); - $larrysGuild = Set::extract('/Guild/GuildsPlayer', $larry); + $larrysGuild = Hash::extract($larry, 'Guild.{n}.GuildsPlayer'); $this->assertEquals(2 , count($larrysGuild)); - $larrysArmor = Set::extract('/Armor/ArmorsPlayer', $larry); + $larrysArmor = Hash::extract($larry, 'Armor.{n}.ArmorsPlayer'); $this->assertEquals(2 , count($larrysArmor)); - $larrysArmorsPlayersIds = Set::extract('/Armor/ArmorsPlayer/id', $larry); + $larrysArmorsPlayersIds = Hash::extract($larry, 'Armor.{n}.ArmorsPlayer.id'); $Player->ArmorsPlayer->id = 3; $Player->ArmorsPlayer->saveField('broken', true); // larry's cloak broke $larry = $Player->findByName('larry'); - $larrysArmor = Set::extract('/Armor/ArmorsPlayer', $larry); - $larrysCloak = Set::extract('/ArmorsPlayer[armor_id=3]', $larrysArmor); + $larrysCloak = Hash::extract($larry, 'Armor.{n}.ArmorsPlayer[armor_id=3]', $larry); $this->assertNotEmpty($larrysCloak); - $this->assertTrue($larrysCloak[0]['ArmorsPlayer']['broken']); // still broken + $this->assertTrue($larrysCloak[0]['broken']); // still broken } /** @@ -898,7 +897,7 @@ class ModelIntegrationTest extends BaseModelTest { $this->assertEquals($columns, array_keys($result)); $types = array('integer', 'integer', 'string', 'text', 'string', 'datetime', 'datetime'); - $this->assertEquals(Set::extract(array_values($result), '{n}.type'), $types); + $this->assertEquals(Hash::extract(array_values($result), '{n}.type'), $types); $result = $Post->schema('body'); $this->assertEquals('text', $result['type']); diff --git a/lib/Cake/Test/Case/Model/ModelReadTest.php b/lib/Cake/Test/Case/Model/ModelReadTest.php index 6254ceb97..eff7da54e 100644 --- a/lib/Cake/Test/Case/Model/ModelReadTest.php +++ b/lib/Cake/Test/Case/Model/ModelReadTest.php @@ -80,7 +80,7 @@ class ModelReadTest extends BaseModelTest { $this->assertEquals(2, count($result['SomethingElse'])); - $doomed = Set::extract('/JoinThing/doomed', $result['SomethingElse']); + $doomed = Hash::extract($result['SomethingElse'], '{n}.JoinThing.doomed'); $this->assertTrue(in_array(true, $doomed)); $this->assertTrue(in_array(false, $doomed)); } @@ -5028,19 +5028,19 @@ class ModelReadTest extends BaseModelTest { $this->loadFixtures('Author'); $TestModel = new ModifiedAuthor(); - $result = Set::extract($TestModel->find('all'), '/Author/user'); + $result = Hash::extract($TestModel->find('all'), '{n}.Author.user'); $expected = array('mariano (CakePHP)', 'nate (CakePHP)', 'larry (CakePHP)', 'garrett (CakePHP)'); $this->assertEquals($expected, $result); - $result = Set::extract($TestModel->find('all', array('callbacks' => 'after')), '/Author/user'); + $result = Hash::extract($TestModel->find('all', array('callbacks' => 'after')), '{n}.Author.user'); $expected = array('mariano (CakePHP)', 'nate (CakePHP)', 'larry (CakePHP)', 'garrett (CakePHP)'); $this->assertEquals($expected, $result); - $result = Set::extract($TestModel->find('all', array('callbacks' => 'before')), '/Author/user'); + $result = Hash::extract($TestModel->find('all', array('callbacks' => 'before')), '{n}.Author.user'); $expected = array('mariano', 'nate', 'larry', 'garrett'); $this->assertEquals($expected, $result); - $result = Set::extract($TestModel->find('all', array('callbacks' => false)), '/Author/user'); + $result = Hash::extract($TestModel->find('all', array('callbacks' => false)), '{n}.Author.user'); $expected = array('mariano', 'nate', 'larry', 'garrett'); $this->assertEquals($expected, $result); } diff --git a/lib/Cake/Test/Case/Model/ModelWriteTest.php b/lib/Cake/Test/Case/Model/ModelWriteTest.php index ed1dc0ed1..c165aabf6 100644 --- a/lib/Cake/Test/Case/Model/ModelWriteTest.php +++ b/lib/Cake/Test/Case/Model/ModelWriteTest.php @@ -632,11 +632,11 @@ class ModelWriteTest extends BaseModelTest { $Node = new Node(); $Node->set('id', 1); $result = $Node->read(); - $this->assertEquals(array('Second'), Set::extract('/ParentNode/name', $result)); + $this->assertEquals(array('Second'), Hash::extract($result, 'ParentNode.{n}.name')); $Node->saveField('state', 10); $result = $Node->read(); - $this->assertEquals(array('Second'), Set::extract('/ParentNode/name', $result)); + $this->assertEquals(array('Second'), Hash::extract($result, 'ParentNode.{n}.name')); } /** @@ -1570,9 +1570,9 @@ class ModelWriteTest extends BaseModelTest { $TestModel->save($data); $result = $TestModel->read(null, 1); $expected = array(4, 5); - $this->assertEquals($expected, Set::extract('/JoinC/JoinAsJoinC/id', $result)); + $this->assertEquals($expected, Hash::extract($result, 'JoinC.{n}.JoinAsJoinC.id')); $expected = array('new record', 'new record'); - $this->assertEquals($expected, Set::extract('/JoinC/JoinAsJoinC/other', $result)); + $this->assertEquals($expected, Hash::extract($result, 'JoinC.{n}.JoinAsJoinC.other')); } /** @@ -4492,7 +4492,7 @@ class ModelWriteTest extends BaseModelTest { * @return void */ public function testSaveAllValidateFirst() { - $this->loadFixtures('Article', 'Comment', 'Attachment'); + $this->loadFixtures('Article', 'Comment', 'Attachment', 'User', 'ArticlesTag', 'Tag'); $model = new Article(); $model->deleteAll(true); @@ -4539,7 +4539,7 @@ class ModelWriteTest extends BaseModelTest { $result = $model->Comment->find('all'); $this->assertSame(count($result), 1); - $result = Set::extract('/Comment/article_id', $result); + $result = Hash::extract($result, '{n}.Comment.article_id'); $this->assertEquals(4, $result[0]); $model->deleteAll(true); @@ -4570,6 +4570,7 @@ class ModelWriteTest extends BaseModelTest { * @return void */ public function testSaveAllValidateFirstAtomicFalse() { + $this->loadFixtures('Something'); $Something = new Something(); $invalidData = array( array( @@ -5177,7 +5178,7 @@ class ModelWriteTest extends BaseModelTest { 'First new comment', 'Second new comment' ); - $this->assertEquals($expected, Set::extract($result['Comment'], '{n}.comment')); + $this->assertEquals($expected, Hash::extract($result['Comment'], '{n}.comment')); $result = $TestModel->saveAssociated( array( @@ -5200,7 +5201,7 @@ class ModelWriteTest extends BaseModelTest { 'Second new comment', 'Third new comment' ); - $this->assertEquals($expected, Set::extract($result['Comment'], '{n}.comment')); + $this->assertEquals($expected, Hash::extract($result['Comment'], '{n}.comment')); $TestModel->beforeSaveReturn = false; $result = $TestModel->saveAssociated( @@ -5224,7 +5225,7 @@ class ModelWriteTest extends BaseModelTest { 'Second new comment', 'Third new comment' ); - $this->assertEquals($expected, Set::extract($result['Comment'], '{n}.comment')); + $this->assertEquals($expected, Hash::extract($result['Comment'], '{n}.comment')); } /** @@ -5840,7 +5841,7 @@ class ModelWriteTest extends BaseModelTest { $result = $model->Comment->find('all'); $this->assertSame(count($result), 1); - $result = Set::extract('/Comment/article_id', $result); + $result = Hash::extract($result, '{n}.Comment.article_id'); $this->assertEquals(4, $result[0]); $model->deleteAll(true); @@ -6066,15 +6067,15 @@ class ModelWriteTest extends BaseModelTest { )); $this->assertFalse(empty($result)); - $result = Set::extract('/DataTest/count', $model->find('all', array('fields' => 'count'))); + $result = Hash::extract($model->find('all', array('fields' => 'count')), '{n}.DataTest.count'); $this->assertEquals(array(5, 3, 4, 1), $result); $this->assertTrue($model->updateAll(array('count' => 'count + 2'))); - $result = Set::extract('/DataTest/count', $model->find('all', array('fields' => 'count'))); + $result = Hash::extract($model->find('all', array('fields' => 'count')), '{n}.DataTest.count'); $this->assertEquals(array(7, 5, 6, 3), $result); $this->assertTrue($model->updateAll(array('DataTest.count' => 'DataTest.count - 1'))); - $result = Set::extract('/DataTest/count', $model->find('all', array('fields' => 'count'))); + $result = Hash::extract($model->find('all', array('fields' => 'count')), '{n}.DataTest.count'); $this->assertEquals(array(6, 4, 5, 2), $result); }