Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

remove all Set::extract() from core and tests

  • Loading branch information...
commit 2b7fe21ee089d3e58afa310670dfb395e5c72aa6 1 parent 7700a02
@ceeram ceeram authored
View
12 lib/Cake/Model/Permission.php
@@ -105,7 +105,7 @@ public function check($aro, $aco, $action = "*") {
}
$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 @@ public function check($aro, $aco, $action = "*") {
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 @@ public function getAclLink($aro, $aco) {
}
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'))
)))
);
}
View
8 lib/Cake/Test/Case/Controller/Component/PaginatorComponentTest.php
@@ -619,7 +619,7 @@ public function testPaginateOrderVirtualField() {
$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 @@ public function testPaginateCustomFind() {
$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 @@ public function testPaginateCustomFind() {
$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 @@ public function testPaginateCustomFind() {
$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']);
View
20 lib/Cake/Test/Case/Model/Behavior/ContainableBehaviorTest.php
@@ -92,7 +92,7 @@ public function testContainments() {
'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 @@ public function testContainments() {
$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 @@ public function testBeforeFind() {
$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);
View
8 lib/Cake/Test/Case/Model/Behavior/TreeBehaviorScopedTest.php
@@ -140,8 +140,8 @@ public function testMoveUpWithScope() {
$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 @@ public function testMoveDownWithScope() {
$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'));
}
/**
View
14 lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php
@@ -617,7 +617,7 @@ public function testLog() {
$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 @@ public function testTransactionLogging() {
$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 @@ public function testBuildStatementDefaults() {
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
);
}
-
+
}
View
9 lib/Cake/Test/Case/Model/ModelCrossSchemaHabtmTest.php
@@ -110,7 +110,7 @@ public function testHabtmFind() {
),
));
$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 @@ public function testHabtmFind() {
),
));
$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 @@ public function testHabtmSave() {
),
),
));
-
- $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 @@ public function testHabtmWithThreeDatabases() {
'Player.id' => 10,
)
));
- $spongeBobsArmors = Set::extract('/Armor', $spongebob);
+ $spongeBobsArmors = Hash::extract($spongebob, '{n}.Armor.{n}');
$this->assertEquals(4, count($spongeBobsArmors));
}
}
View
21 lib/Cake/Test/Case/Model/ModelIntegrationTest.php
@@ -456,7 +456,7 @@ public function testCrossDatabaseJoins() {
$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 @@ public function testHABTMKeepExistingWithThreeDbs() {
$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 @@ public function testHABTMKeepExistingWithThreeDbs() {
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 @@ public function testSchema() {
$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']);
View
10 lib/Cake/Test/Case/Model/ModelReadTest.php
@@ -80,7 +80,7 @@ public function testFetchingNonUniqueFKJoinTableRecords() {
$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 @@ public function testCallbackDisabling() {
$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);
}
View
27 lib/Cake/Test/Case/Model/ModelWriteTest.php
@@ -632,11 +632,11 @@ public function testSaveField() {
$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 @@ public function testSaveHabtm() {
$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 @@ public function testSaveAllValidationOnly() {
* @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 @@ public function testSaveAllValidateFirst() {
$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 @@ public function testSaveAllValidateFirst() {
* @return void
*/
public function testSaveAllValidateFirstAtomicFalse() {
+ $this->loadFixtures('Something');
$Something = new Something();
$invalidData = array(
array(
@@ -5177,7 +5178,7 @@ public function testSaveAssociatedHasMany() {
'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 @@ public function testSaveAssociatedHasMany() {
'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 @@ public function testSaveAssociatedHasMany() {
'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 @@ public function testSaveAssociatedValidateFirst() {
$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 @@ public function testUpdateWithCalculation() {
));
$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);
}
Please sign in to comment.
Something went wrong with that request. Please try again.