Skip to content
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

Move generic site data into self contained objects. #21368

Open
wants to merge 7 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
Update tests.
  • Loading branch information
thijsoo committed May 7, 2024
commit 36c618ea1600a98eab60d1600639bb27b5f80ae6
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
],
Expand Down
1 change: 0 additions & 1 deletion tests/Unit/Admin/User_Profile_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
184 changes: 184 additions & 0 deletions tests/WP/Editors/Framework/Site/Post_Site_Information_Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
<?php

// @phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- This namespace should reflect the namespace of the original class.
namespace Yoast\WP\SEO\Tests\WP\Editors\Framework\Site;

use Mockery;
use Yoast\WP\SEO\Actions\Alert_Dismissal_Action;
use Yoast\WP\SEO\Editors\Framework\Site\Post_Site_Information;
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;
use Yoast\WP\SEO\Promotions\Application\Promotion_Manager;
use Yoast\WP\SEO\Surfaces\Meta_Surface;
use Yoast\WP\SEO\Tests\WP\TestCase;

/**
* Class Post_Site_Information_Test
*
* @group editors
*
* @coversDefaultClass \Yoast\WP\SEO\Editors\Framework\Site\Post_Site_Information
*/
final class Post_Site_Information_Test extends TestCase {

/**
* Holds the Alert_Dismissal_Action instance.
*
* @var Mockery\MockInterface|Alert_Dismissal_Action
*/
protected $alert_dismissal_action;

/**
* Holds the Promotion_Manager instance.
*
* @var Mockery\MockInterface|Promotion_Manager
*/
private $promotion_manager;

/**
* Holds the Short_Link_Helper instance.
*
* @var Mockery\MockInterface|Short_Link_Helper
*/
private $short_link_helper;

/**
* Holds the Wistia_Embed_Permission_Repository instance.
*
* @var Mockery\MockInterface|Wistia_Embed_Permission_Repository
*/
private $wistia_embed_repo;

/**
* Holds the Meta_Surface instance.
*
* @var Mockery\MockInterface|Meta_Surface
*/
private $meta_surface;

/**
* Holds the Product_Helper instance.
*
* @var Mockery\MockInterface|Product_Helper
*/
private $product_helper;

/**
* The Post_Site_Information container.
*
* @var Post_Site_Information
*/
private $instance;

/**
* Set up the test.
*
* @return void
*/
public function set_up() {
parent::set_up();
$this->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:https://example.org/wp-admin/edit.php?seo_kw_filter={keyword}',
'post_edit_url' => 'http:https://example.org/wp-admin/post.php?post={id}&action=edit',
'base_url' => 'http:https://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:https://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:https://example.org/wp-admin/edit.php?seo_kw_filter={keyword}',
'post_edit_url' => 'http:https://example.org/wp-admin/post.php?post={id}&action=edit',
'base_url' => 'http:https://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:https://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() );
}
}
1 change: 0 additions & 1 deletion tests/WP/Formatter/Metabox_Formatter_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ) );
}
Expand Down
85 changes: 0 additions & 85 deletions tests/WP/Formatter/Post_Metabox_Formatter_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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:https://example.org/test/%postname%/' );
$result = $instance->get_values();

$this->assertEquals( $result['base_url'], 'http:https://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:https://example.org/test/%pagename%/' );
$result = $instance->get_values();

$this->assertEquals( $result['base_url'], 'http:https://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() );
}
}
4 changes: 0 additions & 4 deletions tests/WP/Formatter/Term_Metabox_Formatter_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] );
Expand Down