Skip to content

Commit

Permalink
Merge pull request #117 from Yoast/stories/testing-code
Browse files Browse the repository at this point in the history
Remove testing code from plugin
  • Loading branch information
moorscode authored Dec 21, 2017
2 parents 88d873d + b7dd4a8 commit ae9ea16
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 24 deletions.
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
19 changes: 0 additions & 19 deletions inc/class-ac-yoast-seo-acf-content-analysis.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -76,21 +72,6 @@ public function boot() {
$registry->add( 'config', $configuration );
}

/**
* Boots the plugin for dev environment.
*/
public function boot_dev() {
$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';
}

/**
* Filters the Scraper Configuration to add the headlines configuration for the text scraper.
*/
Expand Down
24 changes: 24 additions & 0 deletions tests/js/system/data/test-data-loader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

// Only load data when Plugin API is available because it is not needed in Unit Tests anyway.
if ( function_exists( 'add_action' ) ) {
add_action( 'admin_init', 'yoast_acf_analysis_test_data_loader', 11 );
}

function yoast_acf_analysis_test_data_loader() {

if ( ! defined( 'AC_YOAST_ACF_ANALYSIS_ENVIRONMENT' ) || 'development' !== AC_YOAST_ACF_ANALYSIS_ENVIRONMENT ) {
return;
}

$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';

}
14 changes: 10 additions & 4 deletions yoast-acf-analysis.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
$autoload_file = '/vendor/autoload.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', '<' ) ) {
$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;
}

/**
Expand All @@ -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();
}

0 comments on commit ae9ea16

Please sign in to comment.