public function testExtractHabtm()
{
$habtm = array(array('Post' => array('id' => 1, 'title' => 'great post'), 'Comment' => array(array('id' => 1, 'text' => 'foo', 'User' => array('id' => 1, 'name' => 'bob')), array('id' => 2, 'text' => 'bar', 'User' => array('id' => 2, 'name' => 'tod')))), array('Post' => array('id' => 2, 'title' => 'fun post'), 'Comment' => array(array('id' => 3, 'text' => '123', 'User' => array('id' => 3, 'name' => 'dan')), array('id' => 4, 'text' => '987', 'User' => array('id' => 4, 'name' => 'jim')))));
$result = Set::extract($habtm, '/Comment/User[name=/\\w+/]/..');
$this->assertEqual(count($result), 4);
$this->assertEqual($result[0]['Comment']['User']['name'], 'bob');
$this->assertEqual($result[1]['Comment']['User']['name'], 'tod');
$this->assertEqual($result[2]['Comment']['User']['name'], 'dan');
$this->assertEqual($result[3]['Comment']['User']['name'], 'jim');
$result = Set::extract($habtm, '/Comment/User[name=/[a-z]+/]/..');
$this->assertEqual(count($result), 4);
$this->assertEqual($result[0]['Comment']['User']['name'], 'bob');
$this->assertEqual($result[1]['Comment']['User']['name'], 'tod');
$this->assertEqual($result[2]['Comment']['User']['name'], 'dan');
$this->assertEqual($result[3]['Comment']['User']['name'], 'jim');
$result = Set::extract($habtm, '/Comment/User[name=/bob|dan/]/..');
$this->assertEqual(count($result), 2);
$this->assertEqual($result[0]['Comment']['User']['name'], 'bob');
$this->assertEqual($result[1]['Comment']['User']['name'], 'dan');
$result = Set::extract($habtm, '/Comment/User[name=/bob|tod/]/..');
$this->assertEqual(count($result), 2);
$this->assertEqual($result[0]['Comment']['User']['name'], 'bob');
$this->assertEqual($result[1]['Comment']['User']['name'], 'tod');
}