function test_largo_load_more_posts_choose_partial() { $qv = (object) array('query_vars' => array()); // Note: These options are arrayed in the order that they are tested for in largo_load_more_posts_choose_partial($qv) // That is to say, later options *should* override earlier options. This is why $qv is not being unset($qv). $ret = largo_load_more_posts_choose_partial($qv); $this->assertEquals('home', $ret, 'empty query vars did not result in a determination that the partial type is home'); // Test it with everything that shouldn't affect the determination that this is home. $qv->query_vars['category_name'] = ''; $qv->query_vars['author_name'] = ''; $qv->query_vars['tag'] = ''; $qv->query_vars['s'] = ''; $qv->query_vars['year'] = ''; $_POST['is_series_landing'] = false; $qv->query_vars['series'] = ''; // @todo find way to test get_post_type() returning argolinks. $ret = largo_load_more_posts_choose_partial($qv); $this->assertEquals('home', $ret, 'empty query vars did not result in a determination that the partial type is home'); // category $qv->query_vars['category_name'] = 'foo'; $ret = largo_load_more_posts_choose_partial($qv); $this->assertEquals('archive', $ret, 'Testing category'); $this->assertFalse('home' == $ret, 'set query query vars did result in a determination that the partial type is home'); // Author archive page $qv->query_vars['author_name'] = 'admin'; $ret = largo_load_more_posts_choose_partial($qv); $this->assertEquals('archive', $ret, 'Testing author archive'); $this->assertFalse('home' == $ret, 'set query query vars did result in a determination that the partial type is home'); // tag $qv->query_vars['tag'] = 'tag'; $ret = largo_load_more_posts_choose_partial($qv); $this->assertEquals('archive', $ret, 'Testing tag'); $this->assertFalse('home' == $ret, 'set query query vars did result in a determination that the partial type is home'); // Search $qv->query_vars['s'] = 'search'; $ret = largo_load_more_posts_choose_partial($qv); $this->assertEquals('search', $ret, 'Testing search'); $this->assertFalse('home' == $ret, 'set query query vars did result in a determination that the partial type is home'); // Date archive $qv->query_vars['year'] = '2015'; $ret = largo_load_more_posts_choose_partial($qv); $this->assertEquals('archive', $ret, 'Testing date query with "year" => "2015"'); $this->assertFalse('home' == $ret, 'set query query vars did result in a determination that the partial type is home'); // series landing pages $_POST['is_series_landing'] = 'true'; $_POST['opt'] = 'foo'; $ret = largo_load_more_posts_choose_partial($qv); $this->assertEquals('series', $ret, ''); global $opt; $this->assertEquals($opt, $_POST['opt'], 'global $opt was not set to the value supplied in $_POST["opt"]'); $this->assertFalse('home' == $ret, 'set query query vars did result in a determination that the partial type is home'); // non-series-landing series archives $qv->query_vars['series'] = 'series'; $ret = largo_load_more_posts_choose_partial($qv); $this->assertEquals('archive', $ret, ''); $this->assertFalse('home' == $ret, 'set query query vars did result in a determination that the partial type is home'); // @todo find way to test get_post_type() returning argolinks. $this->assertFalse('home' == $ret, 'set query query vars did result in a determination that the partial type is home'); // Test the filter. }
/** * Renders markup for a page of posts and sends it back over the wire. * @global $opt * @global $_POST * @see largo_load_more_posts_choose_partial */ function largo_load_more_posts() { global $opt; $paged = isset($_POST['paged']) ? $_POST['paged'] : 1; $context = isset($_POST['query']) ? json_decode(stripslashes($_POST['query']), true) : array(); $args = array_merge(array('paged' => (int) $paged, 'post_status' => 'publish', 'posts_per_page' => intval(get_option('posts_per_page')), 'ignore_sticky_posts' => true), $context); // Making sure that this query isn't for the homepage if (isset($_POST['is_home'])) { $is_home = $_POST['is_home'] == 'false' ? false : true; } else { $is_home = true; } // num_posts_home is only relevant on the homepage if (of_get_option('num_posts_home') && $is_home) { $args['posts_per_page'] = of_get_option('num_posts_home'); } if ($is_home) { $args['paged'] = $args['paged'] - 1; if (of_get_option('cats_home')) { $args['cat'] = of_get_option('cats_home'); } } $args = apply_filters('largo_lmp_args', $args); $query = new WP_Query($args); if ($query->have_posts()) { // Choose the correct partial to load here $partial = largo_load_more_posts_choose_partial($query); // Render all the posts while ($query->have_posts()) { $query->the_post(); get_template_part('partials/content', $partial); } } wp_die(); }