mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Added tests for Model::__doThread and to prove #3924 which seems to already have been applied to the core. Closes #3924
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6717 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
f9ea98e746
commit
e1ffd25d49
1 changed files with 106 additions and 0 deletions
|
@ -2576,6 +2576,112 @@ class ModelTest extends CakeTestCase {
|
|||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
function testDoThread() {
|
||||
$this->model =& new Category();
|
||||
$this->db->fullDebug = true;
|
||||
|
||||
$result = array(
|
||||
array('Category' => array('id' => 1, 'parent_id' => 0, 'name' => 'Category 1')),
|
||||
array('Category' => array('id' => 2, 'parent_id' => 1, 'name' => 'Category 1.1')),
|
||||
array('Category' => array('id' => 3, 'parent_id' => 1, 'name' => 'Category 1.2')),
|
||||
array('Category' => array('id' => 4, 'parent_id' => 2, 'name' => 'Category 1.1.1')),
|
||||
array('Category' => array('id' => 5, 'parent_id' => 0, 'name' => 'Category 2')),
|
||||
array('Category' => array('id' => 6, 'parent_id' => 5, 'name' => 'Category 2.1')),
|
||||
array('Category' => array('id' => 7, 'parent_id' => 6, 'name' => 'Category 2.1.1'))
|
||||
);
|
||||
$result = $this->model->__doThread($result, null);
|
||||
|
||||
$expected = array(
|
||||
array(
|
||||
'Category' => array('id' => 1, 'parent_id' => 0, 'name' => 'Category 1'),
|
||||
'children' => array(
|
||||
array(
|
||||
'Category' => array('id' => 2, 'parent_id' => 1, 'name' => 'Category 1.1'),
|
||||
'children' => array(
|
||||
array(
|
||||
'Category' => array('id' => 4, 'parent_id' => 2, 'name' => 'Category 1.1.1'),
|
||||
'children' => array()
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
'Category' => array('id' => 3, 'parent_id' => 1, 'name' => 'Category 1.2'),
|
||||
'children' => array()
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
'Category' => array('id' => 5, 'parent_id' => 0, 'name' => 'Category 2'),
|
||||
'children' => array(
|
||||
array(
|
||||
'Category' => array('id' => 6, 'parent_id' => 5, 'name' => 'Category 2.1'),
|
||||
'children' => array(
|
||||
array(
|
||||
'Category' => array('id' => 7, 'parent_id' => 6, 'name' => 'Category 2.1.1'),
|
||||
'children' => array()
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
function testDoThreadOrdered() {
|
||||
$this->model =& new Category();
|
||||
$this->db->fullDebug = true;
|
||||
|
||||
$result = array(
|
||||
array('Category' => array('id' => 7, 'parent_id' => 6, 'name' => 'Category 2.1.1')),
|
||||
array('Category' => array('id' => 6, 'parent_id' => 5, 'name' => 'Category 2.1')),
|
||||
array('Category' => array('id' => 5, 'parent_id' => 0, 'name' => 'Category 2')),
|
||||
array('Category' => array('id' => 4, 'parent_id' => 2, 'name' => 'Category 1.1.1')),
|
||||
array('Category' => array('id' => 3, 'parent_id' => 1, 'name' => 'Category 1.2')),
|
||||
array('Category' => array('id' => 2, 'parent_id' => 1, 'name' => 'Category 1.1')),
|
||||
array('Category' => array('id' => 1, 'parent_id' => 0, 'name' => 'Category 1'))
|
||||
);
|
||||
$result = $this->model->__doThread($result, null);
|
||||
|
||||
$expected = array(
|
||||
array(
|
||||
'Category' => array('id' => 5, 'parent_id' => 0, 'name' => 'Category 2'),
|
||||
'children' => array(
|
||||
array(
|
||||
'Category' => array('id' => 6, 'parent_id' => 5, 'name' => 'Category 2.1'),
|
||||
'children' => array(
|
||||
array(
|
||||
'Category' => array('id' => 7, 'parent_id' => 6, 'name' => 'Category 2.1.1'),
|
||||
'children' => array()
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
'Category' => array('id' => 1, 'parent_id' => 0, 'name' => 'Category 1'),
|
||||
'children' => array(
|
||||
array(
|
||||
'Category' => array('id' => 3, 'parent_id' => 1, 'name' => 'Category 1.2'),
|
||||
'children' => array()
|
||||
),
|
||||
array(
|
||||
'Category' => array('id' => 2, 'parent_id' => 1, 'name' => 'Category 1.1'),
|
||||
'children' => array(
|
||||
array(
|
||||
'Category' => array('id' => 4, 'parent_id' => 2, 'name' => 'Category 1.1.1'),
|
||||
'children' => array()
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
function testFindNeighbours() {
|
||||
$this->loadFixtures('User', 'Article');
|
||||
$this->model =& new Article();
|
||||
|
|
Loading…
Reference in a new issue