diff --git a/tests/phpunit/tests/term/wpGenerateTagCloud.php b/tests/phpunit/tests/term/wpGenerateTagCloud.php new file mode 100644 index 0000000000..c7c79011b4 --- /dev/null +++ b/tests/phpunit/tests/term/wpGenerateTagCloud.php @@ -0,0 +1,192 @@ +assertSame( $expected, wp_generate_tag_cloud( $empty_tags, $args ) ); + } + + /** + * Testing when no tags are found + * + * @dataProvider empty_tags_data_provider + * + * @param $expected Expected output from `wp_generate_tag_cloud()`. + * @param $args Options for `wp_generate_tag_cloud()`. + */ + function test_empty_tags_list_returned( $expected, $args ) { + $this->factory->term->create_many( 4, array( 'taxonomy' => 'post_tag' ) ); + $tags = $this->retrieve_terms( array( 'number' => 4 ) ); + $this->assertSame( $expected, wp_generate_tag_cloud( $tags, $args ) ); + } + + /** + * Provider for test when tags are empty. + * @return array + */ + function empty_tags_data_provider ( ) { + return array( + /** + * when format => array, we should be getting an empty array back + */ + array( + array(), + array( 'format' => 'array' ), + ), + /** + * List format returns an empty string + */ + array( + '', + array( 'format' => 'list' ), + ), + /** + * $args can be an array or ''. Either should return an empty string + */ + array( + '', + array(), + ), + array( + '', + '', + ), + ); + } + + + /** + * Testing the various output for a single link + * in various formats + * + * @dataProvider single_link_data_provider + * + * @param int $create How many tags to create. + * @param array $get_terms_args What args we want to pass to retreve terms. + * @param mixed $expected Expected output from `wp_generate_tag_cloud()`. + * @param array $args Options for `wp_generate_tag_cloud()`. + * + */ + function test_wp_generate_tag_cloud( $create, $get_terms_args, $expected, $args ) { + $this->factory->term->create_many( $create, array( 'taxonomy' => 'post_tag' ) ); + $tags = $this->retrieve_terms( $get_terms_args ); + + $this->assertEquals( $expected, wp_generate_tag_cloud( $tags, $args ) ); + } + + + function single_link_data_provider() { + return array( + array( + 1, + array( + 'number' => 1, + 'hide_empty' => false, + ), + "Term 1", + array( + 'hide_empty' => false, + ), + ), + + // Should return an array of links. + array( + 1, + array( + 'number' => 1, + 'hide_empty' => false, + ), + array( + "Term 1", + ), + array( + 'hide_empty' => false, + 'format' => 'array', + ), + ), + + // Should return a string containing a