WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/17/2015 06:02:16 PM (6 years ago)
Author:
wonderboymusic
Message:

Unit Tests: after [35225], make factory a method/getter on WP_UnitTestCase and add magic methods for BC for every plugin that is extending WP_UnitTestCase and accessing the $factory instance prop.

Props nerrad, wonderboymusic.
See #30017, #33968.

File:
1 edited

Legend:

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

    r35225 r35242  
    3535        $this->assertEquals( $current_blog_id, wp_cache_get( 'switch-test', 'switch-test' ) );
    3636
    37         $blog_id = self::$factory->blog->create();
     37        $blog_id = self::factory()->blog->create();
    3838
    3939        $cap_key = wp_get_current_user()->cap_key;
     
    7575        global $wpdb;
    7676
    77         $blog_id = self::$factory->blog->create();
     77        $blog_id = self::factory()->blog->create();
    7878
    7979        $this->assertInternalType( 'int', $blog_id );
     
    131131     */
    132132    function test_data_in_cache_after_wpmu_delete_blog_drop_false() {
    133         $blog_id = self::$factory->blog->create();
     133        $blog_id = self::factory()->blog->create();
    134134
    135135        $details = get_blog_details( $blog_id, false );
     
    152152        global $wpdb;
    153153
    154         $blog_id = self::$factory->blog->create();
     154        $blog_id = self::factory()->blog->create();
    155155
    156156        // Delete the site without forcing a table drop.
     
    170170     */
    171171    function test_data_in_cache_after_wpmu_delete_blog_drop_true() {
    172         $blog_id = self::$factory->blog->create();
     172        $blog_id = self::factory()->blog->create();
    173173
    174174        $details = get_blog_details( $blog_id, false );
     
    191191        global $wpdb;
    192192
    193         $blog_id = self::$factory->blog->create();
     193        $blog_id = self::factory()->blog->create();
    194194
    195195        // Delete the site and force a table drop.
     
    248248     */
    249249    function test_network_count_after_wpmu_delete_blog_drop_false() {
    250         $blog_id = self::$factory->blog->create();
     250        $blog_id = self::factory()->blog->create();
    251251
    252252        // Delete the site without forcing a table drop.
     
    262262     */
    263263    function test_blog_count_after_wpmu_delete_blog_drop_true() {
    264         $blog_id = self::$factory->blog->create();
     264        $blog_id = self::factory()->blog->create();
    265265
    266266        // Delete the site and force a table drop.
     
    284284        $file1 = wp_upload_bits( $filename, null, $contents );
    285285
    286         $blog_id = self::$factory->blog->create();
     286        $blog_id = self::factory()->blog->create();
    287287
    288288        switch_to_blog( $blog_id );
     
    330330    function test_get_blog_details_when_site_does_not_exist() {
    331331        // Create an unused site so that we can then assume an invalid site ID.
    332         $blog_id = self::$factory->blog->create();
     332        $blog_id = self::factory()->blog->create();
    333333        $blog_id++;
    334334
     
    340340
    341341        // Create a site in the invalid site's place.
    342         self::$factory->blog->create();
     342        self::factory()->blog->create();
    343343
    344344        // When a new site is created, its cache is cleared through refresh_blog_details.
     
    371371        $test_action_counter = 0;
    372372
    373         $blog_id = self::$factory->blog->create();
     373        $blog_id = self::factory()->blog->create();
    374374        update_blog_details( $blog_id, array( 'spam' => 1 ) );
    375375
     
    395395        $test_action_counter = 0;
    396396
    397         $blog_id = self::$factory->blog->create();
     397        $blog_id = self::factory()->blog->create();
    398398
    399399        add_action( 'make_spam_blog', array( $this, '_action_counter_cb' ), 10 );
     
    418418        $test_action_counter = 0;
    419419
    420         $blog_id = self::$factory->blog->create();
     420        $blog_id = self::factory()->blog->create();
    421421
    422422        add_action( 'archive_blog', array( $this, '_action_counter_cb' ), 10 );
     
    441441        $test_action_counter = 0;
    442442
    443         $blog_id = self::$factory->blog->create();
     443        $blog_id = self::factory()->blog->create();
    444444        update_blog_details( $blog_id, array( 'archived' => 1 ) );
    445445
     
    464464        $test_action_counter = 0;
    465465
    466         $blog_id = self::$factory->blog->create();
     466        $blog_id = self::factory()->blog->create();
    467467
    468468        add_action( 'make_delete_blog', array( $this, '_action_counter_cb' ), 10 );
     
    487487        $test_action_counter = 0;
    488488
    489         $blog_id = self::$factory->blog->create();
     489        $blog_id = self::factory()->blog->create();
    490490        update_blog_details( $blog_id, array( 'deleted' => 1 ) );
    491491
     
    511511        $test_action_counter = 0;
    512512
    513         $blog_id = self::$factory->blog->create();
     513        $blog_id = self::factory()->blog->create();
    514514
    515515        add_action( 'mature_blog', array( $this, '_action_counter_cb' ), 10 );
     
    534534        $test_action_counter = 0;
    535535
    536         $blog_id = self::$factory->blog->create();
     536        $blog_id = self::factory()->blog->create();
    537537        update_blog_details( $blog_id, array( 'mature' => 1 ) );
    538538
     
    558558        $test_action_counter = 0;
    559559
    560         $blog_id = self::$factory->blog->create();
     560        $blog_id = self::factory()->blog->create();
    561561
    562562        add_action( 'update_blog_public', array( $this, '_action_counter_cb' ), 10 );
     
    584584     */
    585585    function test_wp_get_sites_with_default_arguments() {
    586         self::$factory->blog->create( array( 'site_id' => 2 ) );
     586        self::factory()->blog->create( array( 'site_id' => 2 ) );
    587587
    588588        $this->assertCount( 1, wp_get_sites() );
     
    600600     */
    601601    function test_wp_get_sites_with_network_id_null() {
    602         self::$factory->blog->create( array( 'site_id' => 2 ) );
     602        self::factory()->blog->create( array( 'site_id' => 2 ) );
    603603
    604604        $this->assertCount( 2, wp_get_sites( array( 'network_id' => null ) ) );
     
    609609     */
    610610    function test_wp_get_sites_with_specific_network_id() {
    611         self::$factory->blog->create( array( 'site_id' => 2 ) );
     611        self::factory()->blog->create( array( 'site_id' => 2 ) );
    612612
    613613        $this->assertCount( 1, wp_get_sites( array( 'network_id' => 2 ) ) );
     
    618618     */
    619619    function test_wp_get_sites_with_multiple_network_ids() {
    620         self::$factory->blog->create( array( 'site_id' => 2 ) );
     620        self::factory()->blog->create( array( 'site_id' => 2 ) );
    621621
    622622        $this->assertCount( 2, wp_get_sites( array( 'network_id' => array( 1, 2 ) ) ) );
     
    627627     */
    628628    function test_wp_get_sites_with_public_meta_on_all_networks() {
    629         self::$factory->blog->create( array( 'site_id' => 2, 'meta' => array( 'public' => 0 ) ) );
     629        self::factory()->blog->create( array( 'site_id' => 2, 'meta' => array( 'public' => 0 ) ) );
    630630
    631631        $this->assertCount( 1, wp_get_sites( array( 'public' => 1, 'network_id' => null ) ) );
     
    637637     */
    638638    function test_wp_get_sites_with_public_meta_restrict_to_one_network() {
    639         self::$factory->blog->create( array( 'site_id' => 1, 'meta' => array( 'public' => 0 ) ) );
     639        self::factory()->blog->create( array( 'site_id' => 1, 'meta' => array( 'public' => 0 ) ) );
    640640
    641641        $this->assertCount( 1, wp_get_sites( array( 'public' => 1, 'network_id' => 1 ) ) );
     
    648648    function test_wp_get_sites_limit_offset() {
    649649        // Create 2 more sites (in addition to the default one)
    650         self::$factory->blog->create_many( 2 );
     650        self::factory()->blog->create_many( 2 );
    651651
    652652        // Expect first 2 sites when using limit
     
    671671     */
    672672    function test_posts_count() {
    673         self::$factory->post->create();
    674         $post2 = self::$factory->post->create();
     673        self::factory()->post->create();
     674        $post2 = self::factory()->post->create();
    675675        $this->assertEquals( 2, get_blog_details()->post_count );
    676676
     
    702702
    703703        foreach ( $network_ids as &$id ) {
    704             $id = self::$factory->network->create( $id );
     704            $id = self::factory()->network->create( $id );
    705705        }
    706706        unset( $id );
     
    715715
    716716        foreach ( $ids as &$id ) {
    717             $id = self::$factory->blog->create( $id );
     717            $id = self::factory()->blog->create( $id );
    718718        }
    719719        unset( $id );
     
    773773     */
    774774    function test_get_blog_id_from_url() {
    775         $blog_id = self::$factory->blog->create();
     775        $blog_id = self::factory()->blog->create();
    776776        $details = get_blog_details( $blog_id, false );
    777777        $key = md5( $details->domain . $details->path );
     
    786786     */
    787787    function test_get_blog_id_from_url_is_case_insensitive() {
    788         $blog_id = self::$factory->blog->create( array( 'domain' => 'example.com', 'path' => '/xyz' ) );
     788        $blog_id = self::factory()->blog->create( array( 'domain' => 'example.com', 'path' => '/xyz' ) );
    789789        $details = get_blog_details( $blog_id, false );
    790790
     
    796796     */
    797797    function test_get_blog_id_from_url_that_does_not_exist() {
    798         $blog_id = self::$factory->blog->create( array( 'path' => '/xyz' ) );
     798        $blog_id = self::factory()->blog->create( array( 'path' => '/xyz' ) );
    799799        $details = get_blog_details( $blog_id, false );
    800800
     
    808808     */
    809809    function test_get_blog_id_from_url_with_deleted_flag() {
    810         $blog_id = self::$factory->blog->create();
     810        $blog_id = self::factory()->blog->create();
    811811        $details = get_blog_details( $blog_id, false );
    812812        $key = md5( $details->domain . $details->path );
     
    822822     */
    823823    function test_get_blog_id_from_url_after_dropped() {
    824         $blog_id = self::$factory->blog->create();
     824        $blog_id = self::factory()->blog->create();
    825825        $details = get_blog_details( $blog_id, false );
    826826        $key = md5( $details->domain . $details->path );
     
    851851     */
    852852    function test_is_main_site_is_false_with_other_blog_id() {
    853         $blog_id = self::$factory->blog->create();
     853        $blog_id = self::factory()->blog->create();
    854854
    855855        $this->assertFalse( is_main_site( $blog_id ) );
     
    860860     */
    861861    function test_is_main_site_is_false_after_switch_to_blog() {
    862         $blog_id = self::$factory->blog->create();
     862        $blog_id = self::factory()->blog->create();
    863863        switch_to_blog( $blog_id );
    864864
     
    879879        $this->assertEquals( '', $info['error'] );
    880880
    881         $blog_id = self::$factory->blog->create();
     881        $blog_id = self::factory()->blog->create();
    882882
    883883        switch_to_blog( $blog_id );
     
    901901     */
    902902    function test_get_blog_post_from_another_site_on_network() {
    903         $blog_id = self::$factory->blog->create();
    904         $post_id = self::$factory->post->create(); // Create a post on the primary site, ID 1.
     903        $blog_id = self::factory()->blog->create();
     904        $post_id = self::factory()->post->create(); // Create a post on the primary site, ID 1.
    905905        $post = get_post( $post_id );
    906906        switch_to_blog( $blog_id );
     
    916916     */
    917917    function test_get_blog_post_from_same_site() {
    918         $post_id = self::$factory->post->create();
     918        $post_id = self::factory()->post->create();
    919919
    920920        $this->assertEquals( get_blog_post( 1, $post_id ), get_post( $post_id ) );
Note: See TracChangeset for help on using the changeset viewer.