Skip to content

Commit

Permalink
Tests: Speed up slashed data tests by reusing shared fixtures.
Browse files Browse the repository at this point in the history
Follow-up to [35249].

See #51344.

git-svn-id: https://develop.svn.wordpress.org/trunk@49003 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed Sep 19, 2020
1 parent 0c5324d commit ffc1293
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 11 deletions.
10 changes: 8 additions & 2 deletions tests/phpunit/tests/attachment/slashes.php
Expand Up @@ -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.
Expand Down
12 changes: 9 additions & 3 deletions tests/phpunit/tests/comment/slashes.php
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/tests/option/slashes.php
Expand Up @@ -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 \\';
Expand Down
9 changes: 7 additions & 2 deletions tests/phpunit/tests/post/slashes.php
Expand Up @@ -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.
Expand Down
9 changes: 7 additions & 2 deletions tests/phpunit/tests/term/slashes.php
Expand Up @@ -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 \\\\';
Expand Down
9 changes: 7 additions & 2 deletions tests/phpunit/tests/user/slashes.php
Expand Up @@ -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.
Expand Down

0 comments on commit ffc1293

Please sign in to comment.