From ce66658e715e6a0be434deb2c9fe0e7dbab75c6e Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 21 Mar 2018 17:46:28 -0700 Subject: [PATCH 01/22] Fix phpunit warnings regarding use of @cover fornon-existing class or interface --- tests/test-amp-analytics-options.php | 4 ++-- tests/test-amp-helper-functions.php | 14 +++++++------- tests/test-amp.php | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/test-amp-analytics-options.php b/tests/test-amp-analytics-options.php index eb91137771f..5472864cedf 100644 --- a/tests/test-amp-analytics-options.php +++ b/tests/test-amp-analytics-options.php @@ -216,7 +216,7 @@ function test_two_analytics_components_added() { /** * Test amp_get_analytics() * - * @covers amp_get_analytics() + * @covers \amp_get_analytics() */ public function test_amp_get_analytics() { $this->insert_one_option( @@ -243,7 +243,7 @@ public function test_amp_get_analytics() { /** * Test amp_print_analytics() * - * @covers amp_print_analytics() + * @covers \amp_print_analytics() */ public function test_amp_print_analytics() { $this->insert_one_option( diff --git a/tests/test-amp-helper-functions.php b/tests/test-amp-helper-functions.php index 3dd206da7aa..b29f3eefaa7 100644 --- a/tests/test-amp-helper-functions.php +++ b/tests/test-amp-helper-functions.php @@ -35,7 +35,7 @@ public function return_example_url( $url, $post_id ) { /** * Test amp_get_slug(). * - * @covers amp_get_slug() + * @covers \amp_get_slug() */ public function test_amp_get_slug() { $this->assertSame( 'amp', amp_get_slug() ); @@ -181,8 +181,8 @@ public function capture_filter_call( $value ) { /** * Test script registering. * - * @covers amp_register_default_scripts() - * @covers amp_filter_script_loader_tag() + * @covers \amp_register_default_scripts() + * @covers \amp_filter_script_loader_tag() * @global WP_Scripts $wp_scripts */ public function test_script_registering() { @@ -223,7 +223,7 @@ public function test_script_registering() { /** * Test amp_get_content_embed_handlers(). * - * @covers amp_get_content_embed_handlers() + * @covers \amp_get_content_embed_handlers() */ public function test_amp_get_content_embed_handlers() { $post = $this->factory()->post->create_and_get(); @@ -249,7 +249,7 @@ public function test_amp_get_content_embed_handlers() { /** * Test deprecated $post param for amp_get_content_embed_handlers(). * - * @covers amp_get_content_embed_handlers() + * @covers \amp_get_content_embed_handlers() */ public function test_amp_get_content_embed_handlers_deprecated_param() { $post = $this->factory()->post->create_and_get(); @@ -261,7 +261,7 @@ public function test_amp_get_content_embed_handlers_deprecated_param() { /** * Test amp_get_content_sanitizers(). * - * @covers amp_get_content_sanitizers() + * @covers \amp_get_content_sanitizers() */ public function test_amp_get_content_sanitizers() { $post = $this->factory()->post->create_and_get(); @@ -299,7 +299,7 @@ public function test_amp_get_content_sanitizers() { /** * Test deprecated $post param for amp_get_content_sanitizers(). * - * @covers amp_get_content_sanitizers() + * @covers \amp_get_content_sanitizers() */ public function test_amp_get_content_sanitizers_deprecated_param() { $post = $this->factory()->post->create_and_get(); diff --git a/tests/test-amp.php b/tests/test-amp.php index 19b68d9ad26..d78bc2edaab 100644 --- a/tests/test-amp.php +++ b/tests/test-amp.php @@ -21,7 +21,7 @@ public function tearDown() { /** * Test amp_is_canonical(). * - * @covers amp_is_canonical() + * @covers \amp_is_canonical() */ public function test_amp_is_canonical() { remove_theme_support( 'amp' ); From 1fe55278955fbd99f66ad13fd16af4c3f571fa2d Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 21 Mar 2018 18:16:46 -0700 Subject: [PATCH 02/22] Add stubs for missing tests; re-order tests to mirror order in theme support class --- phpunit.xml | 1 + tests/test-class-amp-theme-support.php | 516 +++++++++++++++++-------- 2 files changed, 354 insertions(+), 163 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index a2b80c5bb36..4d7d8f842a4 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -22,6 +22,7 @@ ./ dev-lib + svn node_modules tests vendor diff --git a/tests/test-class-amp-theme-support.php b/tests/test-class-amp-theme-support.php index 0e1bd39df8e..a7a42dc17a5 100644 --- a/tests/test-class-amp-theme-support.php +++ b/tests/test-class-amp-theme-support.php @@ -30,6 +30,25 @@ public function tearDown() { AMP_Theme_Support::$headers_sent = array(); } + /** + * Test init. + * + * @covers AMP_Theme_Support::init() + * @covers AMP_Theme_Support::finish_init() + */ + public function test_init() { + $this->markTestIncomplete(); + } + + /** + * Test redirect_canonical_amp. + * + * @covers AMP_Theme_Support::redirect_canonical_amp() + */ + public function test_redirect_canonical_amp() { + $this->markTestIncomplete(); + } + /** * Test is_paired_available. * @@ -78,181 +97,30 @@ public function test_is_paired_available() { } /** - * Test register_widgets(). - * - * @covers AMP_Theme_Support::register_widgets() - * @global WP_Widget_Factory $wp_widget_factory - */ - public function test_register_widgets() { - global $wp_widget_factory; - remove_all_actions( 'widgets_init' ); - $wp_widget_factory->widgets = array(); - wp_widgets_init(); - AMP_Theme_Support::register_widgets(); - - $this->assertArrayNotHasKey( 'WP_Widget_Categories', $wp_widget_factory->widgets ); - $this->assertArrayHasKey( 'AMP_Widget_Categories', $wp_widget_factory->widgets ); - } - - /** - * Test amend_comment_form(). - * - * @covers AMP_Theme_Support::amend_comment_form() - */ - public function test_amend_comment_form() { - $post_id = $this->factory()->post->create(); - $this->go_to( get_permalink( $post_id ) ); - $this->assertTrue( is_singular() ); - - // Test native AMP. - add_theme_support( 'amp' ); - $this->assertTrue( amp_is_canonical() ); - ob_start(); - AMP_Theme_Support::amend_comment_form(); - $output = ob_get_clean(); - $this->assertNotContains( 'assertContains( '
', $output ); - $this->assertContains( '
', $output ); - - // Test paired AMP. - add_theme_support( 'amp', array( - 'template_dir' => 'amp-templates', - ) ); - $this->assertFalse( amp_is_canonical() ); - ob_start(); - AMP_Theme_Support::amend_comment_form(); - $output = ob_get_clean(); - $this->assertContains( 'assertContains( '
', $output ); - $this->assertContains( '
', $output ); - } - - /** - * Test prepare_response. + * Test is_customize_preview_iframe. * - * @global WP_Widget_Factory $wp_widget_factory - * @global WP_Scripts $wp_scripts - * @covers AMP_Theme_Support::prepare_response() + * @covers AMP_Theme_Support::is_customize_preview_iframe() */ - public function test_prepare_response() { - global $wp_widget_factory, $wp_scripts; - $wp_scripts = null; - - add_theme_support( 'amp' ); - AMP_Theme_Support::init(); - AMP_Theme_Support::finish_init(); - $wp_widget_factory = new WP_Widget_Factory(); - wp_widgets_init(); - - add_action( 'wp_enqueue_scripts', function() { - wp_enqueue_script( 'amp-list' ); - } ); - add_action( 'wp_footer', function() { - wp_print_scripts( 'amp-mathml' ); - ?> - - - - > - - - - - - - - - - - - - - - - function( $removed ) use ( &$removed_nodes ) { - $removed_nodes[ $removed['node']->nodeName ] = $removed['node']; - }, - ) ); - - $this->assertContains( '', $sanitized_html ); - $this->assertContains( '', $sanitized_html ); - $this->assertContains( ' + + + function( $removed ) use ( &$removed_nodes ) { + $removed_nodes[ $removed['node']->nodeName ] = $removed['node']; + }, + ) ); + + $this->assertContains( '', $sanitized_html ); + $this->assertContains( '', $sanitized_html ); + $this->assertContains( '', $output ); } /** @@ -742,7 +783,26 @@ public function test_ensure_required_markup( $script, $expected ) { * @covers AMP_Theme_Support::dequeue_customize_preview_scripts() */ public function test_dequeue_customize_preview_scripts() { - $this->markTestIncomplete(); + // Ensure AMP_Theme_Support::is_customize_preview_iframe() is true. + require_once ABSPATH . WPINC . '/class-wp-customize-manager.php'; + $GLOBALS['wp_customize'] = new WP_Customize_Manager( array( + 'messenger_channel' => 'baz', + ) ); + $GLOBALS['wp_customize']->start_previewing_theme(); + $customize_preview = 'customize-preview'; + $preview_style = 'example-preview-style'; + wp_enqueue_style( $preview_style, home_url( '/' ), array( $customize_preview ) ); + AMP_Theme_Support::dequeue_customize_preview_scripts(); + $this->assertTrue( wp_style_is( $preview_style ) ); + $this->assertTrue( wp_style_is( $customize_preview ) ); + + wp_enqueue_style( $preview_style, home_url( '/' ), array( $customize_preview ) ); + wp_enqueue_style( $customize_preview ); + // Ensure AMP_Theme_Support::is_customize_preview_iframe() is false. + $GLOBALS['wp_customize'] = new WP_Customize_Manager(); + AMP_Theme_Support::dequeue_customize_preview_scripts(); + $this->assertFalse( wp_style_is( $preview_style ) ); + $this->assertFalse( wp_style_is( $customize_preview ) ); } /** From f90c40a7afa6cf3825fb1afd5b07377628a4e5c6 Mon Sep 17 00:00:00 2001 From: David Cramer Date: Wed, 28 Mar 2018 08:01:07 +0200 Subject: [PATCH 12/22] Remove test for renamed method, as test already exists. --- tests/test-class-amp-theme-support.php | 9 --------- 1 file changed, 9 deletions(-) diff --git a/tests/test-class-amp-theme-support.php b/tests/test-class-amp-theme-support.php index 38a35156380..0644cd23bc2 100644 --- a/tests/test-class-amp-theme-support.php +++ b/tests/test-class-amp-theme-support.php @@ -587,15 +587,6 @@ public function test_amend_comment_form() { $this->assertContains( '
', $output ); } - /** - * Test add_amp_comment_form_templates. - * - * @covers AMP_Theme_Support::add_amp_comment_form_templates() - */ - public function test_add_amp_comment_form_templates() { - $this->markTestIncomplete(); - } - /** * Test filter_paired_template_hierarchy. * From 912ea33c13d66683b62d729fef2790c8dc2ddfbe Mon Sep 17 00:00:00 2001 From: David Cramer Date: Wed, 28 Mar 2018 08:49:36 +0200 Subject: [PATCH 13/22] Test start and finish output buffers. --- tests/test-class-amp-theme-support.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/tests/test-class-amp-theme-support.php b/tests/test-class-amp-theme-support.php index 0644cd23bc2..aeba120fd34 100644 --- a/tests/test-class-amp-theme-support.php +++ b/tests/test-class-amp-theme-support.php @@ -802,7 +802,14 @@ public function test_dequeue_customize_preview_scripts() { * @covers AMP_Theme_Support::start_output_buffering() */ public function test_start_output_buffering() { - $this->markTestIncomplete(); + $ob_level = ob_get_level(); + AMP_Theme_Support::start_output_buffering(); + $this->assertTrue( ob_get_level() > $ob_level ); + // End output buffer. + if ( ob_get_level() > $ob_level ) { + ob_get_clean(); + } + $this->assertNotEquals( 10, has_action( 'shutdown', array( self::TESTED_CLASS, 'finish_output_buffering' ) ) ); } /** @@ -811,7 +818,15 @@ public function test_start_output_buffering() { * @covers AMP_Theme_Support::finish_output_buffering() */ public function test_finish_output_buffering() { - $this->markTestIncomplete(); + // start first layer buffer. + ob_start(); + AMP_Theme_Support::start_output_buffering(); + echo ''; + AMP_Theme_Support::finish_output_buffering(); + // get first layer buffer. + $output = ob_get_clean(); + + $this->assertContains( '', $output ); } /** From e4dedbbd3e7018279c2ada8f5c0c662a3499ea35 Mon Sep 17 00:00:00 2001 From: David Cramer Date: Wed, 28 Mar 2018 09:12:56 +0200 Subject: [PATCH 14/22] Add test for partial render and flesh out buffer tests. --- tests/test-class-amp-theme-support.php | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/tests/test-class-amp-theme-support.php b/tests/test-class-amp-theme-support.php index aeba120fd34..34af5aabbde 100644 --- a/tests/test-class-amp-theme-support.php +++ b/tests/test-class-amp-theme-support.php @@ -818,15 +818,23 @@ public function test_start_output_buffering() { * @covers AMP_Theme_Support::finish_output_buffering() */ public function test_finish_output_buffering() { + + add_theme_support( 'amp' ); + AMP_Theme_Support::init(); + AMP_Theme_Support::finish_init(); + // start first layer buffer. ob_start(); AMP_Theme_Support::start_output_buffering(); - echo ''; + echo ''; AMP_Theme_Support::finish_output_buffering(); // get first layer buffer. $output = ob_get_clean(); - $this->assertContains( '', $output ); + $this->assertContains( 'assertContains( 'assertNotContains( ''; + $output = AMP_Theme_Support::filter_customize_partial_render( $partial ); + $this->assertContains( 'assertNotContains( 'assertNotContains( ' Date: Wed, 28 Mar 2018 10:44:29 +0200 Subject: [PATCH 15/22] Correct assertion on has_action for shutdown --- tests/test-class-amp-theme-support.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/test-class-amp-theme-support.php b/tests/test-class-amp-theme-support.php index 34af5aabbde..bda834d1a0e 100644 --- a/tests/test-class-amp-theme-support.php +++ b/tests/test-class-amp-theme-support.php @@ -802,14 +802,20 @@ public function test_dequeue_customize_preview_scripts() { * @covers AMP_Theme_Support::start_output_buffering() */ public function test_start_output_buffering() { + + add_theme_support( 'amp' ); + AMP_Theme_Support::init(); + AMP_Theme_Support::finish_init(); + $ob_level = ob_get_level(); AMP_Theme_Support::start_output_buffering(); + + $this->assertEquals( 0, has_action( 'shutdown', array( self::TESTED_CLASS, 'finish_output_buffering' ) ) ); $this->assertTrue( ob_get_level() > $ob_level ); // End output buffer. if ( ob_get_level() > $ob_level ) { ob_get_clean(); } - $this->assertNotEquals( 10, has_action( 'shutdown', array( self::TESTED_CLASS, 'finish_output_buffering' ) ) ); } /** From 9caf29b98347559edde6a5cd400e4bb0b901d08b Mon Sep 17 00:00:00 2001 From: David Cramer Date: Wed, 28 Mar 2018 11:28:20 +0200 Subject: [PATCH 16/22] use function_exists instead of extension_loaded to simplify testing. --- includes/class-amp-theme-support.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-amp-theme-support.php b/includes/class-amp-theme-support.php index 6ba3b507f30..dafb81d3fbb 100644 --- a/includes/class-amp-theme-support.php +++ b/includes/class-amp-theme-support.php @@ -997,7 +997,7 @@ public static function start_output_buffering() { * Sites with New Relic will need to specially configure New Relic for AMP: * https://docs.newrelic.com/docs/browser/new-relic-browser/installation/monitor-amp-pages-new-relic-browser */ - if ( extension_loaded( 'newrelic' ) ) { + if ( function_exists( 'newrelic_disable_autorum' ) ) { newrelic_disable_autorum(); } From cdb6bba68e326e763c6ff828e3031bb6d3ddddfe Mon Sep 17 00:00:00 2001 From: David Cramer Date: Wed, 28 Mar 2018 11:38:07 +0200 Subject: [PATCH 17/22] define newrelic_disable_autorum to allow testing --- tests/test-class-amp-theme-support.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/test-class-amp-theme-support.php b/tests/test-class-amp-theme-support.php index bda834d1a0e..d852c92c507 100644 --- a/tests/test-class-amp-theme-support.php +++ b/tests/test-class-amp-theme-support.php @@ -803,6 +803,15 @@ public function test_dequeue_customize_preview_scripts() { */ public function test_start_output_buffering() { + if ( ! function_exists( 'newrelic_disable_autorum ' ) ) { + /** + * Define newrelic_disable_autorum to allow passing line. + */ + function newrelic_disable_autorum() { + return true; + } + } + add_theme_support( 'amp' ); AMP_Theme_Support::init(); AMP_Theme_Support::finish_init(); From 1b75faeaaba4ca55440290fd05f91db38892ed76 Mon Sep 17 00:00:00 2001 From: David Cramer Date: Wed, 28 Mar 2018 12:13:55 +0200 Subject: [PATCH 18/22] more coverage for intercept_post_request_redirect --- tests/test-class-amp-theme-support.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-class-amp-theme-support.php b/tests/test-class-amp-theme-support.php index d852c92c507..144e78b039b 100644 --- a/tests/test-class-amp-theme-support.php +++ b/tests/test-class-amp-theme-support.php @@ -405,7 +405,7 @@ public function test_handle_wp_die() { public function test_intercept_post_request_redirect() { add_theme_support( 'amp' ); - $url = home_url( '/', 'https' ); + $url = home_url( '', 'https' ) . ':443/?test=true#test'; add_filter( 'wp_doing_ajax', '__return_true' ); add_filter( 'wp_die_ajax_handler', function () { From 2540e86276670399226f163fc79a91c26f4454eb Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Wed, 28 Mar 2018 16:36:33 -0600 Subject: [PATCH 19/22] Remove extra variable declarations. These variables are only used once, so they can simply be passed to the array. --- tests/test-class-amp-theme-support.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/test-class-amp-theme-support.php b/tests/test-class-amp-theme-support.php index 144e78b039b..89e0b0ffd28 100644 --- a/tests/test-class-amp-theme-support.php +++ b/tests/test-class-amp-theme-support.php @@ -670,12 +670,10 @@ public function test_get_comment_form_state_id() { */ public function test_filter_comment_form_defaults() { global $post; - $post = $this->factory()->post->create_and_get(); // WPCS: global override ok. - $title_reply_to = 'Reply To'; - $title_reply = 'Reply'; - $defaults = AMP_Theme_Support::filter_comment_form_defaults( array( - 'title_reply_to' => $title_reply_to, - 'title_reply' => $title_reply, + $post = $this->factory()->post->create_and_get(); // WPCS: global override ok. + $defaults = AMP_Theme_Support::filter_comment_form_defaults( array( + 'title_reply_to' => 'Reply To', + 'title_reply' => 'Reply', 'cancel_reply_before' => '', 'title_reply_before' => '', ) ); From 86f13fb11efff70f650de59e0d941e7b831a59c8 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Wed, 28 Mar 2018 16:49:04 -0600 Subject: [PATCH 20/22] Remove extra phpcs:ignore comments. There's already a phpcs:disable at the top of the method. And a phpcs:enable at the bottom. --- tests/test-class-amp-theme-support.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/test-class-amp-theme-support.php b/tests/test-class-amp-theme-support.php index 89e0b0ffd28..8b9a2a7efbb 100644 --- a/tests/test-class-amp-theme-support.php +++ b/tests/test-class-amp-theme-support.php @@ -218,7 +218,7 @@ public function test_add_hooks() { * @covers AMP_Theme_Support::purge_amp_query_vars() */ public function test_purge_amp_query_vars() { - // phpcs:disable WordPress.Security.NonceVerification.NoNonceVerification + // phpcs:disable WordPress.CSRF.NonceVerification.NoNonceVerification $bad_query_vars = array( 'amp_latest_update_time' => '1517199956', '__amp_source_origin' => home_url(), @@ -232,10 +232,10 @@ public function test_purge_amp_query_vars() { remove_action( 'wp', 'amp_maybe_add_actions' ); $this->go_to( add_query_arg( $all_query_vars, home_url( '/foo/' ) ) ); - $_REQUEST = $_GET; // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification + $_REQUEST = $_GET; foreach ( $all_query_vars as $key => $value ) { - $this->assertArrayHasKey( $key, $_GET ); // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification - $this->assertArrayHasKey( $key, $_REQUEST ); // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification + $this->assertArrayHasKey( $key, $_GET ); + $this->assertArrayHasKey( $key, $_REQUEST ); $this->assertContains( "$key=$value", $_SERVER['QUERY_STRING'] ); $this->assertContains( "$key=$value", $_SERVER['REQUEST_URI'] ); } @@ -245,18 +245,18 @@ public function test_purge_amp_query_vars() { $this->assertEqualSets( AMP_Theme_Support::$purged_amp_query_vars, $bad_query_vars ); foreach ( $bad_query_vars as $key => $value ) { - $this->assertArrayNotHasKey( $key, $_GET ); // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification - $this->assertArrayNotHasKey( $key, $_REQUEST ); // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification + $this->assertArrayNotHasKey( $key, $_GET ); + $this->assertArrayNotHasKey( $key, $_REQUEST ); $this->assertNotContains( "$key=$value", $_SERVER['QUERY_STRING'] ); $this->assertNotContains( "$key=$value", $_SERVER['REQUEST_URI'] ); } foreach ( $ok_query_vars as $key => $value ) { - $this->assertArrayHasKey( $key, $_GET ); // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification - $this->assertArrayHasKey( $key, $_REQUEST ); // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification + $this->assertArrayHasKey( $key, $_GET ); + $this->assertArrayHasKey( $key, $_REQUEST ); $this->assertContains( "$key=$value", $_SERVER['QUERY_STRING'] ); $this->assertContains( "$key=$value", $_SERVER['REQUEST_URI'] ); } - // phpcs:enable WordPress.Security.NonceVerification.NoNonceVerification + // phpcs:enable WordPress.CSRF.NonceVerification.NoNonceVerification } /** From b365e00311618c966dcb97ff90d7e79d8baa5d5c Mon Sep 17 00:00:00 2001 From: David Cramer Date: Thu, 29 Mar 2018 05:40:38 +0200 Subject: [PATCH 21/22] Address issues from CR --- includes/class-amp-theme-support.php | 2 +- tests/test-class-amp-theme-support.php | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/includes/class-amp-theme-support.php b/includes/class-amp-theme-support.php index dafb81d3fbb..77b4be81e59 100644 --- a/includes/class-amp-theme-support.php +++ b/includes/class-amp-theme-support.php @@ -243,7 +243,7 @@ public static function add_hooks() { add_action( 'template_redirect', array( __CLASS__, 'start_output_buffering' ), 0 ); // Commenting hooks. - add_filter( 'wp_list_comments_args', array( __CLASS__, 'amp_set_comments_walker' ), PHP_INT_MAX ); + add_filter( 'wp_list_comments_args', array( __CLASS__, 'set_comments_walker' ), PHP_INT_MAX ); add_filter( 'comment_form_defaults', array( __CLASS__, 'filter_comment_form_defaults' ) ); add_filter( 'comment_reply_link', array( __CLASS__, 'filter_comment_reply_link' ), 10, 4 ); add_filter( 'cancel_comment_reply_link', array( __CLASS__, 'filter_cancel_comment_reply_link' ), 10, 3 ); diff --git a/tests/test-class-amp-theme-support.php b/tests/test-class-amp-theme-support.php index 8b9a2a7efbb..fed0c25e1dc 100644 --- a/tests/test-class-amp-theme-support.php +++ b/tests/test-class-amp-theme-support.php @@ -204,7 +204,7 @@ public function test_add_hooks() { $this->assertEquals( 100, has_filter( 'show_admin_bar', '__return_false' ) ); $this->assertEquals( 0, has_action( 'template_redirect', array( self::TESTED_CLASS, 'start_output_buffering' ) ) ); - $this->assertEquals( PHP_INT_MAX, has_filter( 'wp_list_comments_args', array( self::TESTED_CLASS, 'amp_set_comments_walker' ) ) ); + $this->assertEquals( PHP_INT_MAX, has_filter( 'wp_list_comments_args', array( self::TESTED_CLASS, 'set_comments_walker' ) ) ); $this->assertEquals( 10, has_filter( 'comment_form_defaults', array( self::TESTED_CLASS, 'filter_comment_form_defaults' ) ) ); $this->assertEquals( 10, has_filter( 'comment_reply_link', array( self::TESTED_CLASS, 'filter_comment_reply_link' ) ) ); $this->assertEquals( 10, has_filter( 'cancel_comment_reply_link', array( self::TESTED_CLASS, 'filter_cancel_comment_reply_link' ) ) ); @@ -800,7 +800,6 @@ public function test_dequeue_customize_preview_scripts() { * @covers AMP_Theme_Support::start_output_buffering() */ public function test_start_output_buffering() { - if ( ! function_exists( 'newrelic_disable_autorum ' ) ) { /** * Define newrelic_disable_autorum to allow passing line. @@ -831,7 +830,6 @@ function newrelic_disable_autorum() { * @covers AMP_Theme_Support::finish_output_buffering() */ public function test_finish_output_buffering() { - add_theme_support( 'amp' ); AMP_Theme_Support::init(); AMP_Theme_Support::finish_init(); @@ -856,7 +854,6 @@ public function test_finish_output_buffering() { * @covers AMP_Theme_Support::filter_customize_partial_render() */ public function test_filter_customize_partial_render() { - add_theme_support( 'amp' ); AMP_Theme_Support::init(); AMP_Theme_Support::finish_init(); From 71b83fcd8c0ecc9491a9d3629be1a9aa666bf008 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Fri, 30 Mar 2018 18:37:37 -0600 Subject: [PATCH 22/22] Fix a failed unit test by setting $wp_styles to null. Before, merging in 0.7, there was an amp-default . But test_validate_non_amp_theme() also output that. And that stored the script in $wp_styles->done. So it wasn't output again, and the test failed. So reset $wp_styles, so it gets re-instantiated. --- tests/test-class-amp-theme-support.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test-class-amp-theme-support.php b/tests/test-class-amp-theme-support.php index 5647f6d023d..597375b3990 100644 --- a/tests/test-class-amp-theme-support.php +++ b/tests/test-class-amp-theme-support.php @@ -913,8 +913,9 @@ public function test_filter_customize_partial_render() { * @covers AMP_Theme_Support::prepare_response() */ public function test_prepare_response() { - global $wp_widget_factory, $wp_scripts; + global $wp_widget_factory, $wp_scripts, $wp_styles; $wp_scripts = null; + $wp_styles = null; add_theme_support( 'amp' ); AMP_Theme_Support::init();