Author: weaverryan
Date: 2010-02-10 06:19:48 +0100 (Wed, 10 Feb 2010)
New Revision: 27802

Modified:
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalMenuPlugin/lib/menu/sfSympalMenu.class.php
   plugins/sfSympalPlugin/trunk/test/unit/MenuTest.php
Log:
[1.4][sfSympalPlugin][1.0] Added test for hasChildren() and simplified the 
function slightly.


Modified: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalMenuPlugin/lib/menu/sfSympalMenu.class.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalMenuPlugin/lib/menu/sfSympalMenu.class.php
 2010-02-10 05:14:34 UTC (rev 27801)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalMenuPlugin/lib/menu/sfSympalMenu.class.php
 2010-02-10 05:19:48 UTC (rev 27802)
@@ -1,5 +1,14 @@
 <?php
 
+/**
+ * Base menu item in sympal
+ * 
+ * @package     sfSympalMenuPlugin
+ * @subpackage  menu
+ * @author      Jonathan H. Wage <[email protected]>
+ * @author      Ryan Weaver <[email protected]>
+ * @version     svn:$Id$ $Author$
+ */
 class sfSympalMenu implements ArrayAccess, Countable, IteratorAggregate
 {
   protected
@@ -352,18 +361,26 @@
 
     return $this->_children[$name];
   }
-
+  
+  /**
+   * Returns whether or not this menu items has viewable children
+   * 
+   * This menu MAY have children, but this will return false if the current
+   * user does not have access to vew any of those items
+   * 
+   * @return boolean;
+   */
   public function hasChildren()
   {
-    $children = array();
     foreach ($this->_children as $child)
     {
       if ($child->checkUserAccess())
       {
-        $children[] = true;
+        return true;
       }
     }
-    return !empty($children);
+    
+    return false;
   }
 
   public function __toString()

Modified: plugins/sfSympalPlugin/trunk/test/unit/MenuTest.php
===================================================================
--- plugins/sfSympalPlugin/trunk/test/unit/MenuTest.php 2010-02-10 05:14:34 UTC 
(rev 27801)
+++ plugins/sfSympalPlugin/trunk/test/unit/MenuTest.php 2010-02-10 05:19:48 UTC 
(rev 27802)
@@ -3,7 +3,7 @@
 $app = 'sympal';
 require_once(dirname(__FILE__).'/../bootstrap/unit.php');
 
-$t = new lime_test(53, new lime_output_color());
+$t = new lime_test(55, new lime_output_color());
 
 $configuration->loadHelpers(array('Tag'));
 
@@ -81,8 +81,12 @@
 $menu['Root 3']['With Route']->setOption('target', '_BLANK');
 $t->is((string) $menu['Root 3'], '<ul id="root-3-menu"><li 
id="test-menu-with-route" class="first last"><a target="_BLANK" 
href="http://www.google.com";>With Route</a></li></ul>', 'Test __toString() with 
a target option');
 
+$t->is($menu['Root 3']->hasChildren(), true, 'Test hasChildren() on Root 3');
+
 $menu['Root 3']['With Route']->requiresAuth(true);
 $t->is((string) $menu['Root 3'], '', 'Test requiresAuth()');
+$t->is($menu['Root 3']->hasChildren(), false, 'Test hasChildren() on Root 3 
when user has no access to With Route');
+
 $user = sfContext::getInstance()->getUser();
 $user->setAuthenticated(true);
 $t->is($user->isAuthenticated(), true, 'Test isAuthenticated()');

-- 
You received this message because you are subscribed to the Google Groups 
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/symfony-svn?hl=en.

Reply via email to