Esempio n. 1
0
 /**
  * Covers bu_navigation_list_pages()
  */
 public function test_bu_navigation_list_pages()
 {
     $parent = $this->posts['parent'];
     $child = $this->posts['child'];
     $parent_two = $this->posts['parent_two'];
     $hidden = $this->posts['hidden'];
     $edit = $this->posts['edit'];
     $google = $this->posts['google'];
     $last_page = $this->posts['last_page'];
     $grandchild_one = $this->posts['grandchild_one'];
     $grandchild_two = $this->posts['grandchild_two'];
     $greatgrandchild = $this->posts['greatgrandchild'];
     $test = $this->posts['test'];
     $test_child = $this->posts['test_child'];
     $test_grandchild = $this->posts['test_grandchild'];
     $list_pages_expected = "<ul >\n" . '<li class="page_item page-item-' . $parent . ' first_item">' . "\n" . '<a title="Parent Page" class="level_1" href="' . get_permalink($parent) . '">Parent Page</a>' . "\n \n" . "<ul>\n" . '<li class="page_item page-item-' . $child . '">' . "\n" . '<a title="Child Page" class="level_2" href="' . get_permalink($child) . '">Child Page</a>' . "\n \n" . "<ul>\n" . '<li class="page_item page-item-' . $grandchild_one . '">' . "\n" . '<a title="Grand Child Page 1" class="level_3" href="' . get_permalink($grandchild_one) . '">Grand Child Page 1</a>' . "\n \n" . "<ul>\n" . '<li class="page_item page-item-' . $greatgrandchild . '">' . "\n" . '<a title="Great Grand Child" class="level_4" href="' . get_permalink($greatgrandchild) . '">Great Grand Child</a>' . "\n" . " </li>\n\n" . "</ul>\n" . "</li>\n" . '<li class="page_item page-item-' . $grandchild_two . '">' . "\n" . '<a title="Grand Child Page 2" class="level_3" href="' . get_permalink($grandchild_two) . '">Grand Child Page 2</a>' . "\n" . " </li>\n\n" . "</ul>\n" . "</li>\n\n" . "</ul>\n" . "</li>\n" . '<li class="page_item page-item-' . $parent_two . '">' . "\n" . '<a title="Parent Page Two" class="level_1" href="' . get_permalink($parent_two) . '">Parent Page Two</a>' . "\n" . " </li>\n" . '<li class="page_item page-item-' . $edit . '">' . "\n" . '<a title="Edit and Delete Me" class="level_1" href="' . get_permalink($edit) . '">Edit and Delete Me</a>' . "\n" . " </li>\n" . '<li class="page_item page-item-' . $google . '">' . "\n" . '<a title="Google" class="level_1" href="' . get_permalink($google) . '" target="_blank">Google</a>' . "\n" . " </li>\n" . '<li class="page_item page-item-' . $last_page . ' last_item">' . "\n" . '<a title="Last Page" class="level_1" href="' . get_permalink($last_page) . '">Last Page</a>' . "\n" . " </li>\n" . "</ul>\n";
     $list_pages_results = bu_navigation_list_pages();
     $this->assertEquals($list_pages_expected, $list_pages_results);
     /**
      * 	Test Page ID Function
      */
     $list_pages_page_id_expected = "<ul >\n" . '<li class="page_item page-item-' . $parent . ' has_children first_item">' . "\n" . '<a title="Parent Page" class="level_1" href="' . get_permalink($parent) . '">Parent Page</a>' . "\n \n" . "<ul>\n" . '<li class="page_item page-item-' . $child . ' has_children">' . "\n" . '<a title="Child Page" class="level_2" href="' . get_permalink($child) . '">Child Page</a>' . "\n" . " </li>\n\n" . "</ul>\n" . "</li>\n" . '<li class="page_item page-item-' . $parent_two . '">' . "\n" . '<a title="Parent Page Two" class="level_1" href="' . get_permalink($parent_two) . '">Parent Page Two</a>' . "\n" . " </li>\n" . '<li class="page_item page-item-' . $edit . '">' . "\n" . '<a title="Edit and Delete Me" class="level_1" href="' . get_permalink($edit) . '">Edit and Delete Me</a>' . "\n" . " </li>\n" . '<li class="page_item page-item-' . $google . '">' . "\n" . '<a title="Google" class="level_1" href="' . get_permalink($google) . '" target="_blank">Google</a>' . "\n" . " </li>\n" . '<li class="page_item page-item-' . $last_page . ' last_item">' . "\n" . '<a title="Last Page" class="level_1" href="' . get_permalink($last_page) . '">Last Page</a>' . "\n" . " </li>\n" . "</ul>\n";
     $args = array('page_id' => $parent);
     $list_pages_page_id_results = bu_navigation_list_pages($args);
     $this->assertEquals($list_pages_page_id_expected, $list_pages_page_id_results);
     /**
      * 	Test Echo Function
      */
     ob_start();
     $args = array('echo' => 1);
     bu_navigation_list_pages($args);
     $list_pages_echo_results = ob_get_contents();
     ob_end_clean();
     $this->assertEquals($list_pages_expected, $list_pages_echo_results);
     /**
      * 	Test Navigate in Section Function
      */
     $list_pages_navigate_in_section_expected = "<ul >\n" . '<li class="page_item page-item-' . $child . ' first_item last_item">' . "\n" . '<a title="Child Page" class="level_1" href="' . get_permalink($child) . '">Child Page</a>' . "\n \n" . "<ul>\n" . '<li class="page_item page-item-' . $grandchild_one . '">' . "\n" . '<a title="Grand Child Page 1" class="level_2" href="' . get_permalink($grandchild_one) . '">Grand Child Page 1</a>' . "\n \n" . "<ul>\n" . '<li class="page_item page-item-' . $greatgrandchild . '">' . "\n" . '<a title="Great Grand Child" class="level_3" href="' . get_permalink($greatgrandchild) . '">Great Grand Child</a>' . "\n" . " </li>\n\n" . "</ul>\n" . "</li>\n" . '<li class="page_item page-item-' . $grandchild_two . '">' . "\n" . '<a title="Grand Child Page 2" class="level_2" href="' . get_permalink($grandchild_two) . '">Grand Child Page 2</a>' . "\n" . " </li>\n\n" . "</ul>\n" . "</li>\n" . "</ul>\n";
     $args = array('navigate_in_section' => true);
     $list_pages_navigate_in_section_results = bu_navigation_list_pages($args);
     $this->assertEquals($list_pages_navigate_in_section_expected, $list_pages_navigate_in_section_results);
     /**
      * 	Test Container Tag Function
      */
     $list_pages_container_tag_expected = "<ol >\n" . '<li class="page_item page-item-' . $parent . ' first_item">' . "\n" . '<a title="Parent Page" class="level_1" href="' . get_permalink($parent) . '">Parent Page</a>' . "\n \n" . "<ol>\n" . '<li class="page_item page-item-' . $child . '">' . "\n" . '<a title="Child Page" class="level_2" href="' . get_permalink($child) . '">Child Page</a>' . "\n \n" . "<ol>\n" . '<li class="page_item page-item-' . $grandchild_one . '">' . "\n" . '<a title="Grand Child Page 1" class="level_3" href="' . get_permalink($grandchild_one) . '">Grand Child Page 1</a>' . "\n \n" . "<ol>\n" . '<li class="page_item page-item-' . $greatgrandchild . '">' . "\n" . '<a title="Great Grand Child" class="level_4" href="' . get_permalink($greatgrandchild) . '">Great Grand Child</a>' . "\n" . " </li>\n\n" . "</ol>\n" . "</li>\n" . '<li class="page_item page-item-' . $grandchild_two . '">' . "\n" . '<a title="Grand Child Page 2" class="level_3" href="' . get_permalink($grandchild_two) . '">Grand Child Page 2</a>' . "\n" . " </li>\n\n" . "</ol>\n" . "</li>\n\n" . "</ol>\n" . "</li>\n" . '<li class="page_item page-item-' . $parent_two . '">' . "\n" . '<a title="Parent Page Two" class="level_1" href="' . get_permalink($parent_two) . '">Parent Page Two</a>' . "\n" . " </li>\n" . '<li class="page_item page-item-' . $edit . '">' . "\n" . '<a title="Edit and Delete Me" class="level_1" href="' . get_permalink($edit) . '">Edit and Delete Me</a>' . "\n" . " </li>\n" . '<li class="page_item page-item-' . $google . '">' . "\n" . '<a title="Google" class="level_1" href="' . get_permalink($google) . '" target="_blank">Google</a>' . "\n" . " </li>\n" . '<li class="page_item page-item-' . $last_page . ' last_item">' . "\n" . '<a title="Last Page" class="level_1" href="' . get_permalink($last_page) . '">Last Page</a>' . "\n" . " </li>\n" . "</ol>\n";
     $args = array('container_tag' => 'ol');
     $list_pages_container_tag_results = bu_navigation_list_pages($args);
     $this->assertEquals($list_pages_container_tag_expected, $list_pages_container_tag_results);
     /**
      * 	Test Container ID Function
      */
     $list_pages_container_id_expected = '<ul  id="test_container_id">' . "\n" . '<li class="page_item page-item-' . $parent . ' first_item">' . "\n" . '<a title="Parent Page" class="level_1" href="' . get_permalink($parent) . '">Parent Page</a>' . "\n \n" . "<ul>\n" . '<li class="page_item page-item-' . $child . '">' . "\n" . '<a title="Child Page" class="level_2" href="' . get_permalink($child) . '">Child Page</a>' . "\n \n" . "<ul>\n" . '<li class="page_item page-item-' . $grandchild_one . '">' . "\n" . '<a title="Grand Child Page 1" class="level_3" href="' . get_permalink($grandchild_one) . '">Grand Child Page 1</a>' . "\n \n" . "<ul>\n" . '<li class="page_item page-item-' . $greatgrandchild . '">' . "\n" . '<a title="Great Grand Child" class="level_4" href="' . get_permalink($greatgrandchild) . '">Great Grand Child</a>' . "\n" . " </li>\n\n" . "</ul>\n" . "</li>\n" . '<li class="page_item page-item-' . $grandchild_two . '">' . "\n" . '<a title="Grand Child Page 2" class="level_3" href="' . get_permalink($grandchild_two) . '">Grand Child Page 2</a>' . "\n" . " </li>\n\n" . "</ul>\n" . "</li>\n\n" . "</ul>\n" . "</li>\n" . '<li class="page_item page-item-' . $parent_two . '">' . "\n" . '<a title="Parent Page Two" class="level_1" href="' . get_permalink($parent_two) . '">Parent Page Two</a>' . "\n" . " </li>\n" . '<li class="page_item page-item-' . $edit . '">' . "\n" . '<a title="Edit and Delete Me" class="level_1" href="' . get_permalink($edit) . '">Edit and Delete Me</a>' . "\n" . " </li>\n" . '<li class="page_item page-item-' . $google . '">' . "\n" . '<a title="Google" class="level_1" href="' . get_permalink($google) . '" target="_blank">Google</a>' . "\n" . " </li>\n" . '<li class="page_item page-item-' . $last_page . ' last_item">' . "\n" . '<a title="Last Page" class="level_1" href="' . get_permalink($last_page) . '">Last Page</a>' . "\n" . " </li>\n" . "</ul>\n";
     $args = array('container_id' => 'test_container_id');
     $list_pages_container_id_results = bu_navigation_list_pages($args);
     $this->assertEquals($list_pages_container_id_expected, $list_pages_container_id_results);
     /**
      * 	Test Container Class Function
      */
     $list_pages_container_class_expected = '<ul  class="test_container_class">' . "\n" . '<li class="page_item page-item-' . $parent . ' first_item">' . "\n" . '<a title="Parent Page" class="level_1" href="' . get_permalink($parent) . '">Parent Page</a>' . "\n \n" . "<ul>\n" . '<li class="page_item page-item-' . $child . '">' . "\n" . '<a title="Child Page" class="level_2" href="' . get_permalink($child) . '">Child Page</a>' . "\n \n" . "<ul>\n" . '<li class="page_item page-item-' . $grandchild_one . '">' . "\n" . '<a title="Grand Child Page 1" class="level_3" href="' . get_permalink($grandchild_one) . '">Grand Child Page 1</a>' . "\n \n" . "<ul>\n" . '<li class="page_item page-item-' . $greatgrandchild . '">' . "\n" . '<a title="Great Grand Child" class="level_4" href="' . get_permalink($greatgrandchild) . '">Great Grand Child</a>' . "\n" . " </li>\n\n" . "</ul>\n" . "</li>\n" . '<li class="page_item page-item-' . $grandchild_two . '">' . "\n" . '<a title="Grand Child Page 2" class="level_3" href="' . get_permalink($grandchild_two) . '">Grand Child Page 2</a>' . "\n" . " </li>\n\n" . "</ul>\n" . "</li>\n\n" . "</ul>\n" . "</li>\n" . '<li class="page_item page-item-' . $parent_two . '">' . "\n" . '<a title="Parent Page Two" class="level_1" href="' . get_permalink($parent_two) . '">Parent Page Two</a>' . "\n" . " </li>\n" . '<li class="page_item page-item-' . $edit . '">' . "\n" . '<a title="Edit and Delete Me" class="level_1" href="' . get_permalink($edit) . '">Edit and Delete Me</a>' . "\n" . " </li>\n" . '<li class="page_item page-item-' . $google . '">' . "\n" . '<a title="Google" class="level_1" href="' . get_permalink($google) . '" target="_blank">Google</a>' . "\n" . " </li>\n" . '<li class="page_item page-item-' . $last_page . ' last_item">' . "\n" . '<a title="Last Page" class="level_1" href="' . get_permalink($last_page) . '">Last Page</a>' . "\n" . " </li>\n" . "</ul>\n";
     $args = array('container_class' => 'test_container_class');
     $list_pages_container_class_results = bu_navigation_list_pages($args);
     $this->assertEquals($list_pages_container_class_expected, $list_pages_container_class_results);
     /**
      * 	Test Item Tag Function
      */
     $list_pages_item_tag_expected = "<ul >\n" . '<ll class="page_item page-item-' . $parent . ' first_item">' . "\n" . '<a title="Parent Page" class="level_1" href="' . get_permalink($parent) . '">Parent Page</a>' . "\n \n" . "<ul>\n" . '<ll class="page_item page-item-' . $child . '">' . "\n" . '<a title="Child Page" class="level_2" href="' . get_permalink($child) . '">Child Page</a>' . "\n \n" . "<ul>\n" . '<ll class="page_item page-item-' . $grandchild_one . '">' . "\n" . '<a title="Grand Child Page 1" class="level_3" href="' . get_permalink($grandchild_one) . '">Grand Child Page 1</a>' . "\n \n" . "<ul>\n" . '<ll class="page_item page-item-' . $greatgrandchild . '">' . "\n" . '<a title="Great Grand Child" class="level_4" href="' . get_permalink($greatgrandchild) . '">Great Grand Child</a>' . "\n" . " </ll>\n\n" . "</ul>\n" . "</ll>\n" . '<ll class="page_item page-item-' . $grandchild_two . '">' . "\n" . '<a title="Grand Child Page 2" class="level_3" href="' . get_permalink($grandchild_two) . '">Grand Child Page 2</a>' . "\n" . " </ll>\n\n" . "</ul>\n" . "</ll>\n\n" . "</ul>\n" . "</ll>\n" . '<ll class="page_item page-item-' . $parent_two . '">' . "\n" . '<a title="Parent Page Two" class="level_1" href="' . get_permalink($parent_two) . '">Parent Page Two</a>' . "\n" . " </ll>\n" . '<ll class="page_item page-item-' . $edit . '">' . "\n" . '<a title="Edit and Delete Me" class="level_1" href="' . get_permalink($edit) . '">Edit and Delete Me</a>' . "\n" . " </ll>\n" . '<ll class="page_item page-item-' . $google . '">' . "\n" . '<a title="Google" class="level_1" href="' . get_permalink($google) . '" target="_blank">Google</a>' . "\n" . " </ll>\n" . '<ll class="page_item page-item-' . $last_page . ' last_item">' . "\n" . '<a title="Last Page" class="level_1" href="' . get_permalink($last_page) . '">Last Page</a>' . "\n" . " </ll>\n" . "</ul>\n";
     $args = array('item_tag' => 'll');
     $list_pages_item_tag_results = bu_navigation_list_pages($args);
     $this->assertEquals($list_pages_item_tag_expected, $list_pages_item_tag_results);
     /**
      * 	Test Style (Adaptive) Function
      */
     $list_pages_style_expected = "<ul >\n" . '<li class="page_item page-item-' . $child . ' has_children first_item last_item">' . "\n" . '<a title="Child Page" class="level_1" href="' . get_permalink($child) . '">Child Page</a>' . "\n \n" . "<ul>\n" . '<li class="page_item page-item-' . $grandchild_one . ' has_children">' . "\n" . '<a title="Grand Child Page 1" class="level_2" href="' . get_permalink($grandchild_one) . '">Grand Child Page 1</a>' . "\n" . " </li>\n" . '<li class="page_item page-item-' . $grandchild_two . '">' . "\n" . '<a title="Grand Child Page 2" class="level_2" href="' . get_permalink($grandchild_two) . '">Grand Child Page 2</a>' . "\n" . " </li>\n\n" . "</ul>\n" . "</li>\n" . "</ul>\n";
     $args = array('page_id' => $child, 'style' => 'adaptive');
     $list_pages_style_results = bu_navigation_list_pages($args);
     $this->assertEquals($list_pages_style_expected, $list_pages_style_results);
     /**
      * 	Test Post Types Function
      */
     $list_pages_post_type_expected = "<ul >\n" . '<li class="page_item page-item-' . $test . ' first_item last_item">' . "\n" . '<a title="Test Type Page" class="level_1" href="' . get_permalink($test) . '">Test Type Page</a>' . "\n \n" . "<ul>\n" . '<li class="page_item page-item-' . $test_child . '">' . "\n" . '<a title="Test Child" class="level_2" href="' . get_permalink($test_child) . '">Test Child</a>' . "\n \n" . "<ul>\n" . '<li class="page_item page-item-' . $test_grandchild . '">' . "\n" . '<a title="Test Grandchild" class="level_3" href="' . get_permalink($test_grandchild) . '">Test Grandchild</a>' . "\n" . " </li>\n\n" . "</ul>\n" . "</li>\n\n" . "</ul>\n" . "</li>\n" . "</ul>\n";
     $args = array('post_types' => array('test'));
     $list_pages_post_type_results = bu_navigation_list_pages($args);
     $this->assertEquals($list_pages_post_type_expected, $list_pages_post_type_results);
 }
Esempio n. 2
0
 /**
  * Display the content navigation widget
  *
  * @param array $args widget args
  * @param array $instance widget instance args
  */
 public function widget($args, $instance)
 {
     global $post;
     // Only display navigation widget for supported post types
     if (!in_array($post->post_type, bu_navigation_supported_post_types())) {
         return;
     }
     extract($args);
     $title = '';
     // Set widget title
     if ($instance['navigation_title'] == 'static' && !empty($instance['navigation_title_text'])) {
         $title = apply_filters('widget_title', $instance['navigation_title_text']);
         // Wrap with anchor tag if URL is present
         if (!empty($instance['navigation_title_url'])) {
             $title = sprintf('<a class="content_nav_header" href="%s">%s</a>', $instance['navigation_title_url'], $title);
         }
     } else {
         if ($instance['navigation_title'] == 'section') {
             // Use navigation label of top level post for current section
             $title = $this->section_title($args, $instance);
         }
     }
     // Prepare arguments to bu_navigation_list_pages
     $list_args = array('page_id' => $post->ID, 'title_li' => '', 'echo' => 0, 'container_id' => BU_WIDGET_PAGES_LIST_ID, 'post_types' => $post->post_type);
     // Set list arguments based on navigation style
     if (array_key_exists('navigation_style', $instance)) {
         $list_args['style'] = $instance['navigation_style'];
         if ($instance['navigation_style'] == 'section') {
             $list_args['navigate_in_section'] = 1;
             if (is_404()) {
                 return '';
             }
         } else {
             if ($instance['navigation_style'] == 'adaptive') {
                 add_action('bu_navigation_widget_before_list', 'bu_navigation_widget_adaptive_before_list');
             }
         }
     } else {
         error_log("No nav label widget style set!");
     }
     do_action('bu_navigation_widget_before_list');
     // Fetch markup and display
     $out = bu_navigation_list_pages(apply_filters('widget_bu_pages_args', $list_args));
     if (!empty($out)) {
         printf('%s<div id="contentnav">', $before_widget);
         if ($title) {
             echo $before_title . $title . $after_title;
         }
         printf('%s</div>', $out);
         echo $after_widget;
     }
 }