WordPress.org

Make WordPress Core

Ticket #42251: 42251-tests.diff

File 42251-tests.diff, 3.0 KB (added by mnelson4, 2 years ago)

Adds phpunit tests related to 42251

  • tests/phpunit/tests/multisite/network.php

    diff --git tests/phpunit/tests/multisite/network.php tests/phpunit/tests/multisite/network.php
    index 33c5980..4094730 100644
    class Tests_Multisite_Network extends WP_UnitTestCase { 
    592592
    593593                $this->assertSame( (string) self::$different_site_ids[0], $network->blog_id );
    594594        }
     595
     596        /**
     597         * @ticket 42251
     598         */
     599        public function test_wp_site_get_instance_doesnt_exist() {
     600                $this->assertFalse(WP_Network::get_instance( $this->_get_next_network_id()));
     601        }
     602
     603        /**
     604         * @ticket 42251
     605         */
     606        public function test_wp_site_get_instance_doesnt_exist_but_later_exists() {
     607                $new_site_id = $this->_get_next_network_id();
     608                $this->assertFalse(WP_Network::get_instance($new_site_id));
     609                $new_network = $this->factory()->network->create_and_get();
     610                //make sure we were right about what the new network's ID would be
     611                $this->assertEquals($new_site_id, $new_network->id);
     612                //verify that if we fetch the network now, it's no longer false
     613                $fetched_network = WP_Network::get_instance($new_site_id);
     614                $this->assertInstanceOf('WP_Network', $fetched_network);
     615                $this->assertEquals($new_site_id, $fetched_network->id);
     616        }
     617
     618        /**
     619         * Gets the ID of the site with the highest ID
     620         * @return int
     621         */
     622        protected function _get_next_network_id() {
     623                global $wpdb;
     624                //create an extra network, just to make sure we know the ID of the following one
     625                static::factory()->network->create();
     626                return (int)$wpdb->get_var('SELECT id FROM ' . $wpdb->site . ' ORDER BY id DESC LIMIT 1') + 1;
     627        }
    595628}
    596629
    597630endif;
  • tests/phpunit/tests/multisite/site.php

    diff --git tests/phpunit/tests/multisite/site.php tests/phpunit/tests/multisite/site.php
    index d0b460b..42234e4 100644
    class Tests_Multisite_Site extends WP_UnitTestCase { 
    12421242                        array( 'current_blog_%domain%%path%', 'site-options' ),
    12431243                );
    12441244        }
     1245
     1246        /**
     1247         * @ticket 42251
     1248         */
     1249        public function test_wp_site_get_instance_doesnt_exist() {
     1250                $this->assertFalse(WP_Site::get_instance( $this->_get_next_site_id()));
     1251        }
     1252
     1253        /**
     1254         * @ticket 42251
     1255         */
     1256        public function test_wp_site_get_instance_doesnt_exist_but_later_exists() {
     1257                $new_site_id = $this->_get_next_site_id();
     1258                $this->assertFalse(WP_Site::get_instance($new_site_id));
     1259                $new_site = $this->factory()->blog->create_and_get();
     1260                //double check we got the ID of the new site correct
     1261                $this->assertEquals($new_site_id, $new_site->blog_id);
     1262                //verify that if we fetch the site now, it's no longer false
     1263                $fetched_site = WP_Site::get_instance($new_site_id);
     1264                $this->assertInstanceOf('WP_Site', $fetched_site);
     1265                $this->assertEquals($new_site_id, $fetched_site->blog_id);
     1266
     1267        }
     1268
     1269        /**
     1270         * Gets the ID of the next site that will get inserted
     1271         * @return int
     1272         */
     1273        protected function _get_next_site_id() {
     1274                global $wpdb;
     1275                //create an entry
     1276                static::factory()->blog->create();
     1277                //get the ID after it
     1278                return (int)$wpdb->get_var('SELECT blog_id FROM ' . $wpdb->blogs . ' ORDER BY blog_ID DESC LIMIT 1') + 1;
     1279        }
    12451280}
    12461281
    12471282endif;