$t->info('5 - Test the cache invalidation'); $manager = $configuration->getPluginConfiguration('ioDoctrineMenuPlugin')->getMenuManager(); $cacheKey = md5('Root li'); Doctrine_Query::create()->from('ioDoctrineMenuItem')->delete()->execute(); $arr = create_doctrine_test_tree($t); $rt = $arr['rt']; $t->info(' 5.1 - Retrieve the menu through the menu manager, it should set the cache.'); $menu = $manager->getMenu('Root li'); $t->is($manager->getCacheDriver()->has($cacheKey), true, 'Retrieving the menu sets the cache on the manager'); $t->info(' 5.2 - Change the root node and save, see that the cache cleared.'); $rt->setLabel('Changed label'); $rt->save(); $t->is($manager->getCacheDriver()->has($cacheKey), false, 'The cache is now unset.'); $t->info(' 5.3 - Re-put the cache, modify a child element, and see that the cache clears.'); $menu = $manager->getMenu('Root li'); $t->is($manager->getCacheDriver()->has($cacheKey), true, 'Retrieving the menu sets the cache on the manager'); $children = $rt->getNode()->getChildren(); $children[0]->setRoute('http://www.doctrine-project.org'); $children[0]->save(); $t->is($manager->getCacheDriver()->has($cacheKey), false, 'The cache is now unset.'); $t->info('6 - Test restoreTreeFromNestedArray()'); $tbl->createQuery()->delete()->execute(); $arr = create_doctrine_test_tree($t); extract($arr); $newOrder = get_nested_set_save_array($arr); $newOrder = $newOrder['items']; $tbl->restoreTreeFromNestedArray($newOrder, $rt); root_sanity_check($t, $rt); check_child_ordering($t, $rt, array(), array('Parent 2', 'Parent 1')); check_child_ordering($t, $rt, array(0), array('Child 4')); check_child_ordering($t, $rt, array(1), array('Child 3', 'Child 1', 'Child 2'));
<?php require_once dirname(__FILE__) . '/../bootstrap/functional.php'; require_once sfConfig::get('sf_lib_dir') . '/test/unitHelper.php'; $browser = new sfTestFunctional(new sfBrowser()); $arr = create_doctrine_test_tree($browser->test()); $rt = $arr['rt']; $browser->info('1 - Goto the reorder page and look around')->info(' 1.1 - Goto the reorder page with a fake name sends to a 404')->get('/test/menu/reorder/fake')->with('request')->begin()->isParameter('module', 'io_doctrine_menu')->isParameter('action', 'reorder')->end()->with('response')->begin()->isStatusCode(404)->end()->info(' 1.2 - Goto a real menu reordering page')->get('/test/menu/reorder/' . $rt->id)->with('request')->begin()->isParameter('module', 'io_doctrine_menu')->isParameter('action', 'reorder')->end()->with('response')->begin()->isStatusCode(200)->checkElement('h1', '/Reorder Menu "Root li"/')->info(' 1.3 - check for the correct nested set javascript urls')->matches('/loadUrl:\\ \'\\/index\\.php\\/test\\/menu\\/reorder\\/json\\/' . $rt->id . '/')->matches('/saveUrl:\\ \'\\/index\\.php\\/test\\/menu\\/reorder\\/save\\/' . $rt->id . '/')->end(); $browser->info('2 - Check out the json response for the menu')->get('/test/menu/reorder/json/' . $rt->id)->with('request')->begin()->isParameter('module', 'io_doctrine_menu')->isParameter('action', 'json')->isParameter('sf_format', 'json')->end()->with('response')->begin()->isStatusCode(200)->end(); $response = $browser->getResponse()->getContent(); $json = json_decode($response); $browser->test()->isnt($json, null, 'The response returns a valid json object'); $browser->info('3 - Test the save method')->call('/test/menu/reorder/save/' . $rt->id, 'post', array('nested-sortable-widget' => get_nested_set_save_array($arr)))->with('request')->begin()->isParameter('module', 'io_doctrine_menu')->isParameter('action', 'saveJson')->end()->with('response')->begin()->isStatusCode(200)->end(); $browser->info(' 3.1 - Check the menu to see that it was updated'); root_sanity_check($browser->test(), $rt); check_child_ordering($browser->test(), $rt, array(), array('Parent 2', 'Parent 1')); check_child_ordering($browser->test(), $rt, array(0), array('Child 4')); check_child_ordering($browser->test(), $rt, array(1), array('Child 3', 'Child 1', 'Child 2'));