Changeset 39189 for trunk/tests/phpunit/tests/user/author.php
- Timestamp:
- 11/10/2016 01:53:08 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/user/author.php
r37306 r39189 8 8 */ 9 9 class Tests_User_Author_Template extends WP_UnitTestCase { 10 protected $author_id = 0;11 protected $post_id = 0;10 protected static $author_id = 0; 11 protected static $post_id = 0; 12 12 13 13 private $permalink_structure; 14 15 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 16 self::$author_id = $factory->user->create( array( 17 'role' => 'author', 18 'user_login' => 'test_author', 19 'description' => 'test_author', 20 ) ); 21 22 self::$post_id = $factory->post->create( array( 23 'post_author' => self::$author_id, 24 'post_status' => 'publish', 25 'post_content' => rand_str(), 26 'post_title' => rand_str(), 27 'post_type' => 'post' 28 ) ); 29 } 14 30 15 31 function setUp() { 16 32 parent::setUp(); 17 33 18 $this->author_id = self::factory()->user->create( array( 19 'role' => 'author', 20 'user_login' => 'test_author', 21 'description' => 'test_author', 22 ) ); 23 $user = new WP_User( $this->author_id ); 24 25 $post = array( 26 'post_author' => $this->author_id, 27 'post_status' => 'publish', 28 'post_content' => rand_str(), 29 'post_title' => rand_str(), 30 'post_type' => 'post' 31 ); 32 33 // insert a post and make sure the ID is ok 34 $this->post_id = self::factory()->post->create( $post ); 35 36 setup_postdata( get_post( $this->post_id ) ); 34 setup_postdata( get_post( self::$post_id ) ); 37 35 } 38 36 … … 44 42 function test_get_the_author() { 45 43 $author_name = get_the_author(); 46 $user = new WP_User( $this->author_id );44 $user = new WP_User( self::$author_id ); 47 45 48 46 $this->assertEquals( $user->display_name, $author_name ); … … 57 55 $this->assertEquals( 'test_author', get_the_author_meta( 'description' ) ); 58 56 $this->assertEquals( 'test_author', get_the_author_meta( 'user_description' ) ); 59 add_user_meta( $this->author_id, 'user_description', 'user description' );60 $this->assertEquals( 'user description', get_user_meta( $this->author_id, 'user_description', true ) );57 add_user_meta( self::$author_id, 'user_description', 'user description' ); 58 $this->assertEquals( 'user description', get_user_meta( self::$author_id, 'user_description', true ) ); 61 59 // user_description in meta is ignored. The content of description is returned instead. 62 60 // See #20285 63 61 $this->assertEquals( 'test_author', get_the_author_meta( 'user_description' ) ); 64 62 $this->assertEquals( 'test_author', get_the_author_meta( 'description' ) ); 65 update_user_meta( $this->author_id, 'user_description', '' );66 $this->assertEquals( '', get_user_meta( $this->author_id, 'user_description', true ) );63 update_user_meta( self::$author_id, 'user_description', '' ); 64 $this->assertEquals( '', get_user_meta( self::$author_id, 'user_description', true ) ); 67 65 $this->assertEquals( 'test_author', get_the_author_meta( 'user_description' ) ); 68 66 $this->assertEquals( 'test_author', get_the_author_meta( 'description' ) ); … … 81 79 // Test with no global post, result should be 0 because no author is found 82 80 $this->assertEquals( 0, get_the_author_posts() ); 83 $GLOBALS['post'] = $this->post_id;81 $GLOBALS['post'] = self::$post_id; 84 82 $this->assertEquals( 1, get_the_author_posts() ); 85 83 } … … 92 90 93 91 $cpt_ids = self::factory()->post->create_many( 2, array( 94 'post_author' => $this->author_id,92 'post_author' => self::$author_id, 95 93 'post_type' => 'wptests_pt', 96 94 ) );
Note: See TracChangeset
for help on using the changeset viewer.