Skip to content

Commit

Permalink
Moving tests around in set test.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Mar 27, 2010
1 parent 35446a4 commit 3040c6f
Showing 1 changed file with 78 additions and 80 deletions.
158 changes: 78 additions & 80 deletions cake/tests/cases/libs/set.test.php
Expand Up @@ -795,10 +795,87 @@ function testExtract() {

$r = Set::extract('/Comment/User[name=/bob|tod/]/..', $habtm);
$this->assertEqual($r[0]['Comment']['User']['name'], 'bob');
// Currently failing, needs fix
$this->assertEqual($r[1]['Comment']['User']['name'], 'tod');
$this->assertEqual(count($r), 2);

$mixedKeys = array(
'User' => array(
0 => array(
'id' => 4,
'name' => 'Neo'
),
1 => array(
'id' => 5,
'name' => 'Morpheus'
),
'stringKey' => array()
)
);
$expected = array('Neo', 'Morpheus');
$r = Set::extract('/User/name', $mixedKeys);
$this->assertEqual($r, $expected);

$f = array(
array(
'file' => array(
'name' => 'zipfile.zip',
'type' => 'application/zip',
'tmp_name' => '/tmp/php178.tmp',
'error' => 0,
'size' => '564647'
)
),
array(
'file' => array(
'name' => 'zipfile2.zip',
'type' => 'application/x-zip-compressed',
'tmp_name' => '/tmp/php179.tmp',
'error' => 0,
'size' => '354784'
)
),
array(
'file' => array(
'name' => 'picture.jpg',
'type' => 'image/jpeg',
'tmp_name' => '/tmp/php180.tmp',
'error' => 0,
'size' => '21324'
)
)
);
$expected = array(array('name' => 'zipfile2.zip','type' => 'application/x-zip-compressed','tmp_name' => '/tmp/php179.tmp','error' => 0,'size' => '354784'));
$r = Set::extract('/file/.[type=application/x-zip-compressed]', $f);
$this->assertEqual($r, $expected);

$expected = array(array('name' => 'zipfile.zip','type' => 'application/zip','tmp_name' => '/tmp/php178.tmp','error' => 0,'size' => '564647'));
$r = Set::extract('/file/.[type=application/zip]', $f);
$this->assertEqual($r, $expected);

$hasMany = array(
'Node' => array(
'id' => 1,
'name' => 'First',
'state' => 50
),
'ParentNode' => array(
0 => array(
'id' => 2,
'name' => 'Second',
'state' => 60,
)
)
);
$result = Set::extract('/ParentNode/name', $hasMany);
$expected = array('Second');
$this->assertEqual($result, $expected);
}
/**
* test parent selectors with extract
*
* @return void
*/
function testExtractParentSelector() {
$tree = array(
array(
'Category' => array(
Expand Down Expand Up @@ -855,24 +932,6 @@ function testExtract() {
$r = Set::extract('/Category[name=Category 2]/../children', $tree);
$this->assertEqual($r, $expected);

$mixedKeys = array(
'User' => array(
0 => array(
'id' => 4,
'name' => 'Neo'
),
1 => array(
'id' => 5,
'name' => 'Morpheus'
),
'stringKey' => array()
)
);

$expected = array('Neo', 'Morpheus');
$r = Set::extract('/User/name', $mixedKeys);
$this->assertEqual($r, $expected);

$single = array(
array(
'CallType' => array(
Expand Down Expand Up @@ -919,67 +978,6 @@ function testExtract() {
$r = Set::extract('/CallType[name=Internal Voice]/../x/hour', $multiple);
$this->assertEqual($r, $expected);

$f = array(
array(
'file' => array(
'name' => 'zipfile.zip',
'type' => 'application/zip',
'tmp_name' => '/tmp/php178.tmp',
'error' => 0,
'size' => '564647'
)
),
array(
'file' => array(
'name' => 'zipfile2.zip',
'type' => 'application/x-zip-compressed',
'tmp_name' => '/tmp/php179.tmp',
'error' => 0,
'size' => '354784'
)
),
array(
'file' => array(
'name' => 'picture.jpg',
'type' => 'image/jpeg',
'tmp_name' => '/tmp/php180.tmp',
'error' => 0,
'size' => '21324'
)
)
);
$expected = array(array('name' => 'zipfile2.zip','type' => 'application/x-zip-compressed','tmp_name' => '/tmp/php179.tmp','error' => 0,'size' => '354784'));
$r = Set::extract('/file/.[type=application/x-zip-compressed]', $f);
$this->assertEqual($r, $expected);

$expected = array(array('name' => 'zipfile.zip','type' => 'application/zip','tmp_name' => '/tmp/php178.tmp','error' => 0,'size' => '564647'));
$r = Set::extract('/file/.[type=application/zip]', $f);
$this->assertEqual($r, $expected);

$hasMany = array(
'Node' => array(
'id' => 1,
'name' => 'First',
'state' => 50
),
'ParentNode' => array(
0 => array(
'id' => 2,
'name' => 'Second',
'state' => 60,
)
)
);
$result = Set::extract('/ParentNode/name', $hasMany);
$expected = array('Second');
$this->assertEqual($result, $expected);
}
/**
* test parent selectors with extract
*
* @return void
*/
function testExtractParentSelector() {
$a = array(
'Model' => array(
'0' => array(
Expand Down

0 comments on commit 3040c6f

Please sign in to comment.