Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LMP bug fix for #499 #636

Merged
merged 3 commits into from
Apr 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions inc/ajax-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@ function largo_load_more_posts() {
if ( of_get_option('num_posts_home') && $is_home )
$args['posts_per_page'] = of_get_option('num_posts_home');
// The first 'page' of the homepage is in $shown_ids, so this number should actually be minus one.
if ( $is_home )
if ( $is_home ) {
$args['paged'] = ( $args['paged'] - 1 );
if ( of_get_option('cats_home') )
$args['cat'] = of_get_option('cats_home');
if ( of_get_option('cats_home') )
$args['cat'] = of_get_option('cats_home');
}
$query = new WP_Query($args);

if ( $query->have_posts() ) {
Expand Down
39 changes: 39 additions & 0 deletions tests/inc/test-ajax-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function setUp() {
// Test data
$this->post_count = 10;
$this->post_ids = $this->factory->post->create_many($this->post_count);
of_reset_options();
}

function test_largo_load_more_posts() {
Expand All @@ -60,6 +61,44 @@ function test_largo_load_more_posts() {
}
}

/*
* Make sure `largo_load_more_posts` works when `cats_home` option is set.
*
* Regression test for issue: http://github.com/inn/largo/issues/499
*/
function test_largo_load_more_posts_cats_home_option() {
$this->markTestSkipped('Unable to read the ajax return, even when it is filled with dumb <h1>foo</h1> tags that do not depend upon categories or posts or queries.');

global $wp_action;
$preserve = $wp_action;
$wp_action = array();

$category = $this->factory->category->create();
of_set_option('cats_home', (string) $category);
$posts = $this->factory->post->create_many(10, array(
'post_category' => $category
));

$_POST['paged'] = 0;
$_POST['query'] = array();

try {
$this->_handleAjax("load_more_posts");
} catch (WPAjaxDieStopException $e) {
foreach ($this->post_ids as $number) {
$pos = strpos($this->_last_response, 'post-' . $number);
$this->assertTrue((bool) $pos);
}
} catch (WPAjaxDieContinueException $e) {
foreach ($this->post_ids as $number) {
$pos = strpos($this->_last_response, 'post-' . $number);
$this->assertTrue((bool) $pos);
}
}

$wp_action = $preserve;
}

function test_largo_load_more_posts_empty_query() {
$_POST['paged'] = 0;

Expand Down
7 changes: 6 additions & 1 deletion tests/inc/test-post-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ function test_largo_post_social_links() {
$this->go_to('/?p=' . $id);

// Test the output of this when no options are set
$this->assertFalse(of_get_option('article_utilities'));
of_set_option('article_utilities', array(
'facebook' => false,
'twitter' => false,
'print' => false,
'email' => false
));

ob_start();
largo_post_social_links();
Expand Down
1 change: 1 addition & 0 deletions tests/mock/mock-options-framework.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function set_option($name, $value=null) {

public function reset_options() {
$this->options = array();
$this->populate_defaults();
}
}

Expand Down