From 20ef0bb74693779be6f22b1afd0e3e1778de9853 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Kr=C3=A4ftner?= Date: Wed, 18 Oct 2017 15:29:33 +0200 Subject: [PATCH 1/4] Ensure no errors on CPTs without Yoast SEO metabox --- inc/class-ac-yoast-acf-content-analysis.php | 24 ++++++++++- tests/js/system/data/acf4.php | 38 +++++++++++++++++ tests/js/system/data/acf5.php | 46 +++++++++++++++++++++ tests/js/system/data/cpt-non-public.php | 9 ++++ tests/js/system/pages/WordPressHelper.js | 8 +++- tests/js/system/tests/general/cpt.js | 38 +++++++++++++++++ 6 files changed, 159 insertions(+), 4 deletions(-) create mode 100644 tests/js/system/data/cpt-non-public.php create mode 100644 tests/js/system/tests/general/cpt.js diff --git a/inc/class-ac-yoast-acf-content-analysis.php b/inc/class-ac-yoast-acf-content-analysis.php index ace0cb70..ba1b97da 100755 --- a/inc/class-ac-yoast-acf-content-analysis.php +++ b/inc/class-ac-yoast-acf-content-analysis.php @@ -14,6 +14,10 @@ class AC_Yoast_SEO_ACF_Content_Analysis { */ public function init() { add_action( 'admin_init', array( $this, 'admin_init' ) ); + + if ( $this->is_dev_environment() ) { + add_action( 'init', array( $this, 'add_cpt_for_tests' ) ); + } } /** @@ -30,7 +34,7 @@ public function admin_init() { $this->boot(); - if ( defined( 'AC_YOAST_ACF_ANALYSIS_ENVIRONMENT' ) && 'development' === AC_YOAST_ACF_ANALYSIS_ENVIRONMENT ) { + if ( $this->is_dev_environment() ) { $this->boot_dev(); } @@ -92,7 +96,7 @@ public function boot_dev() { protected function register_config_filters() { add_filter( Yoast_ACF_Analysis_Facade::get_filter_name( 'scraper_config' ), - array( $this, 'filter_scraper_config') + array( $this, 'filter_scraper_config' ) ); } @@ -223,4 +227,20 @@ protected function get_blacklist_type() { protected function get_blacklist_name() { return new Yoast_ACF_Analysis_String_Store(); } + + /** + * Adds a CPT for tests + */ + public function add_cpt_for_tests() { + require_once AC_SEO_ACF_ANALYSIS_PLUGIN_PATH . '/tests/js/system/data/cpt-non-public.php'; + } + + + /** + * @return bool + */ + protected function is_dev_environment() { + return ( defined( 'AC_YOAST_ACF_ANALYSIS_ENVIRONMENT' ) && 'development' === AC_YOAST_ACF_ANALYSIS_ENVIRONMENT ); + } + } diff --git a/tests/js/system/data/acf4.php b/tests/js/system/data/acf4.php index 3f4af7de..dd2c7fac 100644 --- a/tests/js/system/data/acf4.php +++ b/tests/js/system/data/acf4.php @@ -100,4 +100,42 @@ ), 'menu_order' => 0, )); + + register_field_group(array ( + 'id' => 'acf_non-public-cpt', + 'title' => 'Non Public CPT', + 'fields' => array ( + array ( + 'key' => 'field_59e897a8755dc', + 'label' => 'Text', + 'name' => 'yoast_acf_analysis_text', + 'type' => 'text', + 'default_value' => '', + 'placeholder' => '', + 'prepend' => '', + 'append' => '', + 'formatting' => 'html', + 'maxlength' => '', + ), + ), + 'location' => array ( + array ( + array ( + 'param' => 'post_type', + 'operator' => '==', + 'value' => 'test_non_public_cpt', + 'order_no' => 0, + 'group_no' => 0, + ), + ), + ), + 'options' => array ( + 'position' => 'normal', + 'layout' => 'no_box', + 'hide_on_screen' => array ( + ), + ), + 'menu_order' => 0, + )); + } diff --git a/tests/js/system/data/acf5.php b/tests/js/system/data/acf5.php index c373195e..acc0339f 100644 --- a/tests/js/system/data/acf5.php +++ b/tests/js/system/data/acf5.php @@ -336,4 +336,50 @@ 'description' => '', )); + acf_add_local_field_group(array ( + 'key' => 'group_59e89863c6498', + 'title' => 'Non Public CPT', + 'fields' => array ( + array ( + 'key' => 'field_59e897a8755dc', + 'label' => 'Text', + 'name' => 'yoast_acf_analysis_text', + 'type' => 'text', + 'value' => NULL, + 'instructions' => '', + 'required' => 0, + 'conditional_logic' => 0, + 'wrapper' => array ( + 'width' => '', + 'class' => '', + 'id' => '', + ), + 'default_value' => '', + 'placeholder' => '', + 'prepend' => '', + 'append' => '', + 'formatting' => 'html', + 'maxlength' => '', + ), + ), + 'location' => array ( + array ( + array ( + 'param' => 'post_type', + 'operator' => '==', + 'value' => 'test_non_public_cpt', + ), + ), + ), + 'menu_order' => 0, + 'position' => 'normal', + 'style' => 'seamless', + 'label_placement' => 'top', + 'instruction_placement' => 'label', + 'hide_on_screen' => array ( + ), + 'active' => 1, + 'description' => '', + )); + endif; \ No newline at end of file diff --git a/tests/js/system/data/cpt-non-public.php b/tests/js/system/data/cpt-non-public.php new file mode 100644 index 00000000..2db38f33 --- /dev/null +++ b/tests/js/system/data/cpt-non-public.php @@ -0,0 +1,9 @@ + false, + 'show_ui' => true, + 'supports' => array( 'thumbnail' ), + 'label' => 'Non Public CPT', +); + +register_post_type( 'test_non_public_cpt', $args ); diff --git a/tests/js/system/pages/WordPressHelper.js b/tests/js/system/pages/WordPressHelper.js index a54e45ce..1dc20927 100644 --- a/tests/js/system/pages/WordPressHelper.js +++ b/tests/js/system/pages/WordPressHelper.js @@ -27,8 +27,12 @@ module.exports = { this.click('@submitButton'); return this.waitForElementVisible('#adminmenu #menu-dashboard .current', 15000); }, - newPost: function(){ - this.api.url( this.api.launchUrl + '/wp/wp-admin/post-new.php' ); + newPost: function(cpt){ + if(cpt !== undefined){ + cpt = '?post_type=' + cpt; + } + cpt = cpt || ''; + this.api.url( this.api.launchUrl + '/wp/wp-admin/post-new.php' + cpt ); this.waitForElementVisible('body.post-new-php', 15000); return this.api.execute(function() { diff --git a/tests/js/system/tests/general/cpt.js b/tests/js/system/tests/general/cpt.js new file mode 100644 index 00000000..e924443b --- /dev/null +++ b/tests/js/system/tests/general/cpt.js @@ -0,0 +1,38 @@ +var simpleField = require('../../helpers/simpleField'); +var Logger = require('nightwatch/lib/util/logger.js'); + +module.exports = { + tags: ['acf4', 'acf5', 'cpt'], + + before: function (browser) { + var page = browser.page.WordPressHelper(); + page.newPost('test_non_public_cpt'); + }, + + beforeEach: function (browser) { + }, + + 'Custom Post Type (non public->no metabox)' : function (browser) { + browser.getLog('browser', function(logEntriesArray) { + + var errors = logEntriesArray.filter(function(log){ + return log.level === 'SEVERE'; + }); + + browser.assert.ok( errors.length === 0, "No JS errors thrown." ) + + var warnings = logEntriesArray.filter(function(log){ + return log.level === 'WARNING'; + }); + + warnings.forEach(function(log){ + console.log(Logger.colors.light_purple(' WARNING: ' + log.message)); + }); + + }); + }, + + after : function(browser) { + browser.end(); + } +}; From f2879dbd678ce034085f094d0d59b9f5d420e34c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Kr=C3=A4ftner?= Date: Fri, 20 Oct 2017 11:29:05 +0200 Subject: [PATCH 2/4] improve documentation --- inc/class-ac-yoast-acf-content-analysis.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/inc/class-ac-yoast-acf-content-analysis.php b/inc/class-ac-yoast-acf-content-analysis.php index ba1b97da..491d77f4 100755 --- a/inc/class-ac-yoast-acf-content-analysis.php +++ b/inc/class-ac-yoast-acf-content-analysis.php @@ -229,7 +229,7 @@ protected function get_blacklist_name() { } /** - * Adds a CPT for tests + * Adds a Custom Post Type used in the general/cpt Nightwatch test */ public function add_cpt_for_tests() { require_once AC_SEO_ACF_ANALYSIS_PLUGIN_PATH . '/tests/js/system/data/cpt-non-public.php'; @@ -237,6 +237,8 @@ public function add_cpt_for_tests() { /** + * Returns true if the plugin is currently running in a development environment. + * * @return bool */ protected function is_dev_environment() { From 7432e6f59f9f67dd07160f20340d0d6c4c36fa88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Kr=C3=A4ftner?= Date: Thu, 21 Dec 2017 12:50:14 +0100 Subject: [PATCH 3/4] move test CPT to new loader for tests --- tests/js/system/data/cpt-non-public.php | 9 --------- tests/js/system/data/test-data-loader.php | 9 +++++++++ 2 files changed, 9 insertions(+), 9 deletions(-) delete mode 100644 tests/js/system/data/cpt-non-public.php diff --git a/tests/js/system/data/cpt-non-public.php b/tests/js/system/data/cpt-non-public.php deleted file mode 100644 index 2db38f33..00000000 --- a/tests/js/system/data/cpt-non-public.php +++ /dev/null @@ -1,9 +0,0 @@ - false, - 'show_ui' => true, - 'supports' => array( 'thumbnail' ), - 'label' => 'Non Public CPT', -); - -register_post_type( 'test_non_public_cpt', $args ); diff --git a/tests/js/system/data/test-data-loader.php b/tests/js/system/data/test-data-loader.php index 0ad4dc46..21f713a5 100644 --- a/tests/js/system/data/test-data-loader.php +++ b/tests/js/system/data/test-data-loader.php @@ -21,4 +21,13 @@ function yoast_acf_analysis_test_data_loader() { require_once AC_SEO_ACF_ANALYSIS_PLUGIN_PATH . '/tests/js/system/data/acf' . $version . '.php'; + $args = array( + 'public' => false, + 'show_ui' => true, + 'supports' => array( 'thumbnail' ), + 'label' => 'Non Public CPT', + ); + + register_post_type( 'test_non_public_cpt', $args ); + } From 500e08acba2bee61634067c48457e761f34b988c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Kr=C3=A4ftner?= Date: Thu, 21 Dec 2017 12:53:42 +0100 Subject: [PATCH 4/4] fix remains of old test data loading --- 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. */