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

Fix layout issue with Academia theme #2773

Merged
merged 4 commits into from
Oct 15, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,26 @@
*/
abstract class Sensei_Unsupported_Theme_Handler_Page_Imitator {
/**
* @var WP_Query The original query for the query.
* The original query for the query.
*
* @var WP_Query
*/
private $original_query;

/**
* @var WP_Post The original post for the query.
* The original post for the query.
*
* @var WP_Post
*/
private $original_post;

/**
* The dummy post to be rendered.
*
* @var WP_Post
*/
private $dummy_post;

/**
* Prepare the WP query object for the imitated request.
*
Expand Down Expand Up @@ -62,12 +73,15 @@ protected function output_content_as_page( $content, $object_to_copy = null, $po
$this->original_query = $wp_query;
$this->original_post = $post;

// Create the dummy post object.
$this->dummy_post = new WP_Post( (object) $dummy_post_properties );

/*
* Set up new global $post and set it on $wp_query. Set $wp_the_query
* as well so we can reset it back to this later.
*/
// phpcs:disable WordPress.WP.GlobalVariablesOverride.OverrideProhibited -- Used to mock our own page within a custom loop. Reset afterwards.
$post = new WP_Post( (object) $dummy_post_properties );
$post = $this->dummy_post;
$wp_query = clone $wp_query;
$wp_query->post = $post;
$wp_query->posts = array( $post );
Expand Down Expand Up @@ -110,8 +124,10 @@ protected function output_content_as_page( $content, $object_to_copy = null, $po
* @return array
*/
private function generate_dummy_post_args( $object_to_copy ) {
global $wpdb;

$default_args = array(
'ID' => 0,
'ID' => absint( $wpdb->get_var( "SELECT MAX( ID ) from {$wpdb->prefix}posts" ) ) + 1,
'post_status' => 'publish',
'post_author' => 0,
'post_parent' => 0,
Expand Down Expand Up @@ -231,7 +247,7 @@ public function do_sensei_pagination() {
* @return string|bool
*/
public function hide_dummy_post_title( $title, $id ) {
if ( 0 === $id ) {
if ( $this->dummy_post->ID === $id ) {
return '';
}
return $title;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ public function testShouldSetupDummyPost() {

$this->handler->handle_request();

$this->assertEquals( 0, $post->ID, 'The dummy post ID should be 0' );
$this->assertNotEquals( 0, $post->ID, 'The dummy post ID should be non-zero' );
$this->assertNull( get_post( $post->ID ), 'The dummy post ID should be unused' );
$this->assertEquals( 'page', $post->post_type, 'The dummy post type should be "page"' );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ public function testShouldSetupDummyPost() {

$this->handler->handle_request();

$this->assertEquals( 0, $post->ID, 'The dummy post ID should be 0' );
$this->assertNotEquals( 0, $post->ID, 'The dummy post ID should be non-zero' );
$this->assertNull( get_post( $post->ID ), 'The dummy post ID should be unused' );
$this->assertEquals( 'page', $post->post_type, 'The dummy post type should be "page"' );

$copied_from_course = array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ public function testShouldSetupDummyPost() {

$this->handler->handle_request();

$this->assertEquals( 0, $post->ID, 'The dummy post ID should be 0' );
$this->assertNotEquals( 0, $post->ID, 'The dummy post ID should be non-zero' );
$this->assertNull( get_post( $post->ID ), 'The dummy post ID should be unused' );
$this->assertEquals( 'page', $post->post_type, 'The dummy post type should be "page"' );

$copied_from_learner_user = array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ public function testShouldSetupDummyPost() {

$this->handler->handle_request();

$this->assertEquals( 0, $post->ID, 'The dummy post ID should be 0' );
$this->assertNotEquals( 0, $post->ID, 'The dummy post ID should be non-zero' );
$this->assertNull( get_post( $post->ID ), 'The dummy post ID should be unused' );
$this->assertEquals( 'page', $post->post_type, 'The dummy post type should be "page"' );

$copied_from_term = array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ public function testShouldSetupDummyPost() {

$this->handler->handle_request();

$this->assertEquals( 0, $post->ID, 'The dummy post ID should be 0' );
$this->assertNotEquals( 0, $post->ID, 'The dummy post ID should be non-zero' );
$this->assertNull( get_post( $post->ID ), 'The dummy post ID should be unused' );
$this->assertEquals( 'page', $post->post_type, 'The dummy post type should be "page"' );

$post_type = get_post_type_object( 'sensei_message' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ public function testShouldSetupDummyPost() {

$this->handler->handle_request();

$this->assertEquals( 0, $post->ID, 'The dummy post ID should be 0' );
$this->assertNotEquals( 0, $post->ID, 'The dummy post ID should be non-zero' );
$this->assertNull( get_post( $post->ID ), 'The dummy post ID should be unused' );
$this->assertEquals( 'page', $post->post_type, 'The dummy post type should be "page"' );

$copied_from_course = array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ public function testShouldSetupDummyPost() {

$this->handler->handle_request();

$this->assertEquals( 0, $post->ID, 'The dummy post ID should be 0' );
$this->assertNotEquals( 0, $post->ID, 'The dummy post ID should be non-zero' );
$this->assertNull( get_post( $post->ID ), 'The dummy post ID should be unused' );
$this->assertEquals( 'page', $post->post_type, 'The dummy post type should be "page"' );

$copied_from_course = array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ public function testShouldSetupDummyPost() {

$this->handler->handle_request();

$this->assertEquals( 0, $post->ID, 'The dummy post ID should be 0' );
$this->assertNotEquals( 0, $post->ID, 'The dummy post ID should be non-zero' );
$this->assertNull( get_post( $post->ID ), 'The dummy post ID should be unused' );
$this->assertEquals( 'page', $post->post_type, 'The dummy post type should be "page"' );

$copied_from_teacher_user = array(
Expand Down