Make WordPress Core


Ignore:
Timestamp:
11/01/2014 04:47:00 AM (12 years ago)
Author:
jeremyfelt
Message:

Expand and clarify tests for get_blog_post()

Remove unnecessary user factory use. Be explicit about test scenarios.

See #30080

File:
1 edited

Legend:

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

    r30114 r30151  
    987987        }
    988988
    989         function test_get_blog_post() {
    990                 $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
    991                 $blog_id = $this->factory->blog->create( array( 'user_id' => $user_id, 'path' => '/test_blogpath', 'title' => 'Test Title' ) );
    992                 $current_blog_id = get_current_blog_id();
    993 
     989        /**
     990         * Test the primary purpose of get_blog_post(), to retrieve a post from
     991         * another site on the network.
     992         */
     993        function test_get_blog_post_from_another_site_on_network() {
     994                $blog_id = $this->factory->blog->create();
     995                $post_id = $this->factory->post->create(); // Create a post on the primary site, ID 1.
     996                $post = get_post( $post_id );
     997                switch_to_blog( $blog_id );
     998
     999                // The post created and retrieved on the main site should match the one retrieved "remotely".
     1000                $this->assertEquals( $post, get_blog_post( 1, $post_id ) );
     1001
     1002                restore_current_blog();
     1003        }
     1004
     1005        /**
     1006         * If get_blog_post() is used on the same site, it should still work.
     1007         */
     1008        function test_get_blog_post_from_same_site() {
    9941009                $post_id = $this->factory->post->create();
    995                 $this->assertInstanceOf( 'WP_Post', get_post( $post_id ) );
    996                 switch_to_blog( $blog_id );
    997                 $this->assertNull( get_post( $post_id ) );
    998                 $post = get_blog_post( $current_blog_id, $post_id );
    999                 $this->assertInstanceOf( 'WP_Post', $post );
    1000                 $this->assertEquals( $post_id, $post->ID );
    1001                 restore_current_blog();
    1002 
    1003                 wp_update_post( array( 'ID' => $post_id, 'post_title' => 'A Different Title' ) );
    1004                 switch_to_blog( $blog_id );
    1005                 $post = get_blog_post( $current_blog_id, $post_id );
    1006                 // Make sure cache is good
    1007                 $this->assertEquals( 'A Different Title', $post->post_title );
    1008 
    1009                 $post_id2 = $this->factory->post->create();
    1010                 // Test get_blog_post() with currently active blog ID.
    1011                 $post = get_blog_post( $blog_id, $post_id2 );
    1012                 $this->assertInstanceOf( 'WP_Post', $post );
    1013                 $this->assertEquals( $post_id2, $post->ID );
    1014                 restore_current_blog();
     1010
     1011                $this->assertEquals( get_blog_post( 1, $post_id ), get_post( $post_id ) );
     1012        }
     1013
     1014        /**
     1015         * A null response should be returned if an invalid post is requested.
     1016         */
     1017        function test_get_blog_post_invalid_returns_null() {
     1018                $this->assertNull( get_blog_post( 1, 999999 ) );
    10151019        }
    10161020
Note: See TracChangeset for help on using the changeset viewer.