From 98a36c5388348ab5285289adbfb7a585776c6b43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Kr=C3=A4ftner?= Date: Thu, 2 Nov 2017 15:55:32 +0100 Subject: [PATCH 01/10] move testing code out of plugin --- composer.json | 5 ++- ...lass-ac-yoast-seo-acf-content-analysis.php | 12 ------ tests/js/system/data/test-data-loader.php | 38 +++++++++++++++++++ 3 files changed, 42 insertions(+), 13 deletions(-) create mode 100644 tests/js/system/data/test-data-loader.php diff --git a/composer.json b/composer.json index 8e92fca2..15253794 100644 --- a/composer.json +++ b/composer.json @@ -59,7 +59,10 @@ "autoload-dev": { "psr-4": { "Yoast\\AcfAnalysis\\Tests\\": "tests/php/unit" - } + }, + "files": [ + "tests/js/system/data/test-data-loader.php" + ] }, "scripts": { "post-install-cmd": [ diff --git a/inc/class-ac-yoast-seo-acf-content-analysis.php b/inc/class-ac-yoast-seo-acf-content-analysis.php index dd448693..25248478 100755 --- a/inc/class-ac-yoast-seo-acf-content-analysis.php +++ b/inc/class-ac-yoast-seo-acf-content-analysis.php @@ -28,10 +28,6 @@ public function admin_init() { $this->boot(); - if ( defined( 'AC_YOAST_ACF_ANALYSIS_ENVIRONMENT' ) && 'development' === AC_YOAST_ACF_ANALYSIS_ENVIRONMENT ) { - $this->boot_dev(); - } - $this->register_config_filters(); $assets = new Yoast_ACF_Analysis_Assets(); @@ -76,14 +72,6 @@ public function boot() { $registry->add( 'config', $configuration ); } - /** - * Boots the plugin for dev environment. - */ - public function boot_dev() { - $version = ( -1 === version_compare( get_option( 'acf_version' ), 5 ) ) ? '4' : '5'; - require_once AC_SEO_ACF_ANALYSIS_PLUGIN_PATH . '/tests/js/system/data/acf' . $version . '.php'; - } - /** * Filters the Scraper Configuration to add the headlines configuration for the text scraper. */ diff --git a/tests/js/system/data/test-data-loader.php b/tests/js/system/data/test-data-loader.php new file mode 100644 index 00000000..6bd8bbe4 --- /dev/null +++ b/tests/js/system/data/test-data-loader.php @@ -0,0 +1,38 @@ + $function_name, + 'accepted_args' => 1, +); + +function yoast_acf_analysis_test_data_loader() { + + if ( defined( 'AC_YOAST_ACF_ANALYSIS_ENVIRONMENT' ) && 'development' === AC_YOAST_ACF_ANALYSIS_ENVIRONMENT ) { + + $version = ( -1 === version_compare( get_option( 'acf_version' ), 5 ) ) ? '4' : '5'; + require_once AC_SEO_ACF_ANALYSIS_PLUGIN_PATH . '/tests/js/system/data/acf' . $version . '.php'; + + } + +} From 38ff8e18aa25cb9b81417960a700bf7bc689ef24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Kr=C3=A4ftner?= Date: Thu, 2 Nov 2017 17:38:29 +0100 Subject: [PATCH 02/10] use default composer autoloader if supported (xrstf/composer-php52 apparently doesn't support "files" in "autoload") --- tests/js/system/data/test-data-loader.php | 34 ++++++++++++++--------- yoast-acf-analysis.php | 16 +++++++---- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/tests/js/system/data/test-data-loader.php b/tests/js/system/data/test-data-loader.php index 6bd8bbe4..35e1380f 100644 --- a/tests/js/system/data/test-data-loader.php +++ b/tests/js/system/data/test-data-loader.php @@ -9,22 +9,30 @@ $hook_name = 'admin_init'; $function_name = 'yoast_acf_analysis_test_data_loader'; -if ( ! is_array( $wp_filter ) ) { - $wp_filter = array(); -} +if ( ! function_exists( 'add_action' ) ) { -if ( ! isset( $wp_filter[ $hook_name ] ) ) { - $wp_filter[ $hook_name ] = array(); -} + if ( ! is_array( $wp_filter ) ) { + $wp_filter = array(); + } -if ( ! isset( $wp_filter[ $hook_name ][10] ) ) { - $wp_filter[ $hook_name ][10] = array(); -} + if ( ! isset( $wp_filter[ $hook_name ] ) ) { + $wp_filter[ $hook_name ] = array(); + } -$wp_filter[ $hook_name ][10][ $function_name ] = array( - 'function' => $function_name, - 'accepted_args' => 1, -); + if ( ! isset( $wp_filter[ $hook_name ][10] ) ) { + $wp_filter[ $hook_name ][10] = array(); + } + + $wp_filter[ $hook_name ][10][ $function_name ] = array( + 'function' => $function_name, + 'accepted_args' => 1, + ); + +}else{ + + add_action( $hook_name, $function_name ); + +} function yoast_acf_analysis_test_data_loader() { diff --git a/yoast-acf-analysis.php b/yoast-acf-analysis.php index ccbeaa03..7b74a60c 100755 --- a/yoast-acf-analysis.php +++ b/yoast-acf-analysis.php @@ -27,11 +27,14 @@ define( 'AC_SEO_ACF_ANALYSIS_PLUGIN_NAME', untrailingslashit( plugin_basename( __FILE__ ) ) ); } -if ( is_file( AC_SEO_ACF_ANALYSIS_PLUGIN_PATH . '/vendor/autoload_52.php' ) ) { - require AC_SEO_ACF_ANALYSIS_PLUGIN_PATH . '/vendor/autoload_52.php'; - - $ac_yoast_seo_acf_analysis = new AC_Yoast_SEO_ACF_Content_Analysis(); - $ac_yoast_seo_acf_analysis->init(); +if ( version_compare( PHP_VERSION, '5.3.2', '>=' ) ) { + if ( is_file( AC_SEO_ACF_ANALYSIS_PLUGIN_PATH . '/vendor/autoload.php' ) ) { + require AC_SEO_ACF_ANALYSIS_PLUGIN_PATH . '/vendor/autoload.php'; + } +} else { + if ( is_file( AC_SEO_ACF_ANALYSIS_PLUGIN_PATH . '/vendor/autoload_52.php' ) ) { + require AC_SEO_ACF_ANALYSIS_PLUGIN_PATH . '/vendor/autoload_52.php'; + } } /** @@ -57,4 +60,7 @@ function yoast_acf_analysis_load_textdomain() { 'admin_notices', create_function( '', "echo '

$message

';" ) ); +} else { + $ac_yoast_seo_acf_analysis = new AC_Yoast_SEO_ACF_Content_Analysis(); + $ac_yoast_seo_acf_analysis->init(); } From b80d0e1731d1a59335b7a702c73ae3bd071b9c70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Kr=C3=A4ftner?= Date: Mon, 11 Dec 2017 12:28:32 +0100 Subject: [PATCH 03/10] improve version detection in test data loader --- tests/js/system/data/test-data-loader.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tests/js/system/data/test-data-loader.php b/tests/js/system/data/test-data-loader.php index 35e1380f..2bb3ed25 100644 --- a/tests/js/system/data/test-data-loader.php +++ b/tests/js/system/data/test-data-loader.php @@ -19,18 +19,18 @@ $wp_filter[ $hook_name ] = array(); } - if ( ! isset( $wp_filter[ $hook_name ][10] ) ) { - $wp_filter[ $hook_name ][10] = array(); + if ( ! isset( $wp_filter[ $hook_name ][11] ) ) { + $wp_filter[ $hook_name ][11] = array(); } - $wp_filter[ $hook_name ][10][ $function_name ] = array( + $wp_filter[ $hook_name ][11][ $function_name ] = array( 'function' => $function_name, 'accepted_args' => 1, ); }else{ - add_action( $hook_name, $function_name ); + add_action( $hook_name, $function_name, 11 ); } @@ -38,7 +38,14 @@ function yoast_acf_analysis_test_data_loader() { if ( defined( 'AC_YOAST_ACF_ANALYSIS_ENVIRONMENT' ) && 'development' === AC_YOAST_ACF_ANALYSIS_ENVIRONMENT ) { - $version = ( -1 === version_compare( get_option( 'acf_version' ), 5 ) ) ? '4' : '5'; + $registry = Yoast_ACF_Analysis_Facade::get_registry(); + $configuration = $registry->get( 'config' ); + + $version = 4; + if ( version_compare( $configuration->get_acf_version(), 5, '>=' ) ) { + $version = 5; + } + require_once AC_SEO_ACF_ANALYSIS_PLUGIN_PATH . '/tests/js/system/data/acf' . $version . '.php'; } From aae6ea35afda8534504a3e68758567f3db623c2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Kr=C3=A4ftner?= Date: Mon, 11 Dec 2017 12:49:17 +0100 Subject: [PATCH 04/10] remove bootstrap code again (slipped back in when merging develop in) --- inc/class-ac-yoast-seo-acf-content-analysis.php | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/inc/class-ac-yoast-seo-acf-content-analysis.php b/inc/class-ac-yoast-seo-acf-content-analysis.php index dd448693..25248478 100755 --- a/inc/class-ac-yoast-seo-acf-content-analysis.php +++ b/inc/class-ac-yoast-seo-acf-content-analysis.php @@ -28,10 +28,6 @@ public function admin_init() { $this->boot(); - if ( defined( 'AC_YOAST_ACF_ANALYSIS_ENVIRONMENT' ) && 'development' === AC_YOAST_ACF_ANALYSIS_ENVIRONMENT ) { - $this->boot_dev(); - } - $this->register_config_filters(); $assets = new Yoast_ACF_Analysis_Assets(); @@ -76,14 +72,6 @@ public function boot() { $registry->add( 'config', $configuration ); } - /** - * Boots the plugin for dev environment. - */ - public function boot_dev() { - $version = ( -1 === version_compare( get_option( 'acf_version' ), 5 ) ) ? '4' : '5'; - require_once AC_SEO_ACF_ANALYSIS_PLUGIN_PATH . '/tests/js/system/data/acf' . $version . '.php'; - } - /** * Filters the Scraper Configuration to add the headlines configuration for the text scraper. */ From c9004b28d38806a7f73ab16bb0691f26c3e39efb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Kr=C3=A4ftner?= Date: Thu, 21 Dec 2017 11:01:29 +0100 Subject: [PATCH 05/10] fix CS --- tests/js/system/data/test-data-loader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/js/system/data/test-data-loader.php b/tests/js/system/data/test-data-loader.php index 2bb3ed25..6cba113d 100644 --- a/tests/js/system/data/test-data-loader.php +++ b/tests/js/system/data/test-data-loader.php @@ -28,7 +28,7 @@ 'accepted_args' => 1, ); -}else{ +} else { add_action( $hook_name, $function_name, 11 ); From d8fbee04c3c7600baca90a92618d77985253d2b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Kr=C3=A4ftner?= Date: Thu, 21 Dec 2017 11:03:18 +0100 Subject: [PATCH 06/10] negated check and return for condition --- tests/js/system/data/test-data-loader.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/js/system/data/test-data-loader.php b/tests/js/system/data/test-data-loader.php index 6cba113d..34011748 100644 --- a/tests/js/system/data/test-data-loader.php +++ b/tests/js/system/data/test-data-loader.php @@ -36,18 +36,18 @@ function yoast_acf_analysis_test_data_loader() { - if ( defined( 'AC_YOAST_ACF_ANALYSIS_ENVIRONMENT' ) && 'development' === AC_YOAST_ACF_ANALYSIS_ENVIRONMENT ) { - - $registry = Yoast_ACF_Analysis_Facade::get_registry(); - $configuration = $registry->get( 'config' ); - - $version = 4; - if ( version_compare( $configuration->get_acf_version(), 5, '>=' ) ) { - $version = 5; - } + if ( ! defined( 'AC_YOAST_ACF_ANALYSIS_ENVIRONMENT' ) || 'development' !== AC_YOAST_ACF_ANALYSIS_ENVIRONMENT ) { + return; + } - require_once AC_SEO_ACF_ANALYSIS_PLUGIN_PATH . '/tests/js/system/data/acf' . $version . '.php'; + $registry = Yoast_ACF_Analysis_Facade::get_registry(); + $configuration = $registry->get( 'config' ); + $version = 4; + if ( version_compare( $configuration->get_acf_version(), 5, '>=' ) ) { + $version = 5; } + require_once AC_SEO_ACF_ANALYSIS_PLUGIN_PATH . '/tests/js/system/data/acf' . $version . '.php'; + } From 0198d956b3ee263db0a28f0c51be41697b97e16b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Kr=C3=A4ftner?= Date: Thu, 21 Dec 2017 11:15:01 +0100 Subject: [PATCH 07/10] simplify autoloader selection --- yoast-acf-analysis.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/yoast-acf-analysis.php b/yoast-acf-analysis.php index 7b74a60c..273dd078 100755 --- a/yoast-acf-analysis.php +++ b/yoast-acf-analysis.php @@ -27,14 +27,14 @@ define( 'AC_SEO_ACF_ANALYSIS_PLUGIN_NAME', untrailingslashit( plugin_basename( __FILE__ ) ) ); } -if ( version_compare( PHP_VERSION, '5.3.2', '>=' ) ) { - if ( is_file( AC_SEO_ACF_ANALYSIS_PLUGIN_PATH . '/vendor/autoload.php' ) ) { - require AC_SEO_ACF_ANALYSIS_PLUGIN_PATH . '/vendor/autoload.php'; - } -} else { - if ( is_file( AC_SEO_ACF_ANALYSIS_PLUGIN_PATH . '/vendor/autoload_52.php' ) ) { - require AC_SEO_ACF_ANALYSIS_PLUGIN_PATH . '/vendor/autoload_52.php'; - } +$autoload_file = '/vendor/autoload.php'; + +if ( version_compare( PHP_VERSION, '5.3.2', '<' ) ) { + $autoload_file = '/vendor/autoload_52.php'; +} + +if ( is_file( AC_SEO_ACF_ANALYSIS_PLUGIN_PATH . $autoload_file ) ) { + require AC_SEO_ACF_ANALYSIS_PLUGIN_PATH . $autoload_file; } /** From 6be2ea3612c8d2bf5494476c3fd9b41eea1247c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Kr=C3=A4ftner?= Date: Thu, 21 Dec 2017 11:44:38 +0100 Subject: [PATCH 08/10] remove Plugin API workaround because file is loaded after it is ready anyway --- tests/js/system/data/test-data-loader.php | 34 +---------------------- 1 file changed, 1 insertion(+), 33 deletions(-) diff --git a/tests/js/system/data/test-data-loader.php b/tests/js/system/data/test-data-loader.php index 34011748..dcf0c907 100644 --- a/tests/js/system/data/test-data-loader.php +++ b/tests/js/system/data/test-data-loader.php @@ -1,38 +1,6 @@ $function_name, - 'accepted_args' => 1, - ); - -} else { - - add_action( $hook_name, $function_name, 11 ); - -} +add_action( 'admin_init', 'yoast_acf_analysis_test_data_loader', 11 ); function yoast_acf_analysis_test_data_loader() { From 712b2eaa5fe62eaf78fd5e9a990d61594d840f9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Kr=C3=A4ftner?= Date: Thu, 21 Dec 2017 12:05:38 +0100 Subject: [PATCH 09/10] Mock add_action if Plugin API is not available (e.g. in Unit Tests) --- tests/js/system/data/test-data-loader.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/js/system/data/test-data-loader.php b/tests/js/system/data/test-data-loader.php index dcf0c907..23d9fcbf 100644 --- a/tests/js/system/data/test-data-loader.php +++ b/tests/js/system/data/test-data-loader.php @@ -1,5 +1,10 @@ Date: Thu, 21 Dec 2017 12:14:14 +0100 Subject: [PATCH 10/10] Only load test data when Plugin API is ready (not needed in Unit Tests) --- tests/js/system/data/test-data-loader.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/js/system/data/test-data-loader.php b/tests/js/system/data/test-data-loader.php index 23d9fcbf..0ad4dc46 100644 --- a/tests/js/system/data/test-data-loader.php +++ b/tests/js/system/data/test-data-loader.php @@ -1,12 +1,10 @@