From df23b65221cce14d90cba345d3e271275abb43f0 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Thu, 23 Mar 2017 17:13:14 +0000 Subject: [PATCH] Multisite: Add further unit tests for `get_blog_details()`. These tests verify that the returned site object is iterable and contains the expected properties. See #40228, #40180. git-svn-id: https://develop.svn.wordpress.org/trunk@40317 602fd350-edb4-49c9-b593-d223f7449a82 --- .../tests/multisite/getBlogDetails.php | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/tests/phpunit/tests/multisite/getBlogDetails.php b/tests/phpunit/tests/multisite/getBlogDetails.php index b954d86e55..94ea754b0b 100644 --- a/tests/phpunit/tests/multisite/getBlogDetails.php +++ b/tests/phpunit/tests/multisite/getBlogDetails.php @@ -117,6 +117,70 @@ class Tests_Multisite_Get_Blog_Details extends WP_UnitTestCase { $site = get_blog_details( array( 'path' => '/foo/' ) ); $this->assertFalse( $site ); } + + /** + * @dataProvider data_get_all + * + * @ticket 40228 + */ + public function test_get_blog_details_get_object_vars( $get_all ) { + $site = get_blog_details( array( 'domain' => 'wordpress.org', 'path' => '/' ), $get_all ); + + $result = array_keys( get_object_vars( $site ) ); + + $this->assertEqualSets( $this->get_fields( $get_all ), $result ); + } + + /** + * @dataProvider data_get_all + * + * @ticket 40228 + */ + public function test_get_blog_details_iterate_over_result( $get_all ) { + $site = get_blog_details( array( 'domain' => 'wordpress.org', 'path' => '/' ), $get_all ); + + $result = array(); + foreach ( $site as $key => $value ) { + $result[] = $key; + } + + $this->assertEqualSets( $this->get_fields( $get_all ), $result ); + } + + public function data_get_all() { + return array( + array( false ), + array( true ), + ); + } + + protected function get_fields( $all = false ) { + $fields = array( + 'blog_id', + 'domain', + 'path', + 'site_id', + 'registered', + 'last_updated', + 'public', + 'archived', + 'mature', + 'spam', + 'deleted', + 'lang_id', + ); + + if ( $all ) { + $fields = array_merge( $fields, array( + 'blogname', + 'siteurl', + 'post_count', + 'home', + ) ); + } + + return $fields; + } } endif;