Tests: Speed up slashed data tests by reusing some more shared fixtures.
Follow-up to [35249], [49003]. See #51344. git-svn-id: https://develop.svn.wordpress.org/trunk@49005 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
4018e92c39
commit
898eb5fc51
@ -7,10 +7,12 @@
|
||||
*/
|
||||
class Tests_Comment_Slashes extends WP_UnitTestCase {
|
||||
protected static $author_id;
|
||||
protected static $post_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' ) );
|
||||
self::$post_id = $factory->post->create();
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
@ -33,7 +35,7 @@ class Tests_Comment_Slashes extends WP_UnitTestCase {
|
||||
* Tests the extended model function that expects slashed data.
|
||||
*/
|
||||
function test_wp_new_comment() {
|
||||
$post_id = self::factory()->post->create();
|
||||
$post_id = self::$post_id;
|
||||
|
||||
// Not testing comment_author_email or comment_author_url
|
||||
// as slashes are not permitted in that data.
|
||||
@ -72,7 +74,7 @@ class Tests_Comment_Slashes extends WP_UnitTestCase {
|
||||
* Tests the controller function that expects slashed data.
|
||||
*/
|
||||
function test_edit_comment() {
|
||||
$post_id = self::factory()->post->create();
|
||||
$post_id = self::$post_id;
|
||||
$comment_id = self::factory()->comment->create(
|
||||
array(
|
||||
'comment_post_ID' => $post_id,
|
||||
@ -118,7 +120,7 @@ class Tests_Comment_Slashes extends WP_UnitTestCase {
|
||||
* Tests the model function that expects slashed data.
|
||||
*/
|
||||
function test_wp_insert_comment() {
|
||||
$post_id = self::factory()->post->create();
|
||||
$post_id = self::$post_id;
|
||||
|
||||
$comment_id = wp_insert_comment(
|
||||
array(
|
||||
@ -149,7 +151,7 @@ class Tests_Comment_Slashes extends WP_UnitTestCase {
|
||||
* Tests the model function that expects slashed data.
|
||||
*/
|
||||
function test_wp_update_comment() {
|
||||
$post_id = self::factory()->post->create();
|
||||
$post_id = self::$post_id;
|
||||
$comment_id = self::factory()->comment->create(
|
||||
array(
|
||||
'comment_post_ID' => $post_id,
|
||||
|
@ -9,11 +9,13 @@ class Tests_Meta_Slashes extends WP_UnitTestCase {
|
||||
protected static $editor_id;
|
||||
protected static $post_id;
|
||||
protected static $comment_id;
|
||||
protected static $user_id;
|
||||
|
||||
public static function wpSetUpBeforeClass( $factory ) {
|
||||
self::$editor_id = $factory->user->create( array( 'role' => 'editor' ) );
|
||||
self::$post_id = $factory->post->create();
|
||||
self::$comment_id = $factory->comment->create( array( 'comment_post_ID' => self::$post_id ) );
|
||||
self::$user_id = $factory->user->create();
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
@ -34,7 +36,7 @@ class Tests_Meta_Slashes extends WP_UnitTestCase {
|
||||
* Tests the controller function that expects slashed data.
|
||||
*/
|
||||
function test_edit_post() {
|
||||
$post_id = self::factory()->post->create();
|
||||
$post_id = self::$post_id;
|
||||
|
||||
if ( function_exists( 'wp_add_post_meta' ) ) {
|
||||
$meta_1 = wp_add_post_meta( $post_id, 'slash_test_1', 'foo' );
|
||||
@ -111,7 +113,7 @@ class Tests_Meta_Slashes extends WP_UnitTestCase {
|
||||
* Tests the legacy model function that expects slashed data.
|
||||
*/
|
||||
function test_add_post_meta() {
|
||||
$post_id = self::factory()->post->create();
|
||||
$post_id = self::$post_id;
|
||||
|
||||
add_post_meta( $post_id, 'slash_test_1', addslashes( $this->slash_1 ) );
|
||||
add_post_meta( $post_id, 'slash_test_2', addslashes( $this->slash_3 ) );
|
||||
@ -126,7 +128,7 @@ class Tests_Meta_Slashes extends WP_UnitTestCase {
|
||||
* Tests the legacy model function that expects slashed data.
|
||||
*/
|
||||
function test_update_post_meta() {
|
||||
$post_id = self::factory()->post->create();
|
||||
$post_id = self::$post_id;
|
||||
|
||||
update_post_meta( $post_id, 'slash_test_1', addslashes( $this->slash_1 ) );
|
||||
update_post_meta( $post_id, 'slash_test_2', addslashes( $this->slash_3 ) );
|
||||
@ -191,7 +193,7 @@ class Tests_Meta_Slashes extends WP_UnitTestCase {
|
||||
* Tests the model function that expects slashed data.
|
||||
*/
|
||||
function test_add_user_meta() {
|
||||
$user_id = self::factory()->user->create();
|
||||
$user_id = self::$user_id;
|
||||
|
||||
add_user_meta( $user_id, 'slash_test_1', $this->slash_1 );
|
||||
add_user_meta( $user_id, 'slash_test_2', $this->slash_3 );
|
||||
@ -214,7 +216,7 @@ class Tests_Meta_Slashes extends WP_UnitTestCase {
|
||||
* Tests the model function that expects slashed data.
|
||||
*/
|
||||
function test_update_user_meta() {
|
||||
$user_id = self::factory()->user->create();
|
||||
$user_id = self::$user_id;
|
||||
|
||||
add_user_meta( $user_id, 'slash_test_1', 'foo' );
|
||||
add_user_meta( $user_id, 'slash_test_2', 'foo' );
|
||||
|
@ -7,9 +7,11 @@
|
||||
*/
|
||||
class Tests_Post_Slashes extends WP_UnitTestCase {
|
||||
protected static $author_id;
|
||||
protected static $post_id;
|
||||
|
||||
public static function wpSetUpBeforeClass( $factory ) {
|
||||
self::$author_id = $factory->user->create( array( 'role' => 'editor' ) );
|
||||
self::$post_id = $factory->post->create();
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
@ -32,7 +34,7 @@ class Tests_Post_Slashes extends WP_UnitTestCase {
|
||||
* Tests the controller function that expects slashed data.
|
||||
*/
|
||||
function test_edit_post() {
|
||||
$post_id = self::factory()->post->create();
|
||||
$post_id = self::$post_id;
|
||||
|
||||
$_POST = array();
|
||||
$_POST['post_ID'] = $post_id;
|
||||
@ -105,7 +107,7 @@ class Tests_Post_Slashes extends WP_UnitTestCase {
|
||||
* Tests the model function that expects slashed data.
|
||||
*/
|
||||
function test_wp_update_post() {
|
||||
$post_id = self::factory()->post->create();
|
||||
$post_id = self::$post_id;
|
||||
|
||||
wp_update_post(
|
||||
array(
|
||||
|
@ -7,9 +7,11 @@
|
||||
*/
|
||||
class Tests_User_Slashes extends WP_UnitTestCase {
|
||||
protected static $author_id;
|
||||
protected static $user_id;
|
||||
|
||||
public static function wpSetUpBeforeClass( $factory ) {
|
||||
self::$author_id = $factory->user->create( array( 'role' => 'administrator' ) );
|
||||
self::$user_id = $factory->user->create();
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
@ -87,7 +89,7 @@ class Tests_User_Slashes extends WP_UnitTestCase {
|
||||
* Tests the controller function that expects slashed data.
|
||||
*/
|
||||
function test_edit_user() {
|
||||
$user_id = self::factory()->user->create();
|
||||
$user_id = self::$user_id;
|
||||
|
||||
$_POST = array();
|
||||
$_GET = array();
|
||||
@ -185,7 +187,7 @@ class Tests_User_Slashes extends WP_UnitTestCase {
|
||||
* Tests the model function that expects slashed data.
|
||||
*/
|
||||
function test_wp_update_user() {
|
||||
$user_id = self::factory()->user->create();
|
||||
$user_id = self::$user_id;
|
||||
$user_id = wp_update_user(
|
||||
array(
|
||||
'ID' => $user_id,
|
||||
|
Loading…
Reference in New Issue
Block a user