Index: tests/jump.test
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/jump/tests/jump.test
diff -N tests/jump.test
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/jump.test	22 Sep 2009 00:05:33 -0000
@@ -0,0 +1,288 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Simpletest integration for the Jump module.
+ */
+
+/**
+ * Test basic Jump functionality.
+ */
+class JumpTestCase extends DrupalWebTestCase {
+  public static function getInfo() {
+    return array(
+     'name' => t('Jump functionality'),
+     'description' => t('Test Jump module functionality.'),
+     'group' => t('Jump'),
+    );
+  }
+
+  public function tearDown() {
+    parent::tearDown();
+  }
+
+  public function setUp() {
+    parent::setUp('jump', 'path', 'taxonomy');
+
+    // Create a user to perform tests.
+    $this->web_user = $this->drupalCreateUser(array (
+      'administer blocks',
+      'administer menu',
+      'access content',
+      'administer nodes',
+      'create story content',
+      'administer taxonomy',
+      'create url aliases'
+    ));
+    $this->drupalLogin($this->web_user);
+
+    // Add a menu for jumping.
+    $this->menu_name = drupal_strtolower($this->randomName(8));
+    $this->menu_name = preg_replace('/simpletest_|[^a-z]/', '', $this->menu_name);
+    $title = $this->randomName(8);
+    $edit = array(
+      'menu_name' => $this->menu_name,
+      'title' => $title,
+      'description' => $this->randomName(8),
+    );
+    $this->drupalPost('admin/build/menu/add', $edit, 'Save');
+    $this->assertRaw($title, "New menu page title.");
+
+    // Enable the jump menu block.
+    $this->drupalGet('admin/build/block');
+    $this->assertText('Jump menu: menu-'. $this->menu_name, 
+      t('Jump menu: menu-'. $this->menu_name .' exists.'));
+
+    // This assumes that the theme being used has a right section.
+    $edit = array(
+      'jump_menu-menu-'. $this->menu_name .'[region]' => 'right',
+    );
+    $this->drupalPost('admin/build/block', $edit, 'Save blocks');
+  }
+
+  /**
+   * Test to make sure basic Jump menu functionality works for nodes.
+   */
+  public function testJumpNode() {
+    // Add a node.
+    $settings = array('type' => 'story');
+    $node = $this->drupalCreateNode($settings);
+
+    // Add the node to the menu.
+    $edit = array(
+      'menu[link_path]' => 'node/'. $node->nid,
+      'menu[link_title]' => $node->title,
+    );
+    $this->drupalPost(
+      '/admin/build/menu-customize/menu-'. $this->menu_name .'/add',
+      $edit, 'Save'
+    );
+    $this->assertRaw($node->title, 'Test story added to menu');
+
+    // Jump to it.
+    $jump_edit = array(
+      'jump_goto' => $edit['menu[link_path]'],
+    );
+    $this->drupalPost('', $jump_edit, 'Go');
+    //$this->outputScreenContents('Test jump click.', 'testJumpNode');
+
+    // Verify jump.
+    $this->assertText($node->body, t('Verified basic jump.'));
+    $this->assertPattern('/class="jump-quickly".*<select.*<option value="node\/'. $node->nid .'" selected="selected"/s', t('Verified that the node we jumped to is selected in the jump form.'));
+  }
+
+  /**
+   * Test to make sure that a jump without jump_activepageinmenu does not
+   * include the active page as selected in the jump menu.
+   */
+  public function testJumpNotActivePageInMenu() {
+    // Unset jump_activepageinmenu.
+    variable_set('jump_activepageinmenu', 0);
+
+    // Add a node.
+    $settings = array('type' => 'story');
+    $node = $this->drupalCreateNode($settings);
+
+    // Add the node to the menu.
+    $edit = array(
+      'menu[link_path]' => 'node/'. $node->nid,
+      'menu[link_title]' => $node->title,
+    );
+    $this->drupalPost(
+      '/admin/build/menu-customize/menu-'. $this->menu_name .'/add',
+      $edit, 'Save'
+    );
+    $this->assertRaw($node->title, 'Test story added to menu');
+
+    // Jump to it.
+    $jump_edit = array(
+      'jump_goto' => $edit['menu[link_path]'],
+    );
+    $this->drupalPost('', $jump_edit, 'Go');
+
+    // Verify jump.
+    $this->assertText($node->body, t('Verified basic jump.'));
+
+    // This should match all of the jump_got select lists on a page.  We want
+    // to check that none of them are "selected".
+    $re = '/<select[^>]*name="jump_goto"[^>]*>(?:<option[^>]*>[^<]*<\/option>)*<\/select>/s';
+    preg_match($re, $this->drupalGetContent(), $matches);
+    $fail = 0;
+    foreach ($matches as $select) {
+      if (preg_match('/selected="selected"/',$select)) {
+        $fail=1;
+        break;
+      }
+    }
+    $this->assertTrue(!$fail, t('A jump option is not selected when jump_activepageinmenu is enabled.'));
+
+    // Unset jump_activepageinmenu.
+    variable_set('jump_activepageinmenu', 1);
+  }
+
+  /**
+   * Test to make sure basic Jump menu functionality works for taxonomy terms.
+   */
+  public function testJumpTaxonomyTerm() {
+    // Add a vocbulary.
+    $vName = $this->randomName(8);
+    $edit = array(
+      'name' => $vName
+    );
+    $this->drupalPost(
+      'admin/content/taxonomy/add/vocabulary',
+      $edit, 'Save'
+    );
+    $vocabularies = taxonomy_get_vocabularies();
+    $vocabulary = new stdClass();
+    foreach ($vocabularies as $vocabulary) {
+      if ($vocabulary->name == $vName) {
+        break;
+      }
+    }
+    if (empty($vocabulary->vid)) {
+      $this->fail('Unable to verify the creation of a vocabulary for testing jump by taxonomy term.');
+      return;
+    }
+
+    // Add a term.
+    $tName = $this->randomName(8);
+    $edit = array(
+      'name' => $tName
+    );
+    $this->drupalPost(
+      'admin/content/taxonomy/'. $vocabulary->vid .'/add/term',
+      $edit, 'Save'
+    );
+    $terms = taxonomy_get_term_by_name($tName);
+    $term = new stdClass();
+    foreach ($terms as $term) {
+      if ($term->name == $tName) {
+        break;
+      }
+    }
+    if (empty($term->tid)) {
+      $this->fail('Unable to verify the creation of a vocabulary term for testing jump by taxonomy term: ', print_r($term) .'.');
+      return;
+    }
+
+    // Add the term to the menu.
+    $edit = array(
+      'menu[link_path]' => 'taxonomy/term/'. $term->tid,
+      'menu[link_title]' => $tName,
+    );
+    $this->drupalPost(
+      'admin/build/menu-customize/menu-'. $this->menu_name .'/add',
+      $edit, 'Save'
+    );
+    $this->assertRaw($term->name, 'Taxonomy term added to menu');
+
+    // Jump to the term.
+    $jump_edit = array(
+      'jump_goto' => $edit['menu[link_path]'],
+    );
+    $this->drupalPost('', $jump_edit, 'Go');
+
+    // Verify jump.
+    $this->assertText('There are currently no posts in this category.', 
+      t('Verified taxonomy term jump.'));
+    $this->assertPattern('/class="jump-quickly".*<select.*<option value="taxonomy\/term\/'. $term->tid .'" selected="selected"/s', 
+      t('Verified that the taxonomy term we jumped to is selected in the jump form.'));
+  }
+
+  public function testJumpNodePathAuto() {
+    // Add a node with a path.
+    $path = $this->randomName(8) .'/'. $this->randomName(8);
+    $settings = array(
+      'type' => 'story',
+      'path' => $path
+    );
+    $node = $this->drupalCreateNode($settings);
+
+    // Add the node to the menu with the node/<nid> path first.
+    $edit = array(
+      'menu[link_path]' => 'node/'. $node->nid,
+      'menu[link_title]' => $node->title,
+    );
+    $this->drupalPost(
+      '/admin/build/menu-customize/menu-'. $this->menu_name .'/add',
+      $edit, 'Save'
+    );
+    $this->assertRaw($node->title, 'Test story added to menu');
+
+    // Jump to it.
+    $jump_edit = array(
+      'jump_goto' => $edit['menu[link_path]'],
+    );
+    $this->drupalPost('', $jump_edit, 'Go');
+
+    // Verify jump.
+    $this->assertText($node->body, t('Verified basic jump.'));
+    $this->assertPattern('/class="jump-quickly".*<select.*<option value="node\/'. $node->nid .'" selected="selected"/s', t('Verified that the node we jumped to is selected in the jump form.'));
+
+    // Add a node with a path.
+    $path = $this->randomName(8) .'/'. $this->randomName(8);
+    $settings = array(
+      'type' => 'story',
+      'path' => $path
+    );
+    $node = $this->drupalCreateNode($settings);
+
+    // Add the node to the menu with the node/<nid> path.
+    $edit = array(
+      'menu[link_path]' => $path,
+      'menu[link_title]' => $node->title,
+    );
+    $this->drupalPost(
+      '/admin/build/menu-customize/menu-'. $this->menu_name .'/add',
+      $edit, 'Save'
+    );
+    $this->assertRaw($node->title, 'Test story added to menu');
+
+    // Jump to it. Even though we add the custom $path instead of the 
+    // node/<nid> path, drupal will output the select options with the
+    // node/<nid> value.  We don't care so long as we can jump to it.
+    $jump_edit = array(
+      //'jump_goto' => $edit['menu[link_path]'],
+      'jump_goto' => 'node/'. $node->nid
+    );
+    $this->drupalPost('', $jump_edit, 'Go');
+    //$this->outputScreenContents('Clicked on Auto Path.', 'testJumpNodePathAuto');
+
+    // Verify jump.
+    $this->assertText($node->body, t('Verified basic jump.'));
+    $this->assertPattern('/class="jump-quickly".*<select.*<option value="node\/'. $node->nid .'" selected="selected"/s', t('Verified that the node we jumped to is selected in the jump form.'));
+  }
+
+  private function outputScreenContents($description, $basename) {
+    // This is a hack to get a directory that won't be cleaned up by simpletest
+    $file_dir = file_directory_path().'/../simpletest_output_pages';
+    if (!is_dir($file_dir)) {
+      mkdir($file_dir, 0777, TRUE);
+    }
+    $output_path = "$file_dir/$basename." . $this->randomName(10) . '.html';
+    $rv = file_put_contents($output_path, $this->drupalGetContent());
+    $this->pass("$description: Contents of result page are ".l('here',$output_path));
+  }
+}
Index: jump.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/jump/jump.module,v
retrieving revision 1.1.4.2
diff -u -p -r1.1.4.2 jump.module
--- jump.module	11 Sep 2009 18:22:48 -0000	1.1.4.2
+++ jump.module	22 Sep 2009 00:05:48 -0000
@@ -8,6 +8,39 @@
  */
 
 /**
+ * Implementation of hook_menu().
+ */
+function jump_menu() {
+  $items = array();
+
+  $items['admin/settings/jump'] = array(
+    'title' => 'Jump Settings',
+    'description' => 'Configure Jump module settings.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('jump_settings'),
+    'access callback' => 'user_access',
+    'access arguments' => array('administer menu'),
+  );
+
+  return $items;
+}
+
+/**
+ * Menu callback for 'admin/settings/jump'.
+ */
+function jump_settings() {
+
+  $form['jump_activepageinmenu'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Show active page in menu.'),
+    '#default_value' => variable_get('jump_activepageinmenu', 1),
+    '#description' => t('This setting will force the jump menu to show the current page as the default selection in the jump menu when checked.  If you have a menu option that you would always like displayed at the top of the menu, like "Select a menu item", you will want to uncheck this.'),
+  );
+
+  return system_settings_form($form);
+}
+
+/**
  * Implementation of hook_block().
  */
 function jump_block($op = 'list', $delta = 0, $edit = array()) {
@@ -76,13 +109,35 @@ function jump_quickly($name = 'navigatio
 }
 
 function jump_quickly_form(&$form_state, $options) {
+  // If the system is configured to show the active page in the menu then
+  // loop through the options to see if they are in the path.  If they are
+  // we have found the default selection for the form.  This sollution is
+  // common between the menu system and taxonomy;
+  $default = '';
+  if (variable_get('jump_activepageinmenu', 1)) {
+    foreach ($options as $path => $name) {
+      $ct = 0;
+      $default = $path;
+      foreach (explode('/', $path) as $index) {
+        if (strcmp($index, arg($ct))) {
+          $default = '';
+          break;
+        }
+        $ct++;
+      }
+      if (!empty($default)) {
+        break;
+      }
+    }
+  }
+
   $form = array();
   $form['#submit'][] = 'jump_quickly_form_submit';
   $form['#theme'] = 'jump_quickly_form';
   $form['#attributes']['class'] = 'jump-quickly';
   $form['jump_goto'] = array(
     '#type' => 'select',
-    '#default_value' => '0',
+    '#default_value' => $default,
     '#options' => $options
   );
   $form['submit'] = array(
