-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove testing code from plugin #117
Changes from 5 commits
98a36c5
38ff8e1
f268760
b80d0e1
aae6ea3
c9004b2
d8fbee0
0198d95
6be2ea3
712b2ea
b7dd4a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
/** | ||
* This file is loaded by Composer autoload-dev, and that happens before `add_action` is available. | ||
* So we "manually" add in global `$wp_filter` the function that loads translations. | ||
*/ | ||
global $wp_filter; | ||
|
||
$hook_name = 'admin_init'; | ||
$function_name = 'yoast_acf_analysis_test_data_loader'; | ||
|
||
if ( ! function_exists( 'add_action' ) ) { | ||
|
||
if ( ! is_array( $wp_filter ) ) { | ||
$wp_filter = array(); | ||
} | ||
|
||
if ( ! isset( $wp_filter[ $hook_name ] ) ) { | ||
$wp_filter[ $hook_name ] = array(); | ||
} | ||
|
||
if ( ! isset( $wp_filter[ $hook_name ][11] ) ) { | ||
$wp_filter[ $hook_name ][11] = array(); | ||
} | ||
|
||
$wp_filter[ $hook_name ][11][ $function_name ] = array( | ||
'function' => $function_name, | ||
'accepted_args' => 1, | ||
); | ||
|
||
}else{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CS: Missing spaces around the |
||
|
||
add_action( $hook_name, $function_name, 11 ); | ||
|
||
} | ||
|
||
function yoast_acf_analysis_test_data_loader() { | ||
|
||
if ( defined( 'AC_YOAST_ACF_ANALYSIS_ENVIRONMENT' ) && 'development' === AC_YOAST_ACF_ANALYSIS_ENVIRONMENT ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We prefer to have a negated condition check and do a |
||
|
||
$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'; | ||
|
||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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', '>=' ) ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be less complicated if you can create a variable to hold the file to be loaded. After that we only have to use one |
||
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 '<div class=\"error\"><p>$message</p></div>';" ) | ||
); | ||
} else { | ||
$ac_yoast_seo_acf_analysis = new AC_Yoast_SEO_ACF_Content_Analysis(); | ||
$ac_yoast_seo_acf_analysis->init(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tried to manually trigger the Monkey Brains setup method, to avoid having to use the ugly global WordPress mocking.
The following code snippet works as expected and removes all problems we have with the current approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, this code isn't mocking
add_action
but actually adds a filter by messing with the globals before the plugin API is ready.But I just realised that that isn't needed anyway because the autoloader only gets loaded after the Plugin API is ready anyway. So I can further simplify this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...and that was there for a reason because of course when running Unit Tests the Plugin API isn't ready. Your alternative approach is nice though. I just wrapped it inside a conditional now because otherwise
Brain\Monkey\setUp()
is also called during normal execution which needlessly loads Patchwork.