Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Split speculation-rules and embed-optimizer generator tag tests from …
…hook tests.
  • Loading branch information
felixarntz committed Apr 1, 2024
commit 4c8aff7fb299f4ed68701a69a4389bf7b7e1fcd3
6 changes: 5 additions & 1 deletion tests/plugins/embed-optimizer/embed-optimizer-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

class Embed_Optimizer_Helper_Tests extends WP_UnitTestCase {

public function test_hooks() {
$this->assertSame( 10, has_filter( 'embed_oembed_html', 'embed_optimizer_filter_oembed_html' ) );
$this->assertSame( 10, has_action( 'wp_head', 'embed_optimizer_render_generator' ) );
}

/**
* Test that the oEmbed HTML is filtered.
*
Expand Down Expand Up @@ -163,7 +168,6 @@ function ( array $attrs, string $javascript ) {
* @covers ::embed_optimizer_render_generator
*/
public function test_embed_optimizer_render_generator() {
$this->assertSame( 10, has_action( 'wp_head', 'embed_optimizer_render_generator' ) );
$tag = get_echo( 'embed_optimizer_render_generator' );
$this->assertStringStartsWith( '<meta', $tag );
$this->assertStringContainsString( 'generator', $tag );
Expand Down
25 changes: 14 additions & 11 deletions tests/plugins/speculation-rules/speculation-rules-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,9 @@ public function tear_down() {
parent::tear_down();
}

public function data_provider_to_test_print_speculation_rules(): array {
return array(
'xhtml' => array(
'html5_support' => false,
),
'html5' => array(
'html5_support' => true,
),
);
public function test_hooks() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I don't think we are validating that hooks are always present for each of the plugins. Should this type of test be added everywhere, since I don't believe we can run tests against the output of wp_head to confirm that these are actually being printed without introducing side effects?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joemcgill I generally like to have this kind of test as it helps prevent accidents with hooks added or removed, but I wouldn't want to mandate it. IMO it's a good practice, but I still think this is something we can leave up to the typical freedom of choice of the respective plugin developers / PR authors and PR reviewers.

I only added this here since the hook check previously was baked into the generator test method, which IMO it shouldn't be since it's a different kind of test.

$this->assertSame( 10, has_action( 'wp_footer', 'plsr_print_speculation_rules' ) );
$this->assertSame( 10, has_action( 'wp_head', 'plsr_render_generator_meta_tag' ) );
}

/**
Expand All @@ -36,14 +30,23 @@ public function data_provider_to_test_print_speculation_rules(): array {
* @covers ::plsr_render_generator_meta_tag
*/
public function test_plsr_render_generator_meta_tag() {
$this->assertSame( 10, has_action( 'wp_head', 'plsr_render_generator_meta_tag' ) );

$tag = get_echo( 'plsr_render_generator_meta_tag' );
$this->assertStringStartsWith( '<meta', $tag );
$this->assertStringContainsString( 'generator', $tag );
$this->assertStringContainsString( 'speculation-rules ' . SPECULATION_RULES_VERSION, $tag );
}

public function data_provider_to_test_print_speculation_rules(): array {
return array(
'xhtml' => array(
'html5_support' => false,
),
'html5' => array(
'html5_support' => true,
),
);
}

/**
* @dataProvider data_provider_to_test_print_speculation_rules
* @covers ::plsr_print_speculation_rules
Expand Down