diff --git a/tests/phpunit/tests/attachment/slashes.php b/tests/phpunit/tests/attachment/slashes.php index 082efb110e..14bf7d4017 100644 --- a/tests/phpunit/tests/attachment/slashes.php +++ b/tests/phpunit/tests/attachment/slashes.php @@ -6,10 +6,16 @@ * @ticket 21767 */ class Tests_Attachment_Slashes extends WP_UnitTestCase { + protected static $author_id; + + public static function wpSetUpBeforeClass( $factory ) { + self::$author_id = $factory->user->create( array( 'role' => 'editor' ) ); + } + function setUp() { parent::setUp(); - $this->author_id = self::factory()->user->create( array( 'role' => 'editor' ) ); - wp_set_current_user( $this->author_id ); + + wp_set_current_user( self::$author_id ); // It is important to test with both even and odd numbered slashes, // as KSES does a strip-then-add slashes in some of its function calls. diff --git a/tests/phpunit/tests/comment/slashes.php b/tests/phpunit/tests/comment/slashes.php index 8fab42b997..d6370c342e 100644 --- a/tests/phpunit/tests/comment/slashes.php +++ b/tests/phpunit/tests/comment/slashes.php @@ -6,11 +6,17 @@ * @ticket 21767 */ class Tests_Comment_Slashes extends WP_UnitTestCase { + protected static $author_id; + + public static function wpSetUpBeforeClass( $factory ) { + // We need an admin user to bypass comment flood protection. + self::$author_id = $factory->user->create( array( 'role' => 'administrator' ) ); + } + function setUp() { parent::setUp(); - // We need an admin user to bypass comment flood protection. - $this->author_id = self::factory()->user->create( array( 'role' => 'administrator' ) ); - wp_set_current_user( $this->author_id ); + + wp_set_current_user( self::$author_id ); // It is important to test with both even and odd numbered slashes, // as KSES does a strip-then-add slashes in some of its function calls. diff --git a/tests/phpunit/tests/option/slashes.php b/tests/phpunit/tests/option/slashes.php index 20220e5d58..8d7491fe76 100644 --- a/tests/phpunit/tests/option/slashes.php +++ b/tests/phpunit/tests/option/slashes.php @@ -6,8 +6,10 @@ * @ticket 21767 */ class Tests_Option_Slashes extends WP_UnitTestCase { + function setUp() { parent::setUp(); + // It is important to test with both even and odd numbered slashes, // as KSES does a strip-then-add slashes in some of its function calls. $this->slash_1 = 'String with 1 slash \\'; diff --git a/tests/phpunit/tests/post/slashes.php b/tests/phpunit/tests/post/slashes.php index 229ec29aa2..bc8b1d8dc0 100644 --- a/tests/phpunit/tests/post/slashes.php +++ b/tests/phpunit/tests/post/slashes.php @@ -6,11 +6,16 @@ * @ticket 21767 */ class Tests_Post_Slashes extends WP_UnitTestCase { + protected static $author_id; + + public static function wpSetUpBeforeClass( $factory ) { + self::$author_id = $factory->user->create( array( 'role' => 'editor' ) ); + } + function setUp() { parent::setUp(); - $this->author_id = self::factory()->user->create( array( 'role' => 'editor' ) ); - wp_set_current_user( $this->author_id ); + wp_set_current_user( self::$author_id ); // It is important to test with both even and odd numbered slashes, // as KSES does a strip-then-add slashes in some of its function calls. diff --git a/tests/phpunit/tests/term/slashes.php b/tests/phpunit/tests/term/slashes.php index ea04097bbe..967e4834bd 100644 --- a/tests/phpunit/tests/term/slashes.php +++ b/tests/phpunit/tests/term/slashes.php @@ -6,11 +6,16 @@ * @ticket 21767 */ class Tests_Term_Slashes extends WP_Ajax_UnitTestCase { + protected static $author_id; + + public static function wpSetUpBeforeClass( $factory ) { + self::$author_id = $factory->user->create( array( 'role' => 'administrator' ) ); + } + function setUp() { parent::setUp(); - $this->author_id = self::factory()->user->create( array( 'role' => 'administrator' ) ); - wp_set_current_user( $this->author_id ); + wp_set_current_user( self::$author_id ); $this->slash_1 = 'String with 1 slash \\'; $this->slash_2 = 'String with 2 slashes \\\\'; diff --git a/tests/phpunit/tests/user/slashes.php b/tests/phpunit/tests/user/slashes.php index e5675abb5d..87def324af 100644 --- a/tests/phpunit/tests/user/slashes.php +++ b/tests/phpunit/tests/user/slashes.php @@ -6,11 +6,16 @@ * @ticket 21767 */ class Tests_User_Slashes extends WP_UnitTestCase { + protected static $author_id; + + public static function wpSetUpBeforeClass( $factory ) { + self::$author_id = $factory->user->create( array( 'role' => 'administrator' ) ); + } + function setUp() { parent::setUp(); - $this->author_id = self::factory()->user->create( array( 'role' => 'administrator' ) ); - wp_set_current_user( $this->author_id ); + wp_set_current_user( self::$author_id ); // It is important to test with both even and odd numbered slashes, // as KSES does a strip-then-add slashes in some of its function calls.