Permalink
Browse files

Merge remote-tracking branch 'ceeram/2.2-hash' into 2.2-hash

  • Loading branch information...
2 parents 8378991 + 2b7fe21 commit eeec3627415635a5e11237bcf2cb049706086b53 @markstory markstory committed Apr 7, 2012
@@ -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'))
)))
);
}
@@ -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,23 +986,23 @@ 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']);
$this->assertEquals(4, $result['count']);
$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']);
$this->assertEquals(3, $result['count']);
$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']);
@@ -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);
@@ -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'));
}
/**
@@ -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
);
}
-
+
}
@@ -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));
}
}
@@ -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']);
@@ -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);
}
Oops, something went wrong. Retry.

0 comments on commit eeec362

Please sign in to comment.