Skip to content

Commit ae9ea16

Browse files
authored
Merge pull request #117 from Yoast/stories/testing-code
Remove testing code from plugin
2 parents 88d873d + b7dd4a8 commit ae9ea16

4 files changed

Lines changed: 38 additions & 24 deletions

File tree

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@
5959
"autoload-dev": {
6060
"psr-4": {
6161
"Yoast\\AcfAnalysis\\Tests\\": "tests/php/unit"
62-
}
62+
},
63+
"files": [
64+
"tests/js/system/data/test-data-loader.php"
65+
]
6366
},
6467
"scripts": {
6568
"post-install-cmd": [

inc/class-ac-yoast-seo-acf-content-analysis.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ public function admin_init() {
2828

2929
$this->boot();
3030

31-
if ( defined( 'AC_YOAST_ACF_ANALYSIS_ENVIRONMENT' ) && 'development' === AC_YOAST_ACF_ANALYSIS_ENVIRONMENT ) {
32-
$this->boot_dev();
33-
}
34-
3531
$this->register_config_filters();
3632

3733
$assets = new Yoast_ACF_Analysis_Assets();
@@ -76,21 +72,6 @@ public function boot() {
7672
$registry->add( 'config', $configuration );
7773
}
7874

79-
/**
80-
* Boots the plugin for dev environment.
81-
*/
82-
public function boot_dev() {
83-
$registry = Yoast_ACF_Analysis_Facade::get_registry();
84-
$configuration = $registry->get( 'config' );
85-
86-
$version = 4;
87-
if ( version_compare( $configuration->get_acf_version(), 5, '>=' ) ) {
88-
$version = 5;
89-
}
90-
91-
require_once AC_SEO_ACF_ANALYSIS_PLUGIN_PATH . '/tests/js/system/data/acf' . $version . '.php';
92-
}
93-
9475
/**
9576
* Filters the Scraper Configuration to add the headlines configuration for the text scraper.
9677
*/
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
// Only load data when Plugin API is available because it is not needed in Unit Tests anyway.
4+
if ( function_exists( 'add_action' ) ) {
5+
add_action( 'admin_init', 'yoast_acf_analysis_test_data_loader', 11 );
6+
}
7+
8+
function yoast_acf_analysis_test_data_loader() {
9+
10+
if ( ! defined( 'AC_YOAST_ACF_ANALYSIS_ENVIRONMENT' ) || 'development' !== AC_YOAST_ACF_ANALYSIS_ENVIRONMENT ) {
11+
return;
12+
}
13+
14+
$registry = Yoast_ACF_Analysis_Facade::get_registry();
15+
$configuration = $registry->get( 'config' );
16+
17+
$version = 4;
18+
if ( version_compare( $configuration->get_acf_version(), 5, '>=' ) ) {
19+
$version = 5;
20+
}
21+
22+
require_once AC_SEO_ACF_ANALYSIS_PLUGIN_PATH . '/tests/js/system/data/acf' . $version . '.php';
23+
24+
}

yoast-acf-analysis.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,14 @@
2727
define( 'AC_SEO_ACF_ANALYSIS_PLUGIN_NAME', untrailingslashit( plugin_basename( __FILE__ ) ) );
2828
}
2929

30-
if ( is_file( AC_SEO_ACF_ANALYSIS_PLUGIN_PATH . '/vendor/autoload_52.php' ) ) {
31-
require AC_SEO_ACF_ANALYSIS_PLUGIN_PATH . '/vendor/autoload_52.php';
30+
$autoload_file = '/vendor/autoload.php';
3231

33-
$ac_yoast_seo_acf_analysis = new AC_Yoast_SEO_ACF_Content_Analysis();
34-
$ac_yoast_seo_acf_analysis->init();
32+
if ( version_compare( PHP_VERSION, '5.3.2', '<' ) ) {
33+
$autoload_file = '/vendor/autoload_52.php';
34+
}
35+
36+
if ( is_file( AC_SEO_ACF_ANALYSIS_PLUGIN_PATH . $autoload_file ) ) {
37+
require AC_SEO_ACF_ANALYSIS_PLUGIN_PATH . $autoload_file;
3538
}
3639

3740
/**
@@ -57,4 +60,7 @@ function yoast_acf_analysis_load_textdomain() {
5760
'admin_notices',
5861
create_function( '', "echo '<div class=\"error\"><p>$message</p></div>';" )
5962
);
63+
} else {
64+
$ac_yoast_seo_acf_analysis = new AC_Yoast_SEO_ACF_Content_Analysis();
65+
$ac_yoast_seo_acf_analysis->init();
6066
}

0 commit comments

Comments
 (0)