Skip to content

Commit

Permalink
Add test for custom template
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter committed Jul 2, 2018
1 parent c172763 commit 38b5546
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion tests/test-class-amp-theme-support.php
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ public function test_get_template_availability() {
$this->assertNull( $wp_query ); // Make sure it is reset.

// Test nested hierarchy.
AMP_Options_Manager::update_option( 'supported_templates', array( 'is_special' ) );
AMP_Options_Manager::update_option( 'supported_templates', array( 'is_special', 'is_custom' ) );
add_filter( 'amp_supportable_templates', function( $templates ) {
$templates['is_single'] = array(
'label' => 'Single post',
Expand All @@ -492,8 +492,18 @@ public function test_get_template_availability() {
'supported' => true,
'parent' => 'is_singular',
);
$templates['is_custom'] = array(
'label' => 'Custom',
'callback' => function( WP_Query $query ) {
return false !== $query->get( 'custom', false );
},
);
return $templates;
} );
add_filter( 'query_vars', function( $vars ) {
$vars[] = 'custom';
return $vars;
} );

$availability = AMP_Theme_Support::get_template_availability( get_post( $post_id ) );
$this->assertFalse( $availability['supported'] );
Expand All @@ -516,6 +526,12 @@ public function test_get_template_availability() {
add_post_type_support( 'page', 'amp' );
$availability = AMP_Theme_Support::get_template_availability( $this->factory()->post->create_and_get( array( 'post_type' => 'page' ) ) );
$this->assertTrue( $availability['supported'] );

// Test custom.
$this->go_to( '/?custom=1' );
$availability = AMP_Theme_Support::get_template_availability();
$this->assertTrue( $availability['supported'] );
$this->assertEquals( 'is_custom', $availability['template'] );
}

/**
Expand Down

0 comments on commit 38b5546

Please sign in to comment.