From b2c48bce251465cc98605aae3f7bae6bba27ef9b Mon Sep 17 00:00:00 2001 From: Thijs van der heijden Date: Mon, 6 May 2024 15:48:20 +0200 Subject: [PATCH 1/4] Move generic site data into self contained objects. --- admin/formatter/class-metabox-formatter.php | 9 - .../class-post-metabox-formatter.php | 49 ------ .../class-term-metabox-formatter.php | 38 ---- admin/metabox/class-metabox.php | 43 +++-- admin/taxonomy/class-taxonomy.php | 15 +- .../integration-information-repository.php | 3 +- .../site/website-information-repository.php | 61 +++++++ .../framework/site/base-site-information.php | 114 ++++++++++++ .../framework/site/post-site-information.php | 90 ++++++++++ .../framework/site/term-site-information.php | 127 ++++++++++++++ .../Editors/Site_Information_Mocks_Trait.php | 40 +++++ .../Site/Post_Site_Information_Test.php | 145 +++++++++++++++ .../Site/Term_Site_Information_Test.php | 166 ++++++++++++++++++ 13 files changed, 779 insertions(+), 121 deletions(-) create mode 100644 src/editors/application/site/website-information-repository.php create mode 100644 src/editors/framework/site/base-site-information.php create mode 100644 src/editors/framework/site/post-site-information.php create mode 100644 src/editors/framework/site/term-site-information.php create mode 100644 tests/Unit/Doubles/Editors/Site_Information_Mocks_Trait.php create mode 100644 tests/Unit/Editors/Framework/Site/Post_Site_Information_Test.php create mode 100644 tests/Unit/Editors/Framework/Site/Term_Site_Information_Test.php diff --git a/admin/formatter/class-metabox-formatter.php b/admin/formatter/class-metabox-formatter.php index 3a248fd8d5d..0d0012a2d87 100644 --- a/admin/formatter/class-metabox-formatter.php +++ b/admin/formatter/class-metabox-formatter.php @@ -53,24 +53,15 @@ private function get_defaults() { $defaults = [ 'author_name' => get_the_author_meta( 'display_name' ), - 'site_name' => YoastSEO()->meta->for_current_page()->site_name, 'sitewide_social_image' => WPSEO_Options::get( 'og_default_image' ), - 'search_url' => '', - 'post_edit_url' => '', - 'base_url' => '', 'contentTab' => __( 'Readability', 'wordpress-seo' ), 'keywordTab' => __( 'Keyphrase:', 'wordpress-seo' ), 'removeKeyword' => __( 'Remove keyphrase', 'wordpress-seo' ), - 'contentLocale' => get_locale(), - 'userLocale' => get_user_locale(), 'translations' => $this->get_translations(), 'keyword_usage' => [], 'title_template' => '', 'metadesc_template' => '', 'intl' => $this->get_content_analysis_component_translations(), - 'isRtl' => is_rtl(), - 'isPremium' => YoastSEO()->helpers->product->is_premium(), - 'siteIconUrl' => get_site_icon_url(), 'showSocial' => [ 'facebook' => WPSEO_Options::get( 'opengraph', false ), 'twitter' => WPSEO_Options::get( 'twitter', false ), diff --git a/admin/formatter/class-post-metabox-formatter.php b/admin/formatter/class-post-metabox-formatter.php index aa4eb2f296f..b5ecc516dcc 100644 --- a/admin/formatter/class-post-metabox-formatter.php +++ b/admin/formatter/class-post-metabox-formatter.php @@ -62,9 +62,6 @@ public function use_social_templates() { public function get_values() { $values = [ - 'search_url' => $this->search_url(), - 'post_edit_url' => $this->edit_url(), - 'base_url' => $this->base_url_for_js(), 'metaDescriptionDate' => '', ]; @@ -106,52 +103,6 @@ protected function get_image_url() { return WPSEO_Image_Utils::get_first_usable_content_image_for_post( $this->post->ID ); } - /** - * Returns the url to search for keyword for the post. - * - * @return string - */ - private function search_url() { - return admin_url( 'edit.php?seo_kw_filter={keyword}' ); - } - - /** - * Returns the url to edit the taxonomy. - * - * @return string - */ - private function edit_url() { - return admin_url( 'post.php?post={id}&action=edit' ); - } - - /** - * Returns a base URL for use in the JS, takes permalink structure into account. - * - * @return string - */ - private function base_url_for_js() { - global $pagenow; - - // The default base is the home_url. - $base_url = home_url( '/', null ); - - if ( $pagenow === 'post-new.php' ) { - return $base_url; - } - - // If %postname% is the last tag, just strip it and use that as a base. - if ( preg_match( '#%postname%/?$#', $this->permalink ) === 1 ) { - $base_url = preg_replace( '#%postname%/?$#', '', $this->permalink ); - } - - // If %pagename% is the last tag, just strip it and use that as a base. - if ( preg_match( '#%pagename%/?$#', $this->permalink ) === 1 ) { - $base_url = preg_replace( '#%pagename%/?$#', '', $this->permalink ); - } - - return $base_url; - } - /** * Counts the number of given keywords used for other posts other than the given post_id. * diff --git a/admin/formatter/class-term-metabox-formatter.php b/admin/formatter/class-term-metabox-formatter.php index aa596cdcaa2..cec44471c1a 100644 --- a/admin/formatter/class-term-metabox-formatter.php +++ b/admin/formatter/class-term-metabox-formatter.php @@ -71,9 +71,6 @@ public function get_values() { // Todo: a column needs to be added on the termpages to add a filter for the keyword, so this can be used in the focus keyphrase doubles. if ( is_object( $this->term ) && property_exists( $this->term, 'taxonomy' ) ) { $values = [ - 'search_url' => $this->search_url(), - 'post_edit_url' => $this->edit_url(), - 'base_url' => $this->base_url_for_js(), 'taxonomy' => $this->term->taxonomy, 'keyword_usage' => $this->get_focus_keyword_usage(), 'title_template' => $this->get_title_template(), @@ -101,41 +98,6 @@ protected function get_image_url() { return WPSEO_Image_Utils::get_first_content_image_for_term( $this->term->term_id ); } - /** - * Returns the url to search for keyword for the taxonomy. - * - * @return string - */ - private function search_url() { - return admin_url( 'edit-tags.php?taxonomy=' . $this->term->taxonomy . '&seo_kw_filter={keyword}' ); - } - - /** - * Returns the url to edit the taxonomy. - * - * @return string - */ - private function edit_url() { - return admin_url( 'term.php?action=edit&taxonomy=' . $this->term->taxonomy . '&tag_ID={id}' ); - } - - /** - * Returns a base URL for use in the JS, takes permalink structure into account. - * - * @return string - */ - private function base_url_for_js() { - - $base_url = home_url( '/', null ); - if ( ! WPSEO_Options::get( 'stripcategorybase', false ) ) { - if ( $this->taxonomy->rewrite ) { - $base_url = trailingslashit( $base_url . $this->taxonomy->rewrite['slug'] ); - } - } - - return $base_url; - } - /** * Counting the number of given keyword used for other term than given term_id. * diff --git a/admin/metabox/class-metabox.php b/admin/metabox/class-metabox.php index 7dc1329ff3d..c4ba2176f0c 100644 --- a/admin/metabox/class-metabox.php +++ b/admin/metabox/class-metabox.php @@ -5,14 +5,12 @@ * @package WPSEO\Admin */ -use Yoast\WP\SEO\Actions\Alert_Dismissal_Action; use Yoast\WP\SEO\Conditionals\Third_Party\Jetpack_Boost_Active_Conditional; use Yoast\WP\SEO\Conditionals\Third_Party\Jetpack_Boost_Not_Premium_Conditional; use Yoast\WP\SEO\Conditionals\WooCommerce_Conditional; -use Yoast\WP\SEO\Introductions\Infrastructure\Wistia_Embed_Permission_Repository; +use Yoast\WP\SEO\Editors\Application\Site\Website_Information_Repository; use Yoast\WP\SEO\Presenters\Admin\Alert_Presenter; use Yoast\WP\SEO\Presenters\Admin\Meta_Fields_Presenter; -use Yoast\WP\SEO\Promotions\Application\Promotion_Manager; /** * This class generates the metabox on the edit post / page as well as contains all page analysis functionality. @@ -285,12 +283,7 @@ public function wpseo_metabox_class( $classes ) { * @return array|bool|int> */ public function get_metabox_script_data() { - $permalink = ''; - - if ( is_object( $this->get_metabox_post() ) ) { - $permalink = get_sample_permalink( $this->get_metabox_post()->ID ); - $permalink = $permalink[0]; - } + $permalink = $this->get_permalink(); $post_formatter = new WPSEO_Metabox_Formatter( new WPSEO_Post_Metabox_Formatter( $this->get_metabox_post(), [], $permalink ) @@ -913,8 +906,6 @@ public function enqueue() { 'log_level' => WPSEO_Utils::get_analysis_worker_log_level(), ]; - $alert_dismissal_action = YoastSEO()->classes->get( Alert_Dismissal_Action::class ); - $dismissed_alerts = $alert_dismissal_action->all_dismissed(); $woocommerce_conditional = new WooCommerce_Conditional(); $woocommerce_active = $woocommerce_conditional->is_met(); $wpseo_plugin_availability_checker = new WPSEO_Plugin_Availability(); @@ -936,20 +927,20 @@ public function enqueue() { 'plugins' => $plugins_script_data, 'worker' => $worker_script_data, ], - 'dismissedAlerts' => $dismissed_alerts, - 'currentPromotions' => YoastSEO()->classes->get( Promotion_Manager::class )->get_current_promotions(), - 'webinarIntroBlockEditorUrl' => WPSEO_Shortlinker::get( 'https://yoa.st/webinar-intro-block-editor' ), - 'blackFridayBlockEditorUrl' => ( YoastSEO()->classes->get( Promotion_Manager::class )->is( 'black-friday-2023-checklist' ) ) ? WPSEO_Shortlinker::get( 'https://yoa.st/black-friday-checklist' ) : '', 'isJetpackBoostActive' => ( $is_block_editor ) ? YoastSEO()->classes->get( Jetpack_Boost_Active_Conditional::class )->is_met() : false, 'isJetpackBoostNotPremium' => ( $is_block_editor ) ? YoastSEO()->classes->get( Jetpack_Boost_Not_Premium_Conditional::class )->is_met() : false, 'isWooCommerceSeoActive' => $woocommerce_seo_active, 'isWooCommerceActive' => $woocommerce_active, 'woocommerceUpsell' => get_post_type( $post_id ) === 'product' && ! $woocommerce_seo_active && $woocommerce_active, - 'linkParams' => WPSEO_Shortlinker::get_query_params(), - 'pluginUrl' => plugins_url( '', WPSEO_FILE ), - 'wistiaEmbedPermission' => YoastSEO()->classes->get( Wistia_Embed_Permission_Repository::class )->get_value_for_user( get_current_user_id() ), ]; - + /** + * The website information repository. + * + * @var $repo Website_Information_Repository + */ + $repo = YoastSEO()->classes->get( Website_Information_Repository::class ); + $repo->get_post_site_information()->set_permalink( $this->get_permalink() ); + $script_data = array_merge_recursive( $repo->get_post_site_information()->get_site_information(), $script_data ); if ( post_type_supports( get_post_type(), 'thumbnail' ) ) { $asset_manager->enqueue_style( 'featured-image' ); @@ -1207,4 +1198,18 @@ public static function is_post_edit( $page ) { protected function get_product_title() { return YoastSEO()->helpers->product->get_product_name(); } + + /** + * @return mixed|string + */ + public function get_permalink() { + $permalink = ''; + + if ( is_object( $this->get_metabox_post() ) ) { + $permalink = get_sample_permalink( $this->get_metabox_post()->ID ); + $permalink = $permalink[0]; + } + + return $permalink; + } } diff --git a/admin/taxonomy/class-taxonomy.php b/admin/taxonomy/class-taxonomy.php index 423b02d9bb2..b7186c2698d 100644 --- a/admin/taxonomy/class-taxonomy.php +++ b/admin/taxonomy/class-taxonomy.php @@ -5,7 +5,7 @@ * @package WPSEO\Admin */ -use Yoast\WP\SEO\Introductions\Infrastructure\Wistia_Embed_Permission_Repository; +use Yoast\WP\SEO\Editors\Application\Site\Website_Information_Repository; use Yoast\WP\SEO\Presenters\Admin\Alert_Presenter; /** @@ -192,10 +192,17 @@ public function admin_enqueue_scripts() { 'postId' => $tag_id, 'termType' => $this->get_taxonomy(), 'usedKeywordsNonce' => wp_create_nonce( 'wpseo-keyword-usage' ), - 'linkParams' => WPSEO_Shortlinker::get_query_params(), - 'pluginUrl' => plugins_url( '', WPSEO_FILE ), - 'wistiaEmbedPermission' => YoastSEO()->classes->get( Wistia_Embed_Permission_Repository::class )->get_value_for_user( get_current_user_id() ), ]; + + /** + * The website information repository. + * + * @var $repo Website_Information_Repository + */ + $repo = YoastSEO()->classes->get( Website_Information_Repository::class ); + $repo->get_term_site_information()->set_term( get_term_by( 'id', $tag_id, $this::get_taxonomy() ) ); + $script_data = array_merge_recursive( $repo->get_term_site_information()->get_site_information(), $script_data ); + $asset_manager->localize_script( 'term-edit', 'wpseoScriptData', $script_data ); $asset_manager->enqueue_user_language_script(); } diff --git a/src/editors/application/integrations/integration-information-repository.php b/src/editors/application/integrations/integration-information-repository.php index 373cc0021d6..c066fc2f740 100644 --- a/src/editors/application/integrations/integration-information-repository.php +++ b/src/editors/application/integrations/integration-information-repository.php @@ -4,7 +4,6 @@ namespace Yoast\WP\SEO\Editors\Application\Integrations; use Yoast\WP\SEO\Editors\Domain\Integrations\Integration_Data_Provider_Interface; -use Yoast\WP\SEO\Editors\Framework\Analysis_Feature_Interface; /** * The repository to get all enabled integrations. @@ -16,7 +15,7 @@ class Integration_Information_Repository { /** * All plugin integrations. * - * @var Analysis_Feature_Interface[] $plugin_integrations + * @var Integration_Data_Provider_Interface[] $plugin_integrations */ private $plugin_integrations; diff --git a/src/editors/application/site/website-information-repository.php b/src/editors/application/site/website-information-repository.php new file mode 100644 index 00000000000..6ff099f9175 --- /dev/null +++ b/src/editors/application/site/website-information-repository.php @@ -0,0 +1,61 @@ +post_site_information = $post_site_information; + $this->term_site_information = $term_site_information; + } + + /** + * Returns the Post Site Information container. + * + * @return Post_Site_Information + */ + public function get_post_site_information(): Post_Site_Information { + return $this->post_site_information; + } + + /** + * Returns the Term Site Information container. + * + * @return Term_Site_Information + */ + public function get_term_site_information(): Term_Site_Information { + return $this->term_site_information; + } +} diff --git a/src/editors/framework/site/base-site-information.php b/src/editors/framework/site/base-site-information.php new file mode 100644 index 00000000000..142994868f9 --- /dev/null +++ b/src/editors/framework/site/base-site-information.php @@ -0,0 +1,114 @@ +promotion_manager = $promotion_manager; + $this->short_link_helper = $short_link_helper; + $this->wistia_embed_permission_repository = $wistia_embed_permission_repository; + $this->meta = $meta; + $this->product_helper = $product_helper; + $this->alert_dismissal_action = $alert_dismissal_action; + } + + /** + * Returns site information that is the + * + * @throws Exception If an invalid user ID is supplied to the wistia repository. + * @return array + */ + public function get_site_information(): array { + $dismissed_alerts = $this->alert_dismissal_action->all_dismissed(); + + return [ + 'dismissedAlerts' => $dismissed_alerts, + 'currentPromotions' => $this->promotion_manager->get_current_promotions(), + 'webinarIntroBlockEditorUrl' => $this->short_link_helper->get( 'https://yoa.st/webinar-intro-block-editor' ), + 'blackFridayBlockEditorUrl' => ( $this->promotion_manager->is( 'black-friday-2023-checklist' ) ) ? $this->short_link_helper->get( 'https://yoa.st/black-friday-checklist' ) : '', + 'linkParams' => $this->short_link_helper->get_query_params(), + 'pluginUrl' => \plugins_url( '', \WPSEO_FILE ), + 'wistiaEmbedPermission' => $this->wistia_embed_permission_repository->get_value_for_user( \get_current_user_id() ), + + 'metabox' => [ + 'site_name' => $this->meta->for_current_page()->site_name, + 'contentLocale' => \get_locale(), + 'userLocale' => \get_user_locale(), + 'isRtl' => \is_rtl(), + 'isPremium' => $this->product_helper->is_premium(), + 'siteIconUrl' => \get_site_icon_url(), + ], + ]; + } +} diff --git a/src/editors/framework/site/post-site-information.php b/src/editors/framework/site/post-site-information.php new file mode 100644 index 00000000000..9f53f82c3cb --- /dev/null +++ b/src/editors/framework/site/post-site-information.php @@ -0,0 +1,90 @@ +permalink = $permalink; + } + + /** + * Returns post specific site information together with the generic site information. + * + * @return array + */ + public function get_site_information(): array { + $data = [ + 'metabox' => [ + 'search_url' => $this->search_url(), + 'post_edit_url' => $this->edit_url(), + 'base_url' => $this->base_url_for_js(), + ], + ]; + + return \array_merge_recursive( $data, parent::get_site_information() ); + } + + /** + * Returns the url to search for keyword for the post. + * + * @return string + */ + private function search_url(): string { + return \admin_url( 'edit.php?seo_kw_filter={keyword}' ); + } + + /** + * Returns the url to edit the taxonomy. + * + * @return string + */ + private function edit_url(): string { + return \admin_url( 'post.php?post={id}&action=edit' ); + } + + /** + * Returns a base URL for use in the JS, takes permalink structure into account. + * + * @return string + */ + private function base_url_for_js(): string { + global $pagenow; + + // The default base is the home_url. + $base_url = \home_url( '/', null ); + + if ( $pagenow === 'post-new.php' ) { + return $base_url; + } + + // If %postname% is the last tag, just strip it and use that as a base. + if ( \preg_match( '#%postname%/?$#', $this->permalink ) === 1 ) { + $base_url = \preg_replace( '#%postname%/?$#', '', $this->permalink ); + } + + // If %pagename% is the last tag, just strip it and use that as a base. + if ( \preg_match( '#%pagename%/?$#', $this->permalink ) === 1 ) { + $base_url = \preg_replace( '#%pagename%/?$#', '', $this->permalink ); + } + + return $base_url; + } +} diff --git a/src/editors/framework/site/term-site-information.php b/src/editors/framework/site/term-site-information.php new file mode 100644 index 00000000000..2d11ffba295 --- /dev/null +++ b/src/editors/framework/site/term-site-information.php @@ -0,0 +1,127 @@ +options_helper = $options_helper; + } + + /** + * Sets the term for the information object and retrieves its taxonomy. + * + * @param WP_Term|string|false $term The term. + * + * @return void + */ + public function set_term( $term ) { + $this->term = $term; + $this->taxonomy = \get_taxonomy( $term->taxonomy ); + } + + /** + * Returns term specific site information together with the generic site information. + * + * @return array + */ + public function get_site_information(): array { + $data = [ + 'metabox' => [ + 'search_url' => $this->search_url(), + 'post_edit_url' => $this->edit_url(), + 'base_url' => $this->base_url_for_js(), + ], + ]; + + return \array_merge_recursive( $data, parent::get_site_information() ); + } + + /** + * Returns the url to search for keyword for the taxonomy. + * + * @return string + */ + private function search_url(): string { + return \admin_url( 'edit-tags.php?taxonomy=' . $this->term->taxonomy . '&seo_kw_filter={keyword}' ); + } + + /** + * Returns the url to edit the taxonomy. + * + * @return string + */ + private function edit_url(): string { + return \admin_url( 'term.php?action=edit&taxonomy=' . $this->term->taxonomy . '&tag_ID={id}' ); + } + + /** + * Returns a base URL for use in the JS, takes permalink structure into account. + * + * @return string + */ + private function base_url_for_js(): string { + $base_url = \home_url( '/', null ); + if ( ! $this->options_helper->get( 'stripcategorybase', false ) ) { + if ( $this->taxonomy->rewrite ) { + $base_url = \trailingslashit( $base_url . $this->taxonomy->rewrite['slug'] ); + } + } + + return $base_url; + } +} diff --git a/tests/Unit/Doubles/Editors/Site_Information_Mocks_Trait.php b/tests/Unit/Doubles/Editors/Site_Information_Mocks_Trait.php new file mode 100644 index 00000000000..b0685b617cf --- /dev/null +++ b/tests/Unit/Doubles/Editors/Site_Information_Mocks_Trait.php @@ -0,0 +1,40 @@ +site_name = 'examepl.com'; + $locale = 'nl_NL'; + + Monkey\Functions\expect( 'plugins_url' )->andReturn( $plugin_url ); + Monkey\Functions\expect( 'get_current_user_id' )->andReturn( 1 ); + Monkey\Functions\expect( 'get_locale' )->andReturn( $locale ); + Monkey\Functions\expect( 'get_user_locale' )->andReturn( $locale ); + Monkey\Functions\expect( 'is_rtl' )->andReturnFalse(); + Monkey\Functions\expect( 'get_site_icon_url' )->andReturn( 'https://example.org' ); + + $this->alert_dismissal_action->expects( 'all_dismissed' )->andReturn( $dismissed_alerts ); + $this->promotion_manager->expects( 'get_current_promotions' )->andReturn( $promotions ); + $this->promotion_manager->expects( 'is' )->andReturnFalse(); + $this->short_link_helper->expects( 'get' )->andReturn( $short_link ); + $this->short_link_helper->expects( 'get_query_params' )->andReturn( $query_params ); + $this->wistia_embed_repo->expects( 'get_value_for_user' )->with( 1 )->andReturnTrue(); + $this->meta_surface->expects( 'for_current_page' )->andReturn( $meta_surface ); + $this->product_helper->expects( 'is_premium' )->andReturnTrue(); + } +} diff --git a/tests/Unit/Editors/Framework/Site/Post_Site_Information_Test.php b/tests/Unit/Editors/Framework/Site/Post_Site_Information_Test.php new file mode 100644 index 00000000000..4ade86f0728 --- /dev/null +++ b/tests/Unit/Editors/Framework/Site/Post_Site_Information_Test.php @@ -0,0 +1,145 @@ +promotion_manager = Mockery::mock( Promotion_Manager::class ); + $this->short_link_helper = Mockery::mock( Short_Link_Helper::class ); + $this->wistia_embed_repo = Mockery::mock( Wistia_Embed_Permission_Repository::class ); + $this->meta_surface = Mockery::mock( Meta_Surface::class ); + $this->product_helper = Mockery::mock( Product_Helper::class ); + $this->alert_dismissal_action = Mockery::mock( Alert_Dismissal_Action::class ); + + $this->instance = new Post_Site_Information( $this->promotion_manager, $this->short_link_helper, $this->wistia_embed_repo, $this->meta_surface, $this->product_helper, $this->alert_dismissal_action ); + } + + /** + * Tests the get_site_information. + * + * @covers ::__construct + * @covers ::get_site_information + * @covers ::search_url + * @covers ::base_url_for_js + * @covers ::edit_url + * @covers ::set_permalink + * + * @return void + */ + public function test_site_information() { + $this->instance->set_permalink( 'perma' ); + $this->set_mocks(); + $expected = [ + 'metabox' => [ + 'search_url' => 'https://example.org', + 'post_edit_url' => 'https://example.org', + 'base_url' => 'https://example.org', + 'site_name' => 'examepl.com', + 'contentLocale' => 'nl_NL', + 'userLocale' => 'nl_NL', + 'isRtl' => false, + 'isPremium' => true, + 'siteIconUrl' => 'https://example.org', + ], + 'dismissedAlerts' => [ + 'the alert', + ], + 'currentPromotions' => [ + 'the promotion', + 'another one', + ], + 'webinarIntroBlockEditorUrl' => 'https://expl.c', + 'blackFridayBlockEditorUrl' => '', + 'linkParams' => [ + 'param', + 'param2', + ], + 'pluginUrl' => '/location', + 'wistiaEmbedPermission' => true, + + ]; + + Monkey\Functions\expect( 'admin_url' )->andReturn( 'https://example.org' ); + Monkey\Functions\expect( 'home_url' )->andReturn( 'https://example.org' ); + + $this->assertSame( $expected, $this->instance->get_site_information() ); + } +} diff --git a/tests/Unit/Editors/Framework/Site/Term_Site_Information_Test.php b/tests/Unit/Editors/Framework/Site/Term_Site_Information_Test.php new file mode 100644 index 00000000000..30b90756708 --- /dev/null +++ b/tests/Unit/Editors/Framework/Site/Term_Site_Information_Test.php @@ -0,0 +1,166 @@ +options_helper = Mockery::mock( Options_Helper::class ); + $this->promotion_manager = Mockery::mock( Promotion_Manager::class ); + $this->short_link_helper = Mockery::mock( Short_Link_Helper::class ); + $this->wistia_embed_repo = Mockery::mock( Wistia_Embed_Permission_Repository::class ); + $this->meta_surface = Mockery::mock( Meta_Surface::class ); + $this->product_helper = Mockery::mock( Product_Helper::class ); + $this->alert_dismissal_action = Mockery::mock( Alert_Dismissal_Action::class ); + + $this->instance = new Term_Site_Information( $this->options_helper, $this->promotion_manager, $this->short_link_helper, $this->wistia_embed_repo, $this->meta_surface, $this->product_helper, $this->alert_dismissal_action ); + } + + /** + * Tests the get_site_information. + * + * @covers ::__construct + * @covers ::get_site_information + * @covers ::search_url + * @covers ::base_url_for_js + * @covers ::edit_url + * @covers ::set_term + * + * @return void + */ + public function test_site_information() { + $taxonomy = Mockery::mock( WP_Taxonomy::class )->makePartial(); + $taxonomy->rewrite = false; + $mock_term = Mockery::mock( WP_Term::class )->makePartial(); + $mock_term->taxonomy = 'tax'; + $mock_term->term_id = 1; + + Monkey\Functions\expect( 'get_taxonomy' )->andReturn( $taxonomy ); + + $this->instance->set_term( $mock_term ); + $this->options_helper->expects( 'get' )->with( 'stripcategorybase', false )->andReturnFalse(); + + $this->set_mocks(); + $expected = [ + 'metabox' => [ + 'search_url' => 'https://example.org', + 'post_edit_url' => 'https://example.org', + 'base_url' => 'https://example.org', + 'site_name' => 'examepl.com', + 'contentLocale' => 'nl_NL', + 'userLocale' => 'nl_NL', + 'isRtl' => false, + 'isPremium' => true, + 'siteIconUrl' => 'https://example.org', + ], + 'dismissedAlerts' => [ + 'the alert', + ], + 'currentPromotions' => [ + 'the promotion', + 'another one', + ], + 'webinarIntroBlockEditorUrl' => 'https://expl.c', + 'blackFridayBlockEditorUrl' => '', + 'linkParams' => [ + 'param', + 'param2', + ], + 'pluginUrl' => '/location', + 'wistiaEmbedPermission' => true, + + ]; + + Monkey\Functions\expect( 'admin_url' )->andReturn( 'https://example.org' ); + Monkey\Functions\expect( 'home_url' )->andReturn( 'https://example.org' ); + + $this->assertSame( $expected, $this->instance->get_site_information() ); + } +} From ce1957272e0cdcdbdb96bcae4d519f15ff97edc4 Mon Sep 17 00:00:00 2001 From: Thijs van der heijden Date: Tue, 7 May 2024 09:50:59 +0200 Subject: [PATCH 2/4] Add legacy non legacy difference. --- admin/metabox/class-metabox.php | 4 +- .../site/site-information-interface.php | 21 ++++++ .../framework/site/base-site-information.php | 32 ++++++++- .../framework/site/post-site-information.php | 25 +++++-- .../framework/site/term-site-information.php | 17 ++++- .../Site/Post_Site_Information_Test.php | 58 +++++++++++++-- .../Site/Term_Site_Information_Test.php | 70 ++++++++++++++++--- 7 files changed, 202 insertions(+), 25 deletions(-) create mode 100644 src/editors/domain/site/site-information-interface.php diff --git a/admin/metabox/class-metabox.php b/admin/metabox/class-metabox.php index c4ba2176f0c..0be2f9ae3b5 100644 --- a/admin/metabox/class-metabox.php +++ b/admin/metabox/class-metabox.php @@ -1200,7 +1200,9 @@ protected function get_product_title() { } /** - * @return mixed|string + * Gets the permalink. + * + * @return string */ public function get_permalink() { $permalink = ''; diff --git a/src/editors/domain/site/site-information-interface.php b/src/editors/domain/site/site-information-interface.php new file mode 100644 index 00000000000..01c3abb6fd6 --- /dev/null +++ b/src/editors/domain/site/site-information-interface.php @@ -0,0 +1,21 @@ + + */ + public function get_site_information(): array; + + /** + * Returns specific site information together with the generic site information compatible with a legacy way. + * + * @return array + */ + public function get_legacy_site_information(): array; +} diff --git a/src/editors/framework/site/base-site-information.php b/src/editors/framework/site/base-site-information.php index 142994868f9..6cbae89c8a8 100644 --- a/src/editors/framework/site/base-site-information.php +++ b/src/editors/framework/site/base-site-information.php @@ -4,6 +4,7 @@ use Exception; use Yoast\WP\SEO\Actions\Alert_Dismissal_Action; +use Yoast\WP\SEO\Editors\Domain\Site\Site_Information_Interface; use Yoast\WP\SEO\Helpers\Product_Helper; use Yoast\WP\SEO\Helpers\Short_Link_Helper; use Yoast\WP\SEO\Introductions\Infrastructure\Wistia_Embed_Permission_Repository; @@ -13,7 +14,7 @@ /** * The Base_Site_Information class. */ -abstract class Base_Site_Information { +abstract class Base_Site_Information implements Site_Information_Interface { /** * The alert dismissal action. @@ -62,7 +63,8 @@ abstract class Base_Site_Information { * * @param Promotion_Manager $promotion_manager The promotion manager. * @param Short_Link_Helper $short_link_helper The short link helper. - * @param Wistia_Embed_Permission_Repository $wistia_embed_permission_repository The wistia embed permission repository. + * @param Wistia_Embed_Permission_Repository $wistia_embed_permission_repository The wistia embed permission + * repository. * @param Meta_Surface $meta The meta surface. * @param Product_Helper $product_helper The product helper. * @param Alert_Dismissal_Action $alert_dismissal_action The alert dismissal action. @@ -92,6 +94,32 @@ public function __construct( public function get_site_information(): array { $dismissed_alerts = $this->alert_dismissal_action->all_dismissed(); + return [ + 'dismissedAlerts' => $dismissed_alerts, + 'currentPromotions' => $this->promotion_manager->get_current_promotions(), + 'webinarIntroBlockEditorUrl' => $this->short_link_helper->get( 'https://yoa.st/webinar-intro-block-editor' ), + 'blackFridayBlockEditorUrl' => ( $this->promotion_manager->is( 'black-friday-2023-checklist' ) ) ? $this->short_link_helper->get( 'https://yoa.st/black-friday-checklist' ) : '', + 'linkParams' => $this->short_link_helper->get_query_params(), + 'pluginUrl' => \plugins_url( '', \WPSEO_FILE ), + 'wistiaEmbedPermission' => $this->wistia_embed_permission_repository->get_value_for_user( \get_current_user_id() ), + 'site_name' => $this->meta->for_current_page()->site_name, + 'contentLocale' => \get_locale(), + 'userLocale' => \get_user_locale(), + 'isRtl' => \is_rtl(), + 'isPremium' => $this->product_helper->is_premium(), + 'siteIconUrl' => \get_site_icon_url(), + ]; + } + + /** + * Returns site information that is the + * + * @throws Exception If an invalid user ID is supplied to the wistia repository. + * @return array + */ + public function get_legacy_site_information(): array { + $dismissed_alerts = $this->alert_dismissal_action->all_dismissed(); + return [ 'dismissedAlerts' => $dismissed_alerts, 'currentPromotions' => $this->promotion_manager->get_current_promotions(), diff --git a/src/editors/framework/site/post-site-information.php b/src/editors/framework/site/post-site-information.php index 9f53f82c3cb..741ec9412e8 100644 --- a/src/editors/framework/site/post-site-information.php +++ b/src/editors/framework/site/post-site-information.php @@ -30,16 +30,31 @@ public function set_permalink( string $permalink ): void { * * @return array */ - public function get_site_information(): array { + public function get_legacy_site_information(): array { $data = [ 'metabox' => [ - 'search_url' => $this->search_url(), - 'post_edit_url' => $this->edit_url(), - 'base_url' => $this->base_url_for_js(), + 'search_url' => $this->search_url(), + 'post_edit_url' => $this->edit_url(), + 'base_url' => $this->base_url_for_js(), ], ]; - return \array_merge_recursive( $data, parent::get_site_information() ); + return \array_merge_recursive( $data, parent::get_legacy_site_information() ); + } + + /** + * Returns post specific site information together with the generic site information. + * + * @return array + */ + public function get_site_information(): array { + $data = [ + 'search_url' => $this->search_url(), + 'post_edit_url' => $this->edit_url(), + 'base_url' => $this->base_url_for_js(), + ]; + + return \array_merge( $data, parent::get_site_information() ); } /** diff --git a/src/editors/framework/site/term-site-information.php b/src/editors/framework/site/term-site-information.php index 2d11ffba295..939b36007d5 100644 --- a/src/editors/framework/site/term-site-information.php +++ b/src/editors/framework/site/term-site-information.php @@ -80,6 +80,21 @@ public function set_term( $term ) { * @return array */ public function get_site_information(): array { + $data = [ + 'search_url' => $this->search_url(), + 'post_edit_url' => $this->edit_url(), + 'base_url' => $this->base_url_for_js(), + ]; + + return \array_merge_recursive( $data, parent::get_site_information() ); + } + + /** + * Returns term specific site information together with the generic site information. + * + * @return array + */ + public function get_legacy_site_information(): array { $data = [ 'metabox' => [ 'search_url' => $this->search_url(), @@ -88,7 +103,7 @@ public function get_site_information(): array { ], ]; - return \array_merge_recursive( $data, parent::get_site_information() ); + return \array_merge_recursive( $data, parent::get_legacy_site_information() ); } /** diff --git a/tests/Unit/Editors/Framework/Site/Post_Site_Information_Test.php b/tests/Unit/Editors/Framework/Site/Post_Site_Information_Test.php index 4ade86f0728..2f72a31f2fa 100644 --- a/tests/Unit/Editors/Framework/Site/Post_Site_Information_Test.php +++ b/tests/Unit/Editors/Framework/Site/Post_Site_Information_Test.php @@ -90,13 +90,15 @@ protected function set_up() { $this->alert_dismissal_action = Mockery::mock( Alert_Dismissal_Action::class ); $this->instance = new Post_Site_Information( $this->promotion_manager, $this->short_link_helper, $this->wistia_embed_repo, $this->meta_surface, $this->product_helper, $this->alert_dismissal_action ); + $this->instance->set_permalink( 'perma' ); + $this->set_mocks(); } /** - * Tests the get_site_information. + * Tests the get_legacy_site_information. * * @covers ::__construct - * @covers ::get_site_information + * @covers ::get_legacy_site_information * @covers ::search_url * @covers ::base_url_for_js * @covers ::edit_url @@ -104,9 +106,7 @@ protected function set_up() { * * @return void */ - public function test_site_information() { - $this->instance->set_permalink( 'perma' ); - $this->set_mocks(); + public function test_legacy_site_information() { $expected = [ 'metabox' => [ 'search_url' => 'https://example.org', @@ -140,6 +140,54 @@ public function test_site_information() { Monkey\Functions\expect( 'admin_url' )->andReturn( 'https://example.org' ); Monkey\Functions\expect( 'home_url' )->andReturn( 'https://example.org' ); + $this->assertSame( $expected, $this->instance->get_legacy_site_information() ); + } + + /** + * Tests the get_site_information. + * + * @covers ::__construct + * @covers ::get_site_information + * @covers ::search_url + * @covers ::base_url_for_js + * @covers ::edit_url + * @covers ::set_permalink + * + * @return void + */ + public function test_site_information() { + $expected = [ + 'search_url' => 'https://example.org', + 'post_edit_url' => 'https://example.org', + 'base_url' => 'https://example.org', + + 'dismissedAlerts' => [ + 'the alert', + ], + 'currentPromotions' => [ + 'the promotion', + 'another one', + ], + 'webinarIntroBlockEditorUrl' => 'https://expl.c', + 'blackFridayBlockEditorUrl' => '', + 'linkParams' => [ + 'param', + 'param2', + ], + 'pluginUrl' => '/location', + 'wistiaEmbedPermission' => true, + 'site_name' => 'examepl.com', + 'contentLocale' => 'nl_NL', + 'userLocale' => 'nl_NL', + 'isRtl' => false, + 'isPremium' => true, + 'siteIconUrl' => 'https://example.org', + + ]; + + Monkey\Functions\expect( 'admin_url' )->andReturn( 'https://example.org' ); + Monkey\Functions\expect( 'home_url' )->andReturn( 'https://example.org' ); + $this->assertSame( $expected, $this->instance->get_site_information() ); } } diff --git a/tests/Unit/Editors/Framework/Site/Term_Site_Information_Test.php b/tests/Unit/Editors/Framework/Site/Term_Site_Information_Test.php index 30b90756708..310200fd200 100644 --- a/tests/Unit/Editors/Framework/Site/Term_Site_Information_Test.php +++ b/tests/Unit/Editors/Framework/Site/Term_Site_Information_Test.php @@ -100,7 +100,19 @@ protected function set_up() { $this->product_helper = Mockery::mock( Product_Helper::class ); $this->alert_dismissal_action = Mockery::mock( Alert_Dismissal_Action::class ); - $this->instance = new Term_Site_Information( $this->options_helper, $this->promotion_manager, $this->short_link_helper, $this->wistia_embed_repo, $this->meta_surface, $this->product_helper, $this->alert_dismissal_action ); + $this->instance = new Term_Site_Information( $this->options_helper, $this->promotion_manager, $this->short_link_helper, $this->wistia_embed_repo, $this->meta_surface, $this->product_helper, $this->alert_dismissal_action ); + $taxonomy = Mockery::mock( WP_Taxonomy::class )->makePartial(); + $taxonomy->rewrite = false; + $mock_term = Mockery::mock( WP_Term::class )->makePartial(); + $mock_term->taxonomy = 'tax'; + $mock_term->term_id = 1; + + Monkey\Functions\expect( 'get_taxonomy' )->andReturn( $taxonomy ); + + $this->instance->set_term( $mock_term ); + $this->options_helper->expects( 'get' )->with( 'stripcategorybase', false )->andReturnFalse(); + + $this->set_mocks(); } /** @@ -116,18 +128,54 @@ protected function set_up() { * @return void */ public function test_site_information() { - $taxonomy = Mockery::mock( WP_Taxonomy::class )->makePartial(); - $taxonomy->rewrite = false; - $mock_term = Mockery::mock( WP_Term::class )->makePartial(); - $mock_term->taxonomy = 'tax'; - $mock_term->term_id = 1; + $expected = [ + 'search_url' => 'https://example.org', + 'post_edit_url' => 'https://example.org', + 'base_url' => 'https://example.org', - Monkey\Functions\expect( 'get_taxonomy' )->andReturn( $taxonomy ); + 'dismissedAlerts' => [ + 'the alert', + ], + 'currentPromotions' => [ + 'the promotion', + 'another one', + ], + 'webinarIntroBlockEditorUrl' => 'https://expl.c', + 'blackFridayBlockEditorUrl' => '', + 'linkParams' => [ + 'param', + 'param2', + ], + 'pluginUrl' => '/location', + 'wistiaEmbedPermission' => true, + 'site_name' => 'examepl.com', + 'contentLocale' => 'nl_NL', + 'userLocale' => 'nl_NL', + 'isRtl' => false, + 'isPremium' => true, + 'siteIconUrl' => 'https://example.org', + ]; - $this->instance->set_term( $mock_term ); - $this->options_helper->expects( 'get' )->with( 'stripcategorybase', false )->andReturnFalse(); + Monkey\Functions\expect( 'admin_url' )->andReturn( 'https://example.org' ); + Monkey\Functions\expect( 'home_url' )->andReturn( 'https://example.org' ); + + $this->assertSame( $expected, $this->instance->get_site_information() ); + } + + /** + * Tests the get_legacy_site_information. + * + * @covers ::__construct + * @covers ::get_legacy_site_information + * @covers ::search_url + * @covers ::base_url_for_js + * @covers ::edit_url + * @covers ::set_term + * + * @return void + */ + public function test_legacy_site_information() { - $this->set_mocks(); $expected = [ 'metabox' => [ 'search_url' => 'https://example.org', @@ -161,6 +209,6 @@ public function test_site_information() { Monkey\Functions\expect( 'admin_url' )->andReturn( 'https://example.org' ); Monkey\Functions\expect( 'home_url' )->andReturn( 'https://example.org' ); - $this->assertSame( $expected, $this->instance->get_site_information() ); + $this->assertSame( $expected, $this->instance->get_legacy_site_information() ); } } From 36c618ea1600a98eab60d1600639bb27b5f80ae6 Mon Sep 17 00:00:00 2001 From: Thijs van der heijden Date: Tue, 7 May 2024 12:12:45 +0200 Subject: [PATCH 3/4] Update tests. --- composer.json | 2 +- tests/Unit/Admin/User_Profile_Test.php | 1 - .../Site/Post_Site_Information_Test.php | 184 ++++++++++++++++++ tests/WP/Formatter/Metabox_Formatter_Test.php | 1 - .../Formatter/Post_Metabox_Formatter_Test.php | 85 -------- .../Formatter/Term_Metabox_Formatter_Test.php | 4 - 6 files changed, 185 insertions(+), 92 deletions(-) create mode 100644 tests/WP/Editors/Framework/Site/Post_Site_Information_Test.php diff --git a/composer.json b/composer.json index 5bad5b6086a..fda1dd8e7f7 100644 --- a/composer.json +++ b/composer.json @@ -92,7 +92,7 @@ "Yoast\\WP\\SEO\\Composer\\Actions::check_coding_standards" ], "check-cs-thresholds": [ - "@putenv YOASTCS_THRESHOLD_ERRORS=2549", + "@putenv YOASTCS_THRESHOLD_ERRORS=2548", "@putenv YOASTCS_THRESHOLD_WARNINGS=267", "Yoast\\WP\\SEO\\Composer\\Actions::check_cs_thresholds" ], diff --git a/tests/Unit/Admin/User_Profile_Test.php b/tests/Unit/Admin/User_Profile_Test.php index 9f70d799c26..7a8c945b7b5 100644 --- a/tests/Unit/Admin/User_Profile_Test.php +++ b/tests/Unit/Admin/User_Profile_Test.php @@ -2,7 +2,6 @@ namespace Yoast\WP\SEO\Tests\Unit\Admin; -use Brain\Monkey; use WPSEO_Admin_User_Profile; use Yoast\WP\SEO\Tests\Unit\TestCase; diff --git a/tests/WP/Editors/Framework/Site/Post_Site_Information_Test.php b/tests/WP/Editors/Framework/Site/Post_Site_Information_Test.php new file mode 100644 index 00000000000..47edfd1c382 --- /dev/null +++ b/tests/WP/Editors/Framework/Site/Post_Site_Information_Test.php @@ -0,0 +1,184 @@ +promotion_manager = \YoastSEO()->classes->get( Promotion_Manager::class ); + $this->short_link_helper = \YoastSEO()->helpers->short_link; + $this->wistia_embed_repo = Mockery::mock( Wistia_Embed_Permission_Repository::class ); + $this->wistia_embed_repo->expects( 'get_value_for_user' )->with( 0 )->andReturnTrue(); + $this->meta_surface = \YoastSEO()->meta; + $this->product_helper = \YoastSEO()->helpers->product; + $this->alert_dismissal_action = \YoastSEO()->classes->get( Alert_Dismissal_Action::class ); + + $this->instance = new Post_Site_Information( $this->promotion_manager, $this->short_link_helper, $this->wistia_embed_repo, $this->meta_surface, $this->product_helper, $this->alert_dismissal_action ); + $this->instance->set_permalink( 'perma' ); + } + + /** + * Tests the get_legacy_site_information. + * + * @covers ::__construct + * @covers ::get_legacy_site_information + * @covers ::search_url + * @covers ::base_url_for_js + * @covers ::edit_url + * @covers ::set_permalink + * + * @return void + */ + public function test_legacy_site_information() { + $expected = [ + 'metabox' => + [ + 'search_url' => 'http://example.org/wp-admin/edit.php?seo_kw_filter={keyword}', + 'post_edit_url' => 'http://example.org/wp-admin/post.php?post={id}&action=edit', + 'base_url' => 'http://example.org/', + 'site_name' => 'Test Blog', + 'contentLocale' => 'en_US', + 'userLocale' => 'en_US', + 'isRtl' => false, + 'isPremium' => false, + 'siteIconUrl' => '', + ], + 'dismissedAlerts' => false, + 'currentPromotions' => [], + 'webinarIntroBlockEditorUrl' => 'https://yoa.st/webinar-intro-block-editor?php_version=7.4&platform=wordpress&platform_version=6.6-alpha-57778-src&software=free&software_version=22.7-RC3&days_active=14&user_language=en_US', + 'blackFridayBlockEditorUrl' => '', + 'linkParams' => + [ + 'php_version' => '7.4', + 'platform' => 'wordpress', + 'platform_version' => '6.6-alpha-57778-src', + 'software' => 'free', + 'software_version' => '22.7-RC3', + 'days_active' => 14, + 'user_language' => 'en_US', + ], + 'pluginUrl' => 'http://example.org/wp-content/plugins/wordpress-seo', + 'wistiaEmbedPermission' => true, + ]; + + $this->assertSame( $expected, $this->instance->get_legacy_site_information() ); + } + + /** + * Tests the get_site_information. + * + * @covers ::__construct + * @covers ::get_site_information + * @covers ::search_url + * @covers ::base_url_for_js + * @covers ::edit_url + * @covers ::set_permalink + * + * @return void + */ + public function test_site_information() { + $expected = [ + 'search_url' => 'http://example.org/wp-admin/edit.php?seo_kw_filter={keyword}', + 'post_edit_url' => 'http://example.org/wp-admin/post.php?post={id}&action=edit', + 'base_url' => 'http://example.org/', + 'dismissedAlerts' => false, + 'currentPromotions' => [], + 'webinarIntroBlockEditorUrl' => 'https://yoa.st/webinar-intro-block-editor?php_version=7.4&platform=wordpress&platform_version=6.6-alpha-57778-src&software=free&software_version=22.7-RC3&days_active=14&user_language=en_US', + 'blackFridayBlockEditorUrl' => '', + 'linkParams' => + [ + 'php_version' => '7.4', + 'platform' => 'wordpress', + 'platform_version' => '6.6-alpha-57778-src', + 'software' => 'free', + 'software_version' => '22.7-RC3', + 'days_active' => 14, + 'user_language' => 'en_US', + ], + 'pluginUrl' => 'http://example.org/wp-content/plugins/wordpress-seo', + 'wistiaEmbedPermission' => true, + 'site_name' => 'Test Blog', + 'contentLocale' => 'en_US', + 'userLocale' => 'en_US', + 'isRtl' => false, + 'isPremium' => false, + 'siteIconUrl' => '', + + ]; + + $this->assertSame( $expected, $this->instance->get_site_information() ); + } +} diff --git a/tests/WP/Formatter/Metabox_Formatter_Test.php b/tests/WP/Formatter/Metabox_Formatter_Test.php index 60c4225ad1f..80aa4a9ba5c 100644 --- a/tests/WP/Formatter/Metabox_Formatter_Test.php +++ b/tests/WP/Formatter/Metabox_Formatter_Test.php @@ -34,7 +34,6 @@ public function test_getting_the_values() { $result = $class_instance->get_values(); $this->assertEquals( 'Readability', $result['contentTab'] ); - $this->assertTrue( \array_key_exists( 'contentLocale', $result ) ); $this->assertTrue( \array_key_exists( 'translations', $result ) ); $this->assertTrue( \is_array( $result['translations'] ) ); } diff --git a/tests/WP/Formatter/Post_Metabox_Formatter_Test.php b/tests/WP/Formatter/Post_Metabox_Formatter_Test.php index ec909cf80c6..25845667e20 100644 --- a/tests/WP/Formatter/Post_Metabox_Formatter_Test.php +++ b/tests/WP/Formatter/Post_Metabox_Formatter_Test.php @@ -29,26 +29,6 @@ public function set_up() { $this->post = $this->factory->post->create_and_get(); } - /** - * Test the formatter when there isn't a post object and without any options. - * - * @covers WPSEO_Post_Metabox_Formatter::__construct - * @covers WPSEO_Post_Metabox_Formatter::get_values - * @covers WPSEO_Post_Metabox_Formatter::search_url - * @covers WPSEO_Post_Metabox_Formatter::edit_url - * @covers WPSEO_Post_Metabox_Formatter::base_url_for_js - * - * @return void - */ - public function test_no_post_with_empty_options() { - $instance = new WPSEO_Post_Metabox_Formatter( null, [], '' ); - $result = $instance->get_values(); - - $this->assertEquals( $result['search_url'], \admin_url( 'edit.php?seo_kw_filter={keyword}' ) ); - $this->assertEquals( $result['post_edit_url'], \admin_url( 'post.php?post={id}&action=edit' ) ); - $this->assertEquals( $result['base_url'], \YoastSEO()->helpers->url->home() ); - } - /** * Test with a post being set but with no options being set. * @@ -90,69 +70,4 @@ public function test_metabox_metadescription_date() { $this->assertEquals( $result['title_template'], 'This is the title' ); $this->assertEquals( $result['metadesc_template'], 'This is the metadescription' ); } - - /** - * Testing the formatter when 'being' on the new post page. - * - * @covers WPSEO_Post_Metabox_Formatter::get_values - * @covers WPSEO_Post_Metabox_Formatter::base_url_for_js - * - * @return void - */ - public function test_post_on_add_page() { - - $GLOBALS['pagenow'] = 'post-new.php'; - - $instance = new WPSEO_Post_Metabox_Formatter( $this->post, [], '' ); - $result = $instance->get_values(); - - $this->assertEquals( $result['base_url'], \YoastSEO()->helpers->url->home() ); - - unset( $GLOBALS['pagenow'] ); - } - - /** - * Testing when the permalink structure contains '%postname%/'. This should be stripped. - * - * @covers WPSEO_Post_Metabox_Formatter::get_values - * @covers WPSEO_Post_Metabox_Formatter::base_url_for_js - * - * @return void - */ - public function test_with_permalink_structure() { - $instance = new WPSEO_Post_Metabox_Formatter( $this->post, [], 'http://example.org/test/%postname%/' ); - $result = $instance->get_values(); - - $this->assertEquals( $result['base_url'], 'http://example.org/test/' ); - } - - /** - * Testing when the permalink structure contains '%pagename%/'. This should be stripped. - * - * @covers WPSEO_Post_Metabox_Formatter::get_values - * @covers WPSEO_Post_Metabox_Formatter::base_url_for_js - * - * @return void - */ - public function test_with_page_permalink_structure() { - $instance = new WPSEO_Post_Metabox_Formatter( $this->post, [], 'http://example.org/test/%pagename%/' ); - $result = $instance->get_values(); - - $this->assertEquals( $result['base_url'], 'http://example.org/test/' ); - } - - /** - * Testing when the permalink structure contains '%postname%/'. This should be stripped. - * - * @covers WPSEO_Post_Metabox_Formatter::get_values - * @covers WPSEO_Post_Metabox_Formatter::base_url_for_js - * - * @return void - */ - public function test_with_unreplaceble_permalink_structure() { - $instance = new WPSEO_Post_Metabox_Formatter( $this->post, [], '%isnotreplaced%/' ); - $result = $instance->get_values(); - - $this->assertEquals( $result['base_url'], \YoastSEO()->helpers->url->home() ); - } } diff --git a/tests/WP/Formatter/Term_Metabox_Formatter_Test.php b/tests/WP/Formatter/Term_Metabox_Formatter_Test.php index 8b902914ba0..bb19baaba5a 100644 --- a/tests/WP/Formatter/Term_Metabox_Formatter_Test.php +++ b/tests/WP/Formatter/Term_Metabox_Formatter_Test.php @@ -76,10 +76,6 @@ public function test_with_taxonomy_and_term_and_without_options() { $result = $instance->get_values(); - $this->assertEquals( $result['search_url'], \admin_url( 'edit-tags.php?taxonomy=' . $this->term->taxonomy . '&seo_kw_filter={keyword}' ) ); - $this->assertEquals( $result['post_edit_url'], \admin_url( 'term.php?action=edit&taxonomy=' . $this->term->taxonomy . '&tag_ID={id}' ) ); - - $this->assertEquals( \trailingslashit( \home_url( 'tag' ) ), $result['base_url'] ); $this->assertEquals( [ '' => [] ], $result['keyword_usage'] ); $this->assertEquals( '%%term_title%% Archives %%page%% %%sep%% %%sitename%%', $result['title_template'] ); $this->assertEquals( '', $result['metadesc_template'] ); From 41803e3b41e438d98b7896181e77fa0aa9c61e7c Mon Sep 17 00:00:00 2001 From: Thijs van der heijden Date: Tue, 7 May 2024 12:21:48 +0200 Subject: [PATCH 4/4] Use dynamic links. --- .../Site/Post_Site_Information_Test.php | 26 +++---------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/tests/WP/Editors/Framework/Site/Post_Site_Information_Test.php b/tests/WP/Editors/Framework/Site/Post_Site_Information_Test.php index 47edfd1c382..45f75860f69 100644 --- a/tests/WP/Editors/Framework/Site/Post_Site_Information_Test.php +++ b/tests/WP/Editors/Framework/Site/Post_Site_Information_Test.php @@ -118,18 +118,9 @@ public function test_legacy_site_information() { ], 'dismissedAlerts' => false, 'currentPromotions' => [], - 'webinarIntroBlockEditorUrl' => 'https://yoa.st/webinar-intro-block-editor?php_version=7.4&platform=wordpress&platform_version=6.6-alpha-57778-src&software=free&software_version=22.7-RC3&days_active=14&user_language=en_US', + 'webinarIntroBlockEditorUrl' => $this->short_link_helper->get( 'https://yoa.st/webinar-intro-block-editor' ), 'blackFridayBlockEditorUrl' => '', - 'linkParams' => - [ - 'php_version' => '7.4', - 'platform' => 'wordpress', - 'platform_version' => '6.6-alpha-57778-src', - 'software' => 'free', - 'software_version' => '22.7-RC3', - 'days_active' => 14, - 'user_language' => 'en_US', - ], + 'linkParams' => $this->short_link_helper->get_query_params(), 'pluginUrl' => 'http://example.org/wp-content/plugins/wordpress-seo', 'wistiaEmbedPermission' => true, ]; @@ -156,18 +147,9 @@ public function test_site_information() { 'base_url' => 'http://example.org/', 'dismissedAlerts' => false, 'currentPromotions' => [], - 'webinarIntroBlockEditorUrl' => 'https://yoa.st/webinar-intro-block-editor?php_version=7.4&platform=wordpress&platform_version=6.6-alpha-57778-src&software=free&software_version=22.7-RC3&days_active=14&user_language=en_US', + 'webinarIntroBlockEditorUrl' => $this->short_link_helper->get( 'https://yoa.st/webinar-intro-block-editor' ), 'blackFridayBlockEditorUrl' => '', - 'linkParams' => - [ - 'php_version' => '7.4', - 'platform' => 'wordpress', - 'platform_version' => '6.6-alpha-57778-src', - 'software' => 'free', - 'software_version' => '22.7-RC3', - 'days_active' => 14, - 'user_language' => 'en_US', - ], + 'linkParams' => $this->short_link_helper->get_query_params(), 'pluginUrl' => 'http://example.org/wp-content/plugins/wordpress-seo', 'wistiaEmbedPermission' => true, 'site_name' => 'Test Blog',