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

Add UI to select an offline page #28

Merged
merged 31 commits into from
Jul 27, 2018
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
314c472
Begin UI to select an offline page.
kienstra Jul 11, 2018
596e44c
Add UI field description and improve settings field title.
hellofromtonya Jul 11, 2018
225ba95
Change option name to `page_for_offline`.
hellofromtonya Jul 12, 2018
53f6533
Add the post state message for the offline page.
hellofromtonya Jul 12, 2018
8d7aa1c
Made settings errors appear on loading the Reading page.
hellofromtonya Jul 12, 2018
7d7da59
Remove the page attributes meta box from only the Offline Page.
hellofromtonya Jul 12, 2018
c683eaf
Remove page attributes support for Offline Page.
hellofromtonya Jul 13, 2018
e76b7f1
Optimize the admin initialization by registering one callback.
hellofromtonya Jul 13, 2018
83c5604
Improve the method names to tell intent.
hellofromtonya Jul 13, 2018
98c6f82
Exclude static pages from dropdowns.
hellofromtonya Jul 13, 2018
7e6574b
Add create new page functionality.
hellofromtonya Jul 13, 2018
c403da5
Merge 'master' to update feature branch.
hellofromtonya Jul 13, 2018
6a7a720
Fix plugin dir constant after master merge.
hellofromtonya Jul 13, 2018
cc997ef
Re-enable page attributes.
hellofromtonya Jul 16, 2018
33c461c
Excluding offline page from menus and search.
hellofromtonya Jul 16, 2018
c7c96b4
Exclude the offline page from Customizer's homepage & posts page drop…
hellofromtonya Jul 16, 2018
c48b36c
Exclude offline page from rendering on frontend.
hellofromtonya Jul 16, 2018
05b655b
Split tasks into separate classes.
hellofromtonya Jul 17, 2018
7104c53
Improve and optimize excluder.
hellofromtonya Jul 17, 2018
cc40e00
Apply changes based on code review
westonruter Jul 26, 2018
846ce07
Include privacy page in `get_static_pages()`.
Jul 26, 2018
11b49fc
Improve tests to ensure privacy page is also excluded from the offlin…
Jul 26, 2018
40f8737
Change settings label to "Default offline status page".
Jul 26, 2018
7ef0dea
Publish status only in the page dropdowns and for creating a new page.
Jul 26, 2018
eddeb84
Merge the offline page ID with the current "post__not_in" var.
Jul 26, 2018
d1dbaf9
Offline page is a page and singular.
Jul 26, 2018
f8c3137
Improve is_offline_page_query().
Jul 26, 2018
ab4cbc6
Allow the default offline page to load on the frontend.
Jul 26, 2018
03e78ba
Make naming more clear by adding "default".
Jul 26, 2018
9669026
Exclude the default offline page from robots.
Jul 26, 2018
af9aedd
Separate concerns for no robots. Code formatting.
Jul 27, 2018
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
5 changes: 5 additions & 0 deletions pwa.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@
/** Amend default filters */
require PWA_PLUGIN_DIR . '/wp-includes/default-filters.php';

/** WP_Offline_Page Class */
require PWA_PLUGIN_DIR . '/wp-includes/class-wp-offline-page.php';

$wp_web_app_manifest = new WP_Web_App_Manifest();
$wp_web_app_manifest->init();
$wp_https_detection = new WP_HTTPS_Detection();
$wp_https_detection->init();
$wp_offline_page = new WP_Offline_Page();
$wp_offline_page->init();
128 changes: 128 additions & 0 deletions tests/test-class-wp-offline-page-excluder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?php
/**
* Tests for class WP_Offline_Page_Excluder.
*
* @package PWA
*/

/**
* Tests for class WP_Offline_Page_Excluder.
*/
class Test_WP_Offline_Page_Excluder extends WP_UnitTestCase {

/**
* Tested instance.
*
* @var WP_Offline_Page_Excluder
*/
public $instance;

/**
* Setup.
*
* @inheritdoc
*/
public function setUp() {
parent::setUp();
$this->instance = new WP_Offline_Page_Excluder( new WP_Offline_Page() );
}

/**
* Test init.
*
* @covers WP_Offline_Page_Excluder::init()
*/
public function test_init() {
$this->instance->init();
$this->assertEquals( 10, has_filter( 'wp_dropdown_pages', array( $this->instance, 'exclude_from_page_dropdown' ) ) );
$this->assertEquals( 10, has_filter( 'parse_query', array( $this->instance, 'exclude_from_query' ) ) );
}

/**
* Test exclude_from_page_dropdown.
*
* @covers WP_Offline_Page_Excluder::exclude_from_page_dropdown()
*/
public function test_exclude_from_page_dropdown() {
$page_id = $this->factory()->post->create( array( 'post_type' => 'page' ) );
$html = <<<EOB
<select name="page_on_front" id="page_on_front">
<option value="0">— Select —</option>
<option class="level-0" value="7">Blog Page</option>
<option class="level-0" value="5" selected="selected">Home page</option>
<option class="level-0" value="13">Offline Page</option>
<option class="level-0" value="3">Privacy Policy</option>
<option class="level-0" value="2">Sample Page</option>
</select>
EOB;
$html = str_replace( '13', $page_id, $html );

// Check that the HTML is unchanged when no Offline Page exists.
$this->assertSame(
$html,
$this->instance->exclude_from_page_dropdown( $html, array( 'name' => 'page_on_front' ) )
);

// Add the Offline Page and recheck.
add_option( WP_Offline_Page::OPTION_NAME, $page_id );
$this->assertNotContains(
'<option class="level-0" value="' . $page_id . '">Offline Page</option>',
$this->instance->exclude_from_page_dropdown( $html, array( 'name' => 'page_on_front' ) )
);
}

/**
* Test is_exclude_from_query.
*
* @covers WP_Offline_Page_Excluder::is_exclude_from_query()
*/
public function test_is_exclude_from_query() {
set_current_screen( 'front' );

$offline_id = $this->factory()->post->create( array(
'post_type' => 'page',
'post_title' => 'Offline page',
) );
$page_id = $this->factory()->post->create( array(
'post_type' => 'page',
'post_title' => 'Accessing via Offline',
) );
add_option( WP_Offline_Page::OPTION_NAME, $offline_id );
add_action( 'parse_query', array( $this->instance, 'exclude_from_query' ) );

// Check a page.
$this->go_to( get_permalink( $page_id ) );
$this->assertEquals( array( $offline_id ), get_query_var( 'post__not_in' ) );
$this->assertSame( $page_id, get_queried_object()->ID );

// Check search.
$this->go_to( '?s=Offline' );
$this->assertEquals( array( $offline_id ), get_query_var( 'post__not_in' ) );
$this->assertTrue( have_posts() );
$this->assertEquals( 1, $GLOBALS['wp_query']->post_count );

// Check edit.php.
set_current_screen( 'edit.php' );
$this->go_to( admin_url( 'edit.php' ) );
$this->assertEquals( array(), get_query_var( 'post__not_in' ) );

// Check that is is excluded on the nav-menu.php query.
set_current_screen( 'nav-menus.php' );
$this->go_to( admin_url( 'nav-menus.php' ) );
$this->assertEquals( array( $offline_id ), get_query_var( 'post__not_in' ) );

set_current_screen( 'front' );

// Check that the offline page is found when using the plan permalink.
$this->go_to( "?page_id={$offline_id}" );
$this->assertEquals( array( $offline_id ), get_query_var( 'post__not_in' ) );
$this->assertFalse( $GLOBALS['wp_query']->is_404() );
$this->assertSame( $offline_id, get_queried_object()->ID );

// Check that the offline page flags a 404.
$this->set_permalink_structure( '/%postname%/' );
$this->go_to( get_permalink( $offline_id ) );
$this->assertEquals( array( $offline_id ), get_query_var( 'post__not_in' ) );
$this->assertTrue( $GLOBALS['wp_query']->is_404() );
}
}
Loading