-
Notifications
You must be signed in to change notification settings - Fork 385
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #877 from Automattic/update/paired-mode-available
Account for post_supports_amp() in is_paired_available()
- Loading branch information
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
/** | ||
* Tests for Theme Support. | ||
* | ||
* @package AMP | ||
* @since 0.7 | ||
*/ | ||
|
||
/** | ||
* Tests for Theme Support. | ||
* | ||
* @covers AMP_Theme_Support | ||
*/ | ||
class Test_AMP_Theme_Support extends WP_UnitTestCase { | ||
|
||
/** | ||
* After a test method runs, reset any state in WordPress the test method might have changed. | ||
*/ | ||
public function tearDown() { | ||
parent::tearDown(); | ||
remove_theme_support( 'amp' ); | ||
} | ||
|
||
/** | ||
* Test is_paired_available. | ||
* | ||
* @covers AMP_Theme_Support::is_paired_available() | ||
*/ | ||
public function test_is_paired_available() { | ||
|
||
// Establish initial state. | ||
$post_id = $this->factory()->post->create( array( 'post_title' => 'Test' ) ); | ||
remove_theme_support( 'amp' ); | ||
query_posts( array( 'p' => $post_id ) ); // phpcs:ignore | ||
$this->assertTrue( is_singular() ); | ||
|
||
// Paired support is not available if theme support is not present or canonical. | ||
$this->assertFalse( AMP_Theme_Support::is_paired_available() ); | ||
add_theme_support( 'amp' ); | ||
$this->assertFalse( AMP_Theme_Support::is_paired_available() ); | ||
|
||
// Paired mode is available once template_dir is supplied. | ||
add_theme_support( 'amp', array( | ||
'template_dir' => 'amp-templates', | ||
) ); | ||
$this->assertTrue( AMP_Theme_Support::is_paired_available() ); | ||
|
||
// Paired mode not available when post does not support AMP. | ||
add_filter( 'amp_skip_post', '__return_true' ); | ||
$this->assertFalse( AMP_Theme_Support::is_paired_available() ); | ||
$this->assertTrue( is_singular() ); | ||
query_posts( array( 's' => 'test' ) ); // phpcs:ignore | ||
$this->assertTrue( is_search() ); | ||
$this->assertTrue( AMP_Theme_Support::is_paired_available() ); | ||
remove_filter( 'amp_skip_post', '__return_true' ); | ||
|
||
// Check that available_callback works. | ||
add_theme_support( 'amp', array( | ||
'template_dir' => 'amp-templates', | ||
'available_callback' => 'is_singular', | ||
) ); | ||
query_posts( array( 'p' => $post_id ) ); // phpcs:ignore | ||
$this->assertTrue( is_singular() ); | ||
$this->assertTrue( AMP_Theme_Support::is_paired_available() ); | ||
|
||
query_posts( array( 's' => $post_id ) ); // phpcs:ignore | ||
$this->assertTrue( is_search() ); | ||
$this->assertFalse( AMP_Theme_Support::is_paired_available() ); | ||
} | ||
} |