Index: menu_example.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/examples/menu_example/menu_example.module,v
retrieving revision 1.2
diff -u -r1.2 menu_example.module
--- menu_example/menu_example.module	29 May 2010 00:35:49 -0000	1.2
+++ menu_example/menu_example.module	13 Oct 2010 20:44:56 -0000
@@ -374,7 +374,9 @@
  *   menu_router table.
  */
 function menu_example_menu_alter(&$items) {
-  // Change the path 'user/logout' to a Spanish 'user/salir''.
+  // Change the path 'user/logout' to a Spanish 'user/salir'. This change will
+  // prevent the menu "Log out" link to show up. You should go to user/salir
+  // manually to log out the site.
   if (!empty($items['user/logout'])) {
     $items['user/salir'] = $items['user/logout'];
     unset($items['user/logout']);
@@ -382,8 +384,8 @@
 
   // Here we will change the title callback to our own function, changing the
   // 'user' link from the traditional to always being "username's account".
-  if (!empty($items['user/%user_uid_only_optional'])) {
-    $items['user/%user_uid_only_optional']['title callback'] = 'menu_example_user_page_title';
+  if (!empty($items['user/%user'])) {
+    $items['user/%user']['title callback'] = 'menu_example_user_page_title';
   }
 }
 
@@ -404,13 +406,7 @@
  * @param $account
  *   User account related to the visited page.
  */
-function menu_example_user_page_title($uid) {
-  if ($GLOBALS['user']->uid == $uid) {
-    $account = $GLOBALS['user'];
-  }
-  else {
-    $account = user_load($uid);
-  }
+function menu_example_user_page_title($account) {
   return is_object($account) ? t("@name's account", array('@name' => format_username($account))) : '';
 }
 
Index: menu_example.test
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/examples/menu_example/menu_example.test,v
retrieving revision 1.2
diff -u -r1.2 menu_example.test
--- menu_example/menu_example.test	29 May 2010 00:35:49 -0000	1.2
+++ menu_example/menu_example.test	13 Oct 2010 20:52:34 -0000
@@ -66,12 +66,18 @@
     $this->clickLink(t('Processed Placeholder Arguments'));
     $this->assertText(t('Loaded value was jackpot! default'));
 
-
     // Create a user with permissions to access protected menu entry.
     $web_user = $this->drupalCreateUser(array('access protected menu example'));
+
+    // User custom overridden drupalLogin function to verify the user is logged
+    // in.
     $this->drupalLogin($web_user);
+
     // Check that our title callback changing /user dynamically is working.
-    $this->assertRaw(t("@name&#039;s account", array('@name' => $web_user->name)));
+    // Using &#039; because of the format_username function.
+    $this->assertRaw(t("@name&#039;s account", array('@name' => format_username($web_user))), t('Title successfully changed to account name: %name.', array('%name' => $web_user->name)));
+
+    // Now start testing other menu entries.
     $this->drupalGet('menu_example');
 
     $this->clickLink(t('Permissioned Example'));
@@ -79,9 +85,65 @@
     $this->assertResponse(200);
     $this->assertText('This menu entry will not show');
 
-    // Verify that the 'logout' link has been changed to 'salir'.
+    // Verify that the 'logout' link has been changed to 'salir', using an 
+    // overridden drupalLogout function.
+    $this->drupalLogout();
+  }
+
+  /**
+   * Log in a user with the internal browser.
+   *
+   * This function overrides default drupalLogin function because the changes
+   * made by this module to the menu entries will make default drupalLogin fail.
+   *
+   * @param $user
+   *   User object representing the user to log in.
+   *
+   * @see drupalCreateUser()
+   */
+  protected function drupalLogin(stdClass $user) {
+    if ($this->loggedInUser) {
+      $this->drupalLogout();
+    }
+
+    $edit = array(
+      'name' => $user->name,
+      'pass' => $user->pass_raw
+    );
+    $this->drupalPost('user', $edit, t('Log in'));
+
+    // menu_example prevents "log out" link from appearing on the page, so the
+    // login function must check other link to verify user has logged in
+    // successfully.
+    $pass = $this->assertLink(t('My account'), 0, t('User %name successfully logged in.', array('%name' => $user->name)), t('User login'));
+
+    if ($pass) {
+      $this->loggedInUser = $user;
+    }
+  }
+
+  /*
+   * Logs a user out of the internal browser, then check the login page to
+   * confirm logout.
+   *
+   * This function overrides default drupalLogout function because the changes
+   * made by this module to the menu entries will make default drupalLogout fail.
+   *
+   * When menu_example module is enabled, logout menu entry is user/salir
+   *
+   */
+  protected function drupalLogout() {
+    // Make a request to the logout page, and redirect to the user page, the
+    // idea being if you were properly logged out you should be seeing a login
+    // screen.
     $this->drupalGet('user/salir');
     $this->drupalGet('user');
-    $this->clickLink(t('Create new account'));
+    $pass = $this->assertField('name', t('Username field found.'), t('Logout'));
+    $pass = $pass && $this->assertField('pass', t('Password field found.'), t('Logout'));
+
+    if ($pass) {
+      $this->loggedInUser = FALSE;
+    }
   }
+
 }

