From ad8dc6395c0142788ee02f595a9481bfe8d796b0 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Thu, 17 Dec 2015 17:11:07 +0000 Subject: [PATCH] Better focus in tag cloud tests. We should avoid testing complete markup strings, unless we are specifically testing for the format of the markup. Fixes #35138. git-svn-id: https://develop.svn.wordpress.org/trunk@35988 602fd350-edb4-49c9-b593-d223f7449a82 --- .../phpunit/tests/term/wpGenerateTagCloud.php | 56 +++++++++++-------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/tests/phpunit/tests/term/wpGenerateTagCloud.php b/tests/phpunit/tests/term/wpGenerateTagCloud.php index 47a1283657..4f50ecc1d7 100644 --- a/tests/phpunit/tests/term/wpGenerateTagCloud.php +++ b/tests/phpunit/tests/term/wpGenerateTagCloud.php @@ -78,10 +78,12 @@ class Tests_WP_Generate_Tag_Cloud extends WP_UnitTestCase { 'number' => 1, 'hide_empty' => false, ) ); - $expected = "{$term->name}"; - $this->assertEquals( $expected, wp_generate_tag_cloud( $tags, array( + + $found = wp_generate_tag_cloud( $tags, array( 'hide_empty' => false, - ) ) ); + ) ); + + $this->assertContains( '>' . $tags[0]->name . '<', $found ); } function test_hide_empty_false_format_array() { @@ -94,10 +96,13 @@ class Tests_WP_Generate_Tag_Cloud extends WP_UnitTestCase { 'format' => 'array', ) ); - $expected = "{$term->name}"; - $this->assertEquals( $expected, wp_generate_tag_cloud( $tags, array( + $found = wp_generate_tag_cloud( $tags, array( 'hide_empty' => false, - ) ) ); + 'format' => 'array', + ) ); + + $this->assertInternalType( 'array', $found ); + $this->assertContains( '>' . $tags[0]->name . '<', $found[0] ); } function test_hide_empty_false_format_list() { @@ -109,11 +114,14 @@ class Tests_WP_Generate_Tag_Cloud extends WP_UnitTestCase { 'hide_empty' => false, ) ); - $expected = "\n"; - $this->assertEquals( $expected, wp_generate_tag_cloud( $tags, array( + $found = wp_generate_tag_cloud( $tags, array( 'hide_empty' => false, 'format' => 'list', - ) ) ); + ) ); + + $this->assertRegExp( "|^\n|", $found ); + $this->assertContains( '>' . $tags[0]->name . '<', $found ); } function test_hide_empty_false_multi() { @@ -129,13 +137,13 @@ class Tests_WP_Generate_Tag_Cloud extends WP_UnitTestCase { 'hide_empty' => false, ) ); - $expected = "{$terms[0]->name}\n". - "{$terms[1]->name}\n". - "{$terms[2]->name}\n". - "{$terms[3]->name}"; - $this->assertEquals( $expected, wp_generate_tag_cloud( $tags, array( + $found = wp_generate_tag_cloud( $tags, array( 'hide_empty' => false, - ) ) ); + ) ); + + foreach ( $tags as $tag ) { + $this->assertContains( '>' . $tag->name . '<', $found ); + } } function test_hide_empty_false_multi_format_list() { @@ -151,17 +159,17 @@ class Tests_WP_Generate_Tag_Cloud extends WP_UnitTestCase { 'hide_empty' => false, ) ); - $expected = "\n"; - - $this->assertEquals( $expected, wp_generate_tag_cloud( $tags, array( + $found = wp_generate_tag_cloud( $tags, array( 'hide_empty' => false, 'format' => 'list', - ) ) ); + ) ); + + $this->assertRegExp( "|^\n|", $found ); + + foreach ( $tags as $tag ) { + $this->assertContains( '>' . $tag->name . '<', $found ); + } } public function test_topic_count_text() {