Unit Tests: better fixtures for `Tests_Meta_Slashes` and `Tests_WP_Customize_Section`.

See #30017, #33968.



git-svn-id: https://develop.svn.wordpress.org/trunk@35249 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor 2015-10-17 21:28:43 +00:00
parent 80b732819b
commit 768958f7a0
2 changed files with 35 additions and 11 deletions

View File

@ -6,6 +6,18 @@
* @group customize
*/
class Tests_WP_Customize_Section extends WP_UnitTestCase {
protected static $admin_id;
protected static $user_ids = array();
public static function wpSetUpBeforeClass( $factory ) {
self::$user_ids[] = self::$admin_id = $factory->user->create( array( 'role' => 'administrator' ) );
}
public static function wpTearDownAfterClass() {
foreach ( self::$user_ids as $id ) {
self::delete_user( $id );
}
}
/**
* @var WP_Customize_Manager
@ -135,8 +147,7 @@ class Tests_WP_Customize_Section extends WP_UnitTestCase {
* @see WP_Customize_Section::check_capabilities()
*/
function test_check_capabilities() {
$user_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
wp_set_current_user( $user_id );
wp_set_current_user( self::$admin_id );
$section = new WP_Customize_Section( $this->manager, 'foo' );
$this->assertTrue( $section->check_capabilities() );
@ -161,7 +172,7 @@ class Tests_WP_Customize_Section extends WP_UnitTestCase {
* @see WP_Customize_Section::maybe_render()
*/
function test_maybe_render() {
wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
wp_set_current_user( self::$admin_id );
$section = new WP_Customize_Section( $this->manager, 'bar' );
$customize_render_section_count = did_action( 'customize_render_section' );
add_action( 'customize_render_section', array( $this, 'action_customize_render_section_test' ) );
@ -186,7 +197,7 @@ class Tests_WP_Customize_Section extends WP_UnitTestCase {
* @see WP_Customize_Section::print_template()
*/
function test_print_templates_standard() {
wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
wp_set_current_user( self::$admin_id );
$section = new WP_Customize_Section( $this->manager, 'baz' );
ob_start();
@ -201,7 +212,7 @@ class Tests_WP_Customize_Section extends WP_UnitTestCase {
* @see WP_Customize_Section::print_template()
*/
function test_print_templates_custom() {
wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
wp_set_current_user( self::$admin_id );
$section = new Custom_Section_Test( $this->manager, 'baz' );
ob_start();

View File

@ -6,12 +6,26 @@
* @ticket 21767
*/
class Tests_Meta_Slashes extends WP_UnitTestCase {
protected static $editor_id;
protected static $post_id;
protected static $comment_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 ) );
}
public static function wpTearDownAfterClass() {
self::delete_user( self::$editor_id );
wp_delete_comment( self::$comment_id, true );
wp_delete_post( self::$post_id, true );
}
function setUp() {
parent::setUp();
$this->author_id = self::factory()->user->create( array( 'role' => 'editor' ) );
$this->post_id = self::factory()->post->create();
wp_set_current_user( $this->author_id );
wp_set_current_user( self::$editor_id );
$this->slash_1 = 'String with 1 slash \\';
$this->slash_2 = 'String with 2 slashes \\\\';
@ -169,7 +183,7 @@ class Tests_Meta_Slashes extends WP_UnitTestCase {
*
*/
function test_add_comment_meta() {
$id = self::factory()->comment->create( array( 'comment_post_ID' => $this->post_id ) );
$id = self::$comment_id;
add_comment_meta( $id, 'slash_test_1', $this->slash_1 );
add_comment_meta( $id, 'slash_test_2', $this->slash_3 );
@ -193,7 +207,7 @@ class Tests_Meta_Slashes extends WP_UnitTestCase {
*
*/
function test_update_comment_meta() {
$id = self::factory()->comment->create( array( 'comment_post_ID' => $this->post_id ) );
$id = self::$comment_id;
add_comment_meta( $id, 'slash_test_1', 'foo' );
add_comment_meta( $id, 'slash_test_2', 'foo' );
@ -267,5 +281,4 @@ class Tests_Meta_Slashes extends WP_UnitTestCase {
$this->assertEquals( wp_unslash( $this->slash_4 ), get_user_meta( $id, 'slash_test_2', true ) );
$this->assertEquals( wp_unslash( $this->slash_6 ), get_user_meta( $id, 'slash_test_3', true ) );
}
}