Index: tests/jump.test
===================================================================
RCS file: tests/jump.test
diff -N tests/jump.test
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/jump.test	18 Sep 2009 03:42:23 -0000
@@ -0,0 +1,239 @@
+<?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 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	18 Sep 2009 03:42:30 -0000
@@ -76,13 +76,31 @@ function jump_quickly($name = 'navigatio
 }
 
 function jump_quickly_form(&$form_state, $options) {
+  // 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;
+  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(
