Changeset 35186
- Timestamp:
- 10/15/2015 04:43:37 AM (9 years ago)
- Location:
- trunk/tests/phpunit
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/includes/testcase.php
r35136 r35186 19 19 */ 20 20 protected $factory; 21 22 protected static $static_factory; 23 24 public static function get_called_class() { 25 if ( function_exists( 'get_called_class' ) ) { 26 return get_called_class(); 27 } 28 29 // PHP 5.2 only 30 $backtrace = debug_backtrace(); 31 // [0] WP_UnitTestCase::get_called_class() 32 // [1] WP_UnitTestCase::setUpBeforeClass() 33 if ( 'call_user_func' === $backtrace[2]['function'] ) { 34 return $backtrace[2]['args'][0][0]; 35 } 36 return $backtrace[2]['class']; 37 } 38 39 public static function setUpBeforeClass() { 40 parent::setUpBeforeClass(); 41 42 $c = self::get_called_class(); 43 if ( ! method_exists( $c, 'wpSetUpBeforeClass' ) ) { 44 return; 45 } 46 47 if ( ! self::$static_factory ) { 48 self::$static_factory = new WP_UnitTest_Factory(); 49 } 50 51 call_user_func( array( $c, 'wpSetUpBeforeClass' ), self::$static_factory ); 52 53 self::commit_transaction(); 54 } 55 56 public static function tearDownAfterClass() { 57 parent::tearDownAfterClass(); 58 59 $c = self::get_called_class(); 60 if ( ! method_exists( $c, 'wpTearDownAfterClass' ) ) { 61 return; 62 } 63 64 call_user_func( array( $c, 'wpTearDownAfterClass' ) ); 65 66 self::commit_transaction(); 67 } 21 68 22 69 function setUp() { -
trunk/tests/phpunit/tests/admin/includesListTable.php
r35165 r35186 17 17 } 18 18 19 public static function setUpBeforeClass() { 20 $factory = new WP_UnitTest_Factory(); 21 19 public static function wpSetUpBeforeClass( $factory ) { 22 20 // note that our top/children/grandchildren arrays are 1-indexed 23 21 … … 65 63 } 66 64 } 67 68 self::commit_transaction(); 69 } 70 71 public static function tearDownAfterClass() { 65 } 66 67 public static function wpTearDownAfterClass() { 72 68 foreach ( self::$post_ids as $post_id ) { 73 69 wp_delete_post( $post_id, true ); 74 70 } 75 76 self::commit_transaction();77 71 } 78 72 -
trunk/tests/phpunit/tests/adminbar.php
r34122 r35186 8 8 class Tests_AdminBar extends WP_UnitTestCase { 9 9 10 static function setUpBeforeClass() { 11 WP_UnitTestCase::setUpBeforeClass(); 12 require_once ABSPATH . WPINC . '/class-wp-admin-bar.php'; 13 } 14 15 function setUp() { 16 parent::setUp(); 17 $this->current_user = get_current_user_id(); 18 } 19 20 function tearDown() { 21 wp_set_current_user( $this->current_user ); 22 parent::tearDown(); 10 public static function setUpBeforeClass() { 11 require_once( ABSPATH . WPINC . '/class-wp-admin-bar.php' ); 23 12 } 24 13 -
trunk/tests/phpunit/tests/auth.php
r35175 r35186 16 16 protected $nonce_failure_hook = 'wp_verify_nonce_failed'; 17 17 18 static function setUpBeforeClass() { 19 parent::setUpBeforeClass(); 20 21 $factory = new WP_UnitTest_Factory(); 22 18 public static function wpSetUpBeforeClass( $factory ) { 23 19 self::$_user = $factory->user->create_and_get( array( 24 20 'user_login' => 'password-tests' … … 29 25 require_once( ABSPATH . WPINC . '/class-phpass.php' ); 30 26 self::$wp_hasher = new PasswordHash( 8, true ); 31 32 self::commit_transaction(); 33 } 34 35 public static function tearDownAfterClass() { 36 parent::tearDownAfterClass(); 37 27 } 28 29 public static function wpTearDownAfterClass() { 38 30 if ( is_multisite() ) { 39 31 wpmu_delete_user( self::$user_id ); … … 41 33 wp_delete_user( self::$user_id ); 42 34 } 43 44 self::commit_transaction();45 35 } 46 36 -
trunk/tests/phpunit/tests/comment.php
r35176 r35186 8 8 protected static $post_id; 9 9 10 public static function setUpBeforeClass() { 11 parent::setUpBeforeClass(); 12 13 $factory = new WP_UnitTest_Factory(); 14 10 public static function wpSetUpBeforeClass( $factory ) { 15 11 self::$user_id = $factory->user->create(); 16 12 self::$post_id = $factory->post->create( array( 17 13 'post_author' => self::$user_id 18 14 ) ); 19 20 self::commit_transaction(); 21 } 22 23 public static function tearDownAfterClass() { 24 parent::tearDownAfterClass(); 25 15 } 16 17 public static function wpTearDownAfterClass() { 26 18 wp_delete_post( self::$post_id ); 27 19 … … 31 23 wp_delete_user( self::$user_id ); 32 24 } 33 34 self::commit_transaction();35 25 } 36 26 -
trunk/tests/phpunit/tests/db/charset.php
r34655 r35186 1 1 <?php 2 3 require_once dirname( dirname( __FILE__ ) ) . '/db.php';4 2 5 3 /** … … 18 16 19 17 public static function setUpBeforeClass() { 18 require_once( dirname( dirname( __FILE__ ) ) . '/db.php' ); 19 20 20 self::$_wpdb = new wpdb_exposed_methods_for_testing(); 21 21 } -
trunk/tests/phpunit/tests/feed/rss2.php
r35162 r35186 13 13 static $posts; 14 14 15 public static function setUpBeforeClass() { 16 $factory = new WP_UnitTest_Factory(); 17 15 public static function wpSetUpBeforeClass( $factory ) { 18 16 self::$user = $factory->user->create(); 19 17 self::$posts = $factory->post->create_many( 5, array( 20 18 'post_author' => self::$user, 21 19 ) ); 22 23 self::commit_transaction();24 20 } 25 21 26 public static function tearDownAfterClass() {22 public static function wpTearDownAfterClass() { 27 23 if ( is_multisite() ) { 28 24 wpmu_delete_user( self::$user ); … … 34 30 wp_delete_post( $post, true ); 35 31 } 36 37 self::commit_transaction();38 32 } 39 33 -
trunk/tests/phpunit/tests/functions/getArchives.php
r35163 r35186 19 19 } 20 20 21 public static function setUpBeforeClass() { 22 $factory = new WP_UnitTest_Factory(); 21 public static function wpSetUpBeforeClass( $factory ) { 23 22 self::$post_ids = $factory->post->create_many( 8, array( 'post_type' => 'post', 'post_author' => '1' ) ); 24 25 self::commit_transaction();26 23 } 27 24 28 public static function tearDownAfterClass() {25 public static function wpTearDownAfterClass() { 29 26 foreach ( self::$post_ids as $post_id ) { 30 27 wp_delete_post( $post_id, true ); 31 28 } 32 33 self::commit_transaction();34 29 } 35 30 … … 53 48 $link5 = get_permalink( $ids[4] ); 54 49 50 $title1 = get_post( $ids[0] )->post_title; 51 $title2 = get_post( $ids[1] )->post_title; 52 $title3 = get_post( $ids[2] )->post_title; 53 $title4 = get_post( $ids[3] )->post_title; 54 $title5 = get_post( $ids[4] )->post_title; 55 55 56 $expected['limit'] = <<<EOF 56 <li><a href='$link1'> Post title 8</a></li>57 <li><a href='$link2'> Post title 7</a></li>58 <li><a href='$link3'> Post title 6</a></li>59 <li><a href='$link4'> Post title 5</a></li>60 <li><a href='$link5'> Post title 4</a></li>57 <li><a href='$link1'>$title1</a></li> 58 <li><a href='$link2'>$title2</a></li> 59 <li><a href='$link3'>$title3</a></li> 60 <li><a href='$link4'>$title4</a></li> 61 <li><a href='$link5'>$title5</a></li> 61 62 EOF; 62 63 $this->assertEquals( $expected['limit'], trim( wp_get_archives( array( 'echo' => false, 'type' => 'postbypost', 'limit' => 5 ) ) ) ); -
trunk/tests/phpunit/tests/media.php
r35181 r35186 8 8 protected static $large_id; 9 9 10 public static function setUpBeforeClass() { 11 parent::setUpBeforeClass(); 12 13 $factory = new WP_UnitTest_Factory(); 14 10 public static function wpSetUpBeforeClass( $factory ) { 15 11 $filename = DIR_TESTDATA . '/images/test-image-large.png'; 16 12 self::$large_id = $factory->attachment->create_upload_object( $filename ); 17 18 self::commit_transaction(); 19 } 20 21 public static function tearDownAfterClass() { 22 parent::tearDownAfterClass(); 23 13 } 14 15 public static function wpTearDownAfterClass() { 24 16 wp_delete_attachment( self::$large_id ); 25 26 self::commit_transaction();27 17 } 28 18 -
trunk/tests/phpunit/tests/post.php
r35183 r35186 10 10 protected static $grammarian_id; 11 11 12 public static function setUpBeforeClass() { 13 parent::setUpBeforeClass(); 14 15 $factory = new WP_UnitTest_Factory(); 16 12 public static function wpSetUpBeforeClass( $factory ) { 17 13 self::$editor_id = $factory->user->create( array( 'role' => 'editor' ) ); 18 14 … … 25 21 26 22 self::$grammarian_id = $factory->user->create( array( 'role' => 'grammarian' ) ); 27 28 self::commit_transaction(); 29 } 30 31 public static function tearDownAfterClass() { 32 parent::tearDownAfterClass(); 33 23 } 24 25 public static function wpTearDownAfterClass() { 34 26 $ids = array( self::$editor_id, self::$grammarian_id ); 35 27 foreach ( $ids as $id ) { … … 40 32 } 41 33 } 42 43 self::commit_transaction();44 34 } 45 35 -
trunk/tests/phpunit/tests/query/date.php
r30276 r35186 13 13 static $post_ids = array(); 14 14 15 public static function setUpBeforeClass() {15 public static function wpSetUpBeforeClass( $factory ) { 16 16 // Be careful modifying this. Tests are coded to expect this exact sample data. 17 17 $post_dates = array( … … 41 41 ); 42 42 43 $factory = new WP_UnitTest_Factory;44 45 43 foreach ( $post_dates as $post_date ) { 46 44 self::$post_ids[] = $factory->post->create( array( 'post_date' => $post_date ) ); 47 45 } 48 49 self::commit_transaction(); 50 } 51 52 public static function tearDownAfterClass() { 46 } 47 48 public static function wpTearDownAfterClass() { 53 49 foreach ( self::$post_ids as $post_id ) { 54 50 wp_delete_post( $post_id, true ); 55 51 } 56 57 self::commit_transaction();58 52 } 59 53 -
trunk/tests/phpunit/tests/query/postStatus.php
r31321 r35186 12 12 public static $author_privatefoo_post; 13 13 14 public static function setUpBeforeClass() { 15 $f = new WP_UnitTest_Factory; 16 17 self::$editor_user = $f->user->create( array( 'role' => 'editor' ) ); 18 self::$author_user = $f->user->create( array( 'role' => 'author' ) ); 19 20 self::$editor_private_post = $f->post->create( array( 'post_author' => self::$editor_user, 'post_status' => 'private' ) ); 21 self::$author_private_post = $f->post->create( array( 'post_author' => self::$author_user, 'post_status' => 'private' ) ); 14 public static function wpSetUpBeforeClass( $factory ) { 15 self::$editor_user = $factory->user->create( array( 'role' => 'editor' ) ); 16 self::$author_user = $factory->user->create( array( 'role' => 'author' ) ); 17 18 self::$editor_private_post = $factory->post->create( array( 'post_author' => self::$editor_user, 'post_status' => 'private' ) ); 19 self::$author_private_post = $factory->post->create( array( 'post_author' => self::$author_user, 'post_status' => 'private' ) ); 22 20 23 21 // Custom status with private=true. 24 22 register_post_status( 'privatefoo', array( 'private' => true ) ); 25 self::$editor_privatefoo_post = $f ->post->create( array( 'post_author' => self::$editor_user, 'post_status' => 'privatefoo' ) );26 self::$author_privatefoo_post = $f ->post->create( array( 'post_author' => self::$author_user, 'post_status' => 'privatefoo' ) );23 self::$editor_privatefoo_post = $factory->post->create( array( 'post_author' => self::$editor_user, 'post_status' => 'privatefoo' ) ); 24 self::$author_privatefoo_post = $factory->post->create( array( 'post_author' => self::$author_user, 'post_status' => 'privatefoo' ) ); 27 25 _unregister_post_status( 'privatefoo' ); 28 29 self::commit_transaction(); 30 } 31 32 public static function tearDownAfterClass() { 26 } 27 28 public static function wpTearDownAfterClass() { 33 29 if ( is_multisite() ) { 34 30 wpmu_delete_user( self::$editor_user ); … … 43 39 wp_delete_post( self::$editor_privatefoo_post, true ); 44 40 wp_delete_post( self::$author_privatefoo_post, true ); 45 46 self::commit_transaction();47 41 } 48 42 -
trunk/tests/phpunit/tests/query/results.php
r34802 r35186 23 23 static $child_four; 24 24 25 public static function setUpBeforeClass() { 26 $factory = new WP_UnitTest_Factory; 27 25 public static function wpSetUpBeforeClass( $factory ) { 28 26 self::$cat_ids[] = $cat_a = $factory->term->create( array( 'taxonomy' => 'category', 'name' => 'cat-a' ) ); 29 27 self::$cat_ids[] = $cat_b = $factory->term->create( array( 'taxonomy' => 'category', 'name' => 'cat-b' ) ); … … 68 66 self::$post_ids[] = self::$child_three = $factory->post->create( array( 'post_title' => 'child-three', 'post_parent' => self::$parent_two, 'post_date' => '2007-01-01 00:00:03' ) ); 69 67 self::$post_ids[] = self::$child_four = $factory->post->create( array( 'post_title' => 'child-four', 'post_parent' => self::$parent_two, 'post_date' => '2007-01-01 00:00:04' ) ); 70 71 self::commit_transaction(); 72 } 73 74 public static function tearDownAfterClass() { 68 } 69 70 public static function wpTearDownAfterClass() { 75 71 foreach ( self::$cat_ids as $cat_id ) { 76 72 wp_delete_term( $cat_id, 'category' ); … … 84 80 wp_delete_post( $post_id, true ); 85 81 } 86 87 self::commit_transaction();88 82 } 89 83 -
trunk/tests/phpunit/tests/query/stickies.php
r31439 r35186 9 9 static $posts = array(); 10 10 11 public static function setUpBeforeClass() { 12 $f = new WP_UnitTest_Factory(); 13 11 public static function wpSetUpBeforeClass( $factory ) { 14 12 // Set post times to get a reliable order. 15 13 $now = time(); 16 14 for ( $i = 0; $i <= 22; $i++ ) { 17 15 $post_date = date( 'Y-m-d H:i:s', $now - ( 10 * $i ) ); 18 self::$posts[ $i ] = $f ->post->create( array(16 self::$posts[ $i ] = $factory->post->create( array( 19 17 'post_date' => $post_date, 20 18 ) ); … … 24 22 stick_post( self::$posts[14] ); 25 23 stick_post( self::$posts[8] ); 26 27 self::commit_transaction();28 24 } 29 25 30 public static function tearDownAfterClass() {26 public static function wpTearDownAfterClass() { 31 27 foreach ( self::$posts as $p ) { 32 28 wp_delete_post( $p, true ); 33 29 } 34 35 self::commit_transaction();36 30 } 37 31 -
trunk/tests/phpunit/tests/term.php
r35185 r35186 8 8 protected static $post_ids = array(); 9 9 10 public static function setUpBeforeClass() { 11 parent::setUpBeforeClass(); 12 13 $factory = new WP_UnitTest_Factory(); 14 10 public static function wpSetUpBeforeClass( $factory ) { 15 11 self::$post_ids = $factory->post->create_many( 5 ); 16 17 self::commit_transaction(); 18 } 19 20 public static function tearDownAfterClass() { 21 parent::tearDownAfterClass(); 22 12 } 13 14 public static function wpTearDownAfterClass() { 23 15 array_map( 'wp_delete_post', self::$post_ids ); 24 25 self::commit_transaction();26 16 } 27 17 -
trunk/tests/phpunit/tests/user/countUserPosts.php
r32523 r35186 9 9 static $post_ids = array(); 10 10 11 public static function setUpBeforeClass() { 12 $factory = new WP_UnitTest_Factory(); 13 11 public static function wpSetUpBeforeClass( $factory ) { 14 12 self::$user_id = $factory->user->create( array( 15 13 'role' => 'author', … … 34 32 'post_type' => 'wptests_pt', 35 33 ) ) ); 36 37 self::commit_transaction();38 34 } 39 35 40 public static function tearDownAfterClass() {36 public static function wpTearDownAfterClass() { 41 37 if ( is_multisite() ) { 42 38 wpmu_delete_user( self::$user_id ); … … 48 44 wp_delete_post( $post_id, true ); 49 45 } 50 51 self::commit_transaction();52 46 } 53 47 -
trunk/tests/phpunit/tests/user/listAuthors.php
r31676 r35186 24 24 'html' => true ); 25 25 */ 26 public static function setUpBeforeClass() { 27 $factory = new WP_UnitTest_Factory; 28 26 public static function wpSetUpBeforeClass( $factory ) { 29 27 self::$users[] = $factory->user->create( array( 'user_login' => 'zack', 'display_name' => 'zack', 'role' => 'author', 'first_name' => 'zack', 'last_name' => 'moon' ) ); 30 28 self::$users[] = $factory->user->create( array( 'user_login' => 'bob', 'display_name' => 'bob', 'role' => 'author', 'first_name' => 'bob', 'last_name' => 'reno' ) ); … … 41 39 self::$user_urls[] = get_author_posts_url( $userid ); 42 40 } 43 44 self::commit_transaction();45 41 } 46 42 47 public static function tearDownAfterClass() {43 public static function wpTearDownAfterClass() { 48 44 foreach ( array_merge( self::$users, array( self::$fred_id ) ) as $user_id ) { 49 45 if ( is_multisite() ) { … … 57 53 wp_delete_post( $post_id, true ); 58 54 } 59 60 self::commit_transaction();61 55 } 62 56
Note: See TracChangeset
for help on using the changeset viewer.