From be58d0243f1ef4e3533e853ff6bb436231104d4f Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Wed, 17 Jan 2018 15:46:27 -0600 Subject: [PATCH] Issue #864: Remove dequeuing of scripts, and create comment subclass. As Weston mentioned, the plugin already prevents scripts in: 'wp_print_footer_scripts'. Also, move the comment filter to a subclass of WP_Widget_Recent_Comments. Includes PHPUnit tests for all of these changes. --- includes/class-amp-autoloader.php | 1 + .../class-amp-widget-recent-comments.php | 23 +++++++++ includes/widgets/class-amp-widgets.php | 21 ++------ tests/test-class-amp-widget-archives.php | 4 +- tests/test-class-amp-widget-categories.php | 4 +- .../test-class-amp-widget-recent-comments.php | 51 +++++++++++++++++++ tests/test-class-amp-widgets.php | 20 ++------ 7 files changed, 89 insertions(+), 35 deletions(-) create mode 100644 includes/widgets/class-amp-widget-recent-comments.php create mode 100644 tests/test-class-amp-widget-recent-comments.php diff --git a/includes/class-amp-autoloader.php b/includes/class-amp-autoloader.php index 89d6b6a8131..5ca2fd0e8a8 100644 --- a/includes/class-amp-autoloader.php +++ b/includes/class-amp-autoloader.php @@ -80,6 +80,7 @@ class AMP_Autoloader { 'AMP_WP_Utils' => 'includes/utils/class-amp-wp-utils', 'AMP_Widget_Archives' => 'includes/widgets/class-amp-widget-archives', 'AMP_Widget_Categories' => 'includes/widgets/class-amp-widget-categories', + 'AMP_Widget_Recent_Comments' => 'includes/widgets/class-amp-widget-recent-comments', 'AMP_Widgets' => 'includes/widgets/class-amp-widgets', 'WPCOM_AMP_Polldaddy_Embed' => 'wpcom/class-amp-polldaddy-embed', 'AMP_Test_Stub_Sanitizer' => 'tests/stubs', diff --git a/includes/widgets/class-amp-widget-recent-comments.php b/includes/widgets/class-amp-widget-recent-comments.php new file mode 100644 index 00000000000..4207b5c2da5 --- /dev/null +++ b/includes/widgets/class-amp-widget-recent-comments.php @@ -0,0 +1,23 @@ + 'AMP_Widget_Archives', - 'WP_Widget_Categories' => 'AMP_Widget_Categories', + 'WP_Widget_Archives' => 'AMP_Widget_Archives', + 'WP_Widget_Categories' => 'AMP_Widget_Categories', + 'WP_Widget_Recent_Comments' => 'AMP_Widget_Recent_Comments', ); } - /** - * Dequeue widget scripts and styles, which aren't allowed in AMP. - * - * Uses the action 'wp_footer' in order to prevent - * 'wp_print_footer_scripts' from outputting the scripts. - * - * @return void. - */ - public function dequeue_scripts() { - wp_dequeue_script( 'wp-mediaelement' ); - wp_dequeue_script( 'mediaelement-vimeo' ); - wp_dequeue_style( 'wp-mediaelement' ); - } - } diff --git a/tests/test-class-amp-widget-archives.php b/tests/test-class-amp-widget-archives.php index 3a3b27f037f..cf195f02735 100644 --- a/tests/test-class-amp-widget-archives.php +++ b/tests/test-class-amp-widget-archives.php @@ -8,9 +8,10 @@ /** * Tests for class AMP_Widget_Archives. * - * @package WidgetLiveEditor + * @package AMP */ class Test_AMP_Widget_Archives extends WP_UnitTestCase { + /** * Instance of the widget. * @@ -68,4 +69,5 @@ public function test_widget() { $this->assertFalse( strpos( $output, 'onchange=' ) ); } + } diff --git a/tests/test-class-amp-widget-categories.php b/tests/test-class-amp-widget-categories.php index c21d7ccd495..f2077dbe356 100644 --- a/tests/test-class-amp-widget-categories.php +++ b/tests/test-class-amp-widget-categories.php @@ -8,9 +8,10 @@ /** * Tests for class AMP_Widget_Categories. * - * @package WidgetLiveEditor + * @package AMP */ class Test_AMP_Widget_Categories extends WP_UnitTestCase { + /** * Instance of the widget. * @@ -68,4 +69,5 @@ public function test_widget() { $this->assertFalse( strpos( $output, '