Make WordPress Core

Changeset 35249


Ignore:
Timestamp:
10/17/2015 09:28:43 PM (11 years ago)
Author:
wonderboymusic
Message:

Unit Tests: better fixtures for Tests_Meta_Slashes and Tests_WP_Customize_Section.

See #30017, #33968.

Location:
trunk/tests/phpunit/tests
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/customize/section.php

    r35242 r35249  
    77 */
    88class Tests_WP_Customize_Section extends WP_UnitTestCase {
     9        protected static $admin_id;
     10        protected static $user_ids = array();
     11
     12        public static function wpSetUpBeforeClass( $factory ) {
     13                self::$user_ids[] = self::$admin_id = $factory->user->create( array( 'role' => 'administrator' ) );
     14        }
     15
     16        public static function wpTearDownAfterClass() {
     17                foreach ( self::$user_ids as $id ) {
     18                        self::delete_user( $id );
     19                }
     20        }
    921
    1022        /**
     
    136148         */
    137149        function test_check_capabilities() {
    138                 $user_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
    139                 wp_set_current_user( $user_id );
     150                wp_set_current_user( self::$admin_id );
    140151
    141152                $section = new WP_Customize_Section( $this->manager, 'foo' );
     
    162173         */
    163174        function test_maybe_render() {
    164                 wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     175                wp_set_current_user( self::$admin_id );
    165176                $section = new WP_Customize_Section( $this->manager, 'bar' );
    166177                $customize_render_section_count = did_action( 'customize_render_section' );
     
    187198         */
    188199        function test_print_templates_standard() {
    189                 wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     200                wp_set_current_user( self::$admin_id );
    190201
    191202                $section = new WP_Customize_Section( $this->manager, 'baz' );
     
    202213         */
    203214        function test_print_templates_custom() {
    204                 wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     215                wp_set_current_user( self::$admin_id );
    205216
    206217                $section = new Custom_Section_Test( $this->manager, 'baz' );
  • trunk/tests/phpunit/tests/meta/slashes.php

    r35244 r35249  
    77 */
    88class Tests_Meta_Slashes extends WP_UnitTestCase {
     9        protected static $editor_id;
     10        protected static $post_id;
     11        protected static $comment_id;
     12
     13        public static function wpSetUpBeforeClass( $factory ) {
     14                self::$editor_id = $factory->user->create( array( 'role' => 'editor' ) );
     15                self::$post_id = $factory->post->create();
     16                self::$comment_id = $factory->comment->create( array( 'comment_post_ID' => self::$post_id ) );
     17        }
     18
     19        public static function wpTearDownAfterClass() {
     20                self::delete_user( self::$editor_id );
     21                wp_delete_comment( self::$comment_id, true );
     22                wp_delete_post( self::$post_id, true );
     23        }
     24
    925        function setUp() {
    1026                parent::setUp();
    11                 $this->author_id = self::factory()->user->create( array( 'role' => 'editor' ) );
    12                 $this->post_id = self::factory()->post->create();
    13 
    14                 wp_set_current_user( $this->author_id );
     27
     28                wp_set_current_user( self::$editor_id );
    1529
    1630                $this->slash_1 = 'String with 1 slash \\';
     
    170184         */
    171185        function test_add_comment_meta() {
    172                 $id = self::factory()->comment->create( array( 'comment_post_ID' => $this->post_id ) );
     186                $id = self::$comment_id;
    173187
    174188                add_comment_meta( $id, 'slash_test_1', $this->slash_1 );
     
    194208         */
    195209        function test_update_comment_meta() {
    196                 $id = self::factory()->comment->create( array( 'comment_post_ID' => $this->post_id ) );
     210                $id = self::$comment_id;
    197211
    198212                add_comment_meta( $id, 'slash_test_1', 'foo' );
     
    268282                $this->assertEquals( wp_unslash( $this->slash_6 ), get_user_meta( $id, 'slash_test_3', true ) );
    269283        }
    270 
    271284}
Note: See TracChangeset for help on using the changeset viewer.