Skip to content

Commit

Permalink
Issue #864: Fix PHPUnit tests, accomodating is_amp_endpoint().
Browse files Browse the repository at this point in the history
The widgets now exit from their methods is is_amp_endpoint().
So set this to true, with amp_theme_support( 'amp' ).
  • Loading branch information
Ryan Kienstra committed Jan 23, 2018
1 parent 6053f9a commit e0456e1
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion includes/widgets/class-amp-widget-rss.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class AMP_Widget_RSS extends WP_Widget_RSS {
* @return void.
*/
public function widget( $args, $instance ) {
if ( is_amp_endpoint() ) {
if ( ! is_amp_endpoint() ) {
parent::widget( $args, $instance );
return;
}
Expand Down
1 change: 1 addition & 0 deletions tests/test-class-amp-widget-archives.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Test_AMP_Widget_Archives extends WP_UnitTestCase {
*/
public function setUp() {
parent::setUp();
add_theme_support( 'amp' );
wp_maybe_load_widgets();
AMP_Theme_Support::init();
}
Expand Down
1 change: 1 addition & 0 deletions tests/test-class-amp-widget-categories.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Test_AMP_Widget_Categories extends WP_UnitTestCase {
*/
public function setUp() {
parent::setUp();
add_theme_support( 'amp ' );
wp_maybe_load_widgets();
AMP_Theme_Support::init();
}
Expand Down
1 change: 1 addition & 0 deletions tests/test-class-amp-widget-media-audio.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function setUp() {
$this->markTestSkipped( sprintf( 'The widget %s is not present, so neither is its child class.', $wp_widget ) );
}
parent::setUp();
add_theme_support( 'amp' );
wp_maybe_load_widgets();
AMP_Theme_Support::init();
}
Expand Down
1 change: 1 addition & 0 deletions tests/test-class-amp-widget-media-gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function setUp() {
$this->markTestSkipped( sprintf( 'The widget %s is not present, so neither is its child class.', $wp_widget ) );
}
parent::setUp();
add_theme_support( 'amp' );
wp_maybe_load_widgets();
AMP_Theme_Support::init();
}
Expand Down
1 change: 1 addition & 0 deletions tests/test-class-amp-widget-media-image.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function setUp() {
$this->markTestSkipped( sprintf( 'The widget %s is not present, so neither is its child class.', $wp_widget ) );
}
parent::setUp();
add_theme_support( 'amp' );
AMP_Theme_Support::init();
}

Expand Down
1 change: 1 addition & 0 deletions tests/test-class-amp-widget-media-video.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function setUp() {
$this->markTestSkipped( sprintf( 'The widget %s is not present, so neither is its child class.', $wp_widget ) );
}
parent::setUp();
add_theme_support( 'amp' );
AMP_Theme_Support::init();
}

Expand Down
10 changes: 10 additions & 0 deletions tests/test-class-amp-widget-recent-comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@
*/
class Test_AMP_Widget_Recent_Comments extends WP_UnitTestCase {

/**
* Setup.
*
* @inheritdoc
*/
public function setUp() {
parent::setUp();
add_theme_support( 'amp' );
}

/**
* Test construct().
*
Expand Down
14 changes: 13 additions & 1 deletion tests/test-class-amp-widget-rss.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@
*/
class Test_AMP_Widget_RSS extends WP_UnitTestCase {

/**
* Setup.
*
* @inheritdoc
*/
public function setUp() {
parent::setUp();
add_theme_support( 'amp' );
wp_maybe_load_widgets();
AMP_Theme_Support::init();
}

/**
* Test construct().
*
Expand Down Expand Up @@ -54,7 +66,7 @@ public function test_widget() {
$widget->widget( $args, $instance );
$output = ob_get_clean();

$this->assertFalse( strpos( $output, '<img' ) );
$this->assertNotContains( '<img', $output );
$this->assertContains( '<amp-img', $output );
}

Expand Down

0 comments on commit e0456e1

Please sign in to comment.