function testGetPostNav()
 {
     global $wp_query;
     $dbi = $this->getMock('ComicPressDBInterface', array('get_previous_post', 'get_next_post', 'get_first_post', 'get_last_post'));
     $storyline = new ComicPressStoryline();
     $storyline->set_flattened_storyline('0/1,0/1/2,0/3');
     wp_insert_post(array('ID' => 1));
     $post = get_post(1);
     wp_set_post_categories(1, array(2));
     $dbi->expects($this->at(0))->method('get_previous_post')->with(array(1, 2, 3), $post);
     $dbi->expects($this->at(1))->method('get_next_post')->with(array(1, 2, 3), $post);
     $dbi->expects($this->at(2))->method('get_first_post')->with(array(1, 2, 3));
     $dbi->expects($this->at(3))->method('get_last_post')->with(array(1, 2, 3));
     $dbi->expects($this->at(4))->method('get_previous_post')->with(2, $post);
     $dbi->expects($this->at(5))->method('get_next_post')->with(2, $post);
     // level
     $dbi->expects($this->at(6))->method('get_first_post')->with(2)->will($this->returnValue((object) array('ID' => 1)));
     // parent
     $dbi->expects($this->at(7))->method('get_first_post')->with(1)->will($this->returnValue((object) array('ID' => 1)));
     // previous
     $dbi->expects($this->at(8))->method('get_first_post')->with(1)->will($this->returnValue((object) array('ID' => 1)));
     // next
     $dbi->expects($this->at(9))->method('get_first_post')->with(3)->will($this->returnValue((object) array('ID' => 1)));
     $this->nav->_dbi = $dbi;
     $this->nav->_storyline = $storyline;
     $this->assertFalse(wp_cache_get('navigation-1', 'comicpress'));
     $wp_query = (object) array('is_single' => true, 'in_the_loop' => true);
     $this->nav->get_post_nav($post);
     $this->assertTrue(wp_cache_get('navigation-1', 'comicpress') !== false);
 }
Ejemplo n.º 2
0
function __comicpress_init()
{
    global $comicpress_options, $__comicpress_handlable_classes;
    $comicpress_options = array();
    // Check if the $comicpress_options exist, if not set defaults
    $comicpress_options = comicpress_load_options();
    // xili-language plugin check
    if (class_exists('xili_language')) {
        define('THEME_TEXTDOMAIN', 'comicpress');
        define('THEME_LANGS_FOLDER', '/lang');
    } else {
        load_theme_textdomain('comicpress', get_template_directory() . '/lang');
    }
    // Queue up the scripts.
    if (!is_admin() && $comicpress_options['enable_scroll_to_top']) {
        wp_enqueue_script('comicpress_scroll', get_template_directory_uri() . '/js/scroll.js');
    }
    // remove intense debates control over the comment numbers
    if (function_exists('id_get_comment_number')) {
        remove_filter('comments_number', 'id_get_comment_number');
    }
    $storyline = get_option('comicpress-storyline-category-order');
    $do_rebuild = false;
    if (empty($storyline)) {
        $do_rebuild = true;
    } else {
        $first = array_pop(explode('/', array_shift(explode(',', $storyline))));
        if ($first != $comicpress_options['comicpress_config']['comiccat']) {
            $do_rebuild = true;
        }
    }
    if ($do_rebuild) {
        $storyline = new ComicPressStoryline();
        update_option('comicpress-storyline-category-order', $storyline->get_category_flattened($comicpress_options['comicpress_config']['comiccat']));
    }
    do_action('comicpress_init');
    if ($verified_nonce = __comicpress_verify_nonce()) {
        do_action("comicpress_init-{$verified_nonce}");
    }
}
 /**
  * @dataProvider providerTestCategoryTraversal
  */
 function testCategoryTraversal($methods, $expected_result, $compare_ids = false)
 {
     global $post;
     $storyline = new ComicPressStoryline();
     $storyline->set_flattened_storyline('0/1,0/2,0/2/3,0/2/4,0/5');
     foreach (array(1 => array('cat_name' => 'Test 1', 'category_nicename' => 'category-1', 'category_parent' => 0), 2 => array('cat_name' => 'Test 2', 'category_nicename' => 'category-2', 'category_parent' => 0), 3 => array('cat_name' => 'Test 3', 'category_nicename' => 'category-3', 'category_parent' => 2), 4 => array('cat_name' => 'Test 4', 'category_nicename' => 'category-4', 'category_parent' => 2), 5 => array('cat_name' => 'Test 5', 'category_nicename' => 'category-5', 'category_parent' => 0)) as $id => $category) {
         add_category($id, (object) $category);
     }
     $post = (object) array('ID' => 1);
     $dbi = $this->getMock('ComicPressDBInterface');
     $core = new ComicPressTagBuilderFactory($dbi);
     wp_insert_post($post);
     wp_insert_post((object) array('ID' => 2));
     wp_set_post_categories(1, array(2));
     wp_set_post_categories(2, array(3));
     foreach ($methods as $method_info) {
         $method = array_shift($method_info);
         $core = call_user_func_array(array($core, $method), $method_info);
     }
     if (is_object($core)) {
         $this->assertEquals($expected_result, $core->cat_ID);
     } else {
         if (is_array($core) && $compare_ids) {
             foreach ($expected_result as $id) {
                 $cat = array_shift($core);
                 $this->assertEquals($id, $cat->cat_ID);
             }
         } else {
             $this->assertEquals($expected_result, $core);
         }
     }
 }