Make WordPress Core

Changeset 40317


Ignore:
Timestamp:
03/23/2017 05:13:14 PM (10 years ago)
Author:
flixos90
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/multisite/getBlogDetails.php

    r37666 r40317  
    118118                $this->assertFalse( $site );
    119119        }
     120
     121        /**
     122         * @dataProvider data_get_all
     123         *
     124         * @ticket 40228
     125         */
     126        public function test_get_blog_details_get_object_vars( $get_all ) {
     127                $site = get_blog_details( array( 'domain' => 'wordpress.org', 'path' => '/' ), $get_all );
     128
     129                $result = array_keys( get_object_vars( $site ) );
     130
     131                $this->assertEqualSets( $this->get_fields( $get_all ), $result );
     132        }
     133
     134        /**
     135         * @dataProvider data_get_all
     136         *
     137         * @ticket 40228
     138         */
     139        public function test_get_blog_details_iterate_over_result( $get_all ) {
     140                $site = get_blog_details( array( 'domain' => 'wordpress.org', 'path' => '/' ), $get_all );
     141
     142                $result = array();
     143                foreach ( $site as $key => $value ) {
     144                        $result[] = $key;
     145                }
     146
     147                $this->assertEqualSets( $this->get_fields( $get_all ), $result );
     148        }
     149
     150        public function data_get_all() {
     151                return array(
     152                        array( false ),
     153                        array( true ),
     154                );
     155        }
     156
     157        protected function get_fields( $all = false ) {
     158                $fields = array(
     159                        'blog_id',
     160                        'domain',
     161                        'path',
     162                        'site_id',
     163                        'registered',
     164                        'last_updated',
     165                        'public',
     166                        'archived',
     167                        'mature',
     168                        'spam',
     169                        'deleted',
     170                        'lang_id',
     171                );
     172
     173                if ( $all ) {
     174                        $fields = array_merge( $fields, array(
     175                                'blogname',
     176                                'siteurl',
     177                                'post_count',
     178                                'home',
     179                        ) );
     180                }
     181
     182                return $fields;
     183        }
    120184}
    121185
Note: See TracChangeset for help on using the changeset viewer.