Skip to content

Commit fb1fa83

Browse files
committed
[test] Finishing up the functional test for admin menu reordering.
1 parent 6636efd commit fb1fa83

File tree

4 files changed

+79
-22
lines changed

4 files changed

+79
-22
lines changed

config/ioDoctrineMenuPluginConfiguration.class.php

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public function loadRoutes(sfEvent $event)
8787
array(
8888
'module' => 'io_doctrine_menu',
8989
'action' => 'json',
90+
'sf_format' => 'json',
9091
),
9192
array(
9293
'sf_method' => array('get'),

test/fixtures/project/lib/test/unitHelper.php

+33
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,37 @@ function check_child_ordering(lime_test $t, ioDoctrineMenuItem $rt, $path, array
239239
}
240240

241241
$t->is($childNameArray, $ordering, 'The children are ordered correctly: '. implode(',', $childNameArray));
242+
}
243+
244+
// returns an array that closely mimics what's posted from the Nested Sortable widget
245+
// $arr is the return value from create_doctrine_test_tree()
246+
function get_nested_set_save_array(array $arr)
247+
{
248+
extract($arr);
249+
250+
$arr = array(
251+
array(
252+
'id' => $pt2->id,
253+
'children' => array(
254+
array(
255+
'id' => $ch4->id,
256+
'children' => array(
257+
array('id' => $gc1->id),
258+
)
259+
),
260+
)
261+
),
262+
array(
263+
'id' => $pt1->id,
264+
'children' => array(
265+
array('id' => $ch3->id),
266+
array('id' => $ch1->id),
267+
array('id' => $ch2->id),
268+
)
269+
)
270+
);
271+
272+
return array(
273+
'items' => $arr
274+
);
242275
}

test/functional/reorderingTest.php

+41
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,46 @@
3131
->with('response')->begin()
3232
->isStatusCode(200)
3333
->checkElement('h1', '/Reorder Menu "Root li"/')
34+
->info(' 1.3 - check for the correct nested set javascript urls')
35+
->matches('/loadUrl:\ \'\/index\.php\/test\/menu\/reorder\/json\/'.$rt->id.'/')
36+
->matches('/saveUrl:\ \'\/index\.php\/test\/menu\/reorder\/save\/'.$rt->id.'/')
3437
->end()
3538
;
39+
40+
$browser->info('2 - Check out the json response for the menu')
41+
->get('/test/menu/reorder/json/'.$rt->id)
42+
43+
->with('request')->begin()
44+
->isParameter('module', 'io_doctrine_menu')
45+
->isParameter('action', 'json')
46+
->isParameter('sf_format', 'json')
47+
->end()
48+
49+
->with('response')->begin()
50+
->isStatusCode(200)
51+
->end()
52+
;
53+
$response = $browser->getResponse()->getContent();
54+
$json = json_decode($response);
55+
$browser->test()->isnt($json, null, 'The response returns a valid json object');
56+
57+
$browser->info('3 - Test the save method')
58+
->call('/test/menu/reorder/save/'.$rt->id, 'post', array(
59+
'nested-sortable-widget' => get_nested_set_save_array($arr)
60+
))
61+
62+
->with('request')->begin()
63+
->isParameter('module', 'io_doctrine_menu')
64+
->isParameter('action', 'saveJson')
65+
->end()
66+
67+
->with('response')->begin()
68+
->isStatusCode(200)
69+
->end()
70+
;
71+
72+
$browser->info(' 3.1 - Check the menu to see that it was updated');
73+
root_sanity_check($browser->test(), $rt);
74+
check_child_ordering($browser->test(), $rt, array(), array('Parent 2', 'Parent 1'));
75+
check_child_ordering($browser->test(), $rt, array(0), array('Child 4'));
76+
check_child_ordering($browser->test(), $rt, array(1), array('Child 3', 'Child 1', 'Child 2'));

test/unit/model/doctrine/PluginioDoctrineMenuItemTableTest.php

+4-22
Original file line numberDiff line numberDiff line change
@@ -77,29 +77,11 @@
7777

7878
$t->info('6 - Test restoreTreeFromNestedArray()');
7979
$tbl->createQuery()->delete()->execute();
80-
extract(create_doctrine_test_tree($t));
80+
$arr = create_doctrine_test_tree($t);
81+
extract($arr);
8182

82-
$newOrder = array(
83-
array(
84-
'id' => $pt2->id,
85-
'children' => array(
86-
array(
87-
'id' => $ch4->id,
88-
'children' => array(
89-
array('id' => $gc1->id),
90-
)
91-
),
92-
)
93-
),
94-
array(
95-
'id' => $pt1->id,
96-
'children' => array(
97-
array('id' => $ch3->id),
98-
array('id' => $ch1->id),
99-
array('id' => $ch2->id),
100-
)
101-
)
102-
);
83+
$newOrder = get_nested_set_save_array($arr);
84+
$newOrder = $newOrder['items'];
10385

10486
$tbl->restoreTreeFromNestedArray($newOrder, $rt);
10587
root_sanity_check($t, $rt);

0 commit comments

Comments
 (0)