public function testExtractAssociatedHasMany()
{
$common = array(array('Article' => array('id' => 1, 'name' => 'Article 1'), 'Comment' => array(array('id' => 1, 'user_id' => 5, 'article_id' => 1, 'text' => 'Comment 1'), array('id' => 2, 'user_id' => 23, 'article_id' => 1, 'text' => 'Comment 2'), array('id' => 3, 'user_id' => 17, 'article_id' => 1, 'text' => 'Comment 3'))), array('Article' => array('id' => 2, 'name' => 'Article 2'), 'Comment' => array(array('id' => 4, 'user_id' => 2, 'article_id' => 2, 'text' => 'Comment 4', 'addition' => ''), array('id' => 5, 'user_id' => 23, 'article_id' => 2, 'text' => 'Comment 5', 'addition' => 'foo'))), array('Article' => array('id' => 3, 'name' => 'Article 3'), 'Comment' => array()));
$result = Set::extract($common, '/');
$this->assertEqual($result, $common);
$expected = array(1);
$result = Set::extract($common, '/Comment/id[:first]');
$this->assertEqual($expected, $result);
$expected = array(5);
$result = Set::extract($common, '/Comment/id[:last]');
$this->assertEqual($expected, $result);
$result = Set::extract($common, '/Comment/id');
$expected = array(1, 2, 3, 4, 5);
$this->assertEqual($expected, $result);
$expected = array(1, 2, 4, 5);
$result = Set::extract($common, '/Comment[id!=3]/id');
$this->assertEqual($expected, $result);
$expected = array($common[0]['Comment'][2]);
$result = Set::extract($common, '/Comment/2');
$this->assertEqual($expected, $result);
$expected = array($common[0]['Comment'][0]);
$result = Set::extract($common, '/Comment[1]/.[id=1]');
$this->assertEqual($expected, $result);
$expected = array($common[1]['Comment'][1]);
$result = Set::extract($common, '/1/Comment/.[2]');
$this->assertEqual($expected, $result);
$expected = array(array('Comment' => $common[1]['Comment'][0]));
$result = Set::extract($common, '/Comment[addition=]');
$this->assertEqual($expected, $result);
$expected = array(3);
$result = Set::extract($common, '/Article[:last]/id');
$this->assertEqual($expected, $result);
$expected = array();
$result = Set::extract(array(), '/User/id');
$this->assertEqual($expected, $result);
}