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 @@ + 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".* '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 = '/]*name="jump_goto"[^>]*>(?:]*>[^<]*<\/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".*randomName(8) .'/'. $this->randomName(8); + $settings = array( + 'type' => 'story', + 'path' => $path + ); + $node = $this->drupalCreateNode($settings); + + // Add the node to the menu with the node/ 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".*randomName(8) .'/'. $this->randomName(8); + $settings = array( + 'type' => 'story', + 'path' => $path + ); + $node = $this->drupalCreateNode($settings); + + // Add the node to the menu with the node/ 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/ path, drupal will output the select options with the + // node/ 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".*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(