mirror of
git://develop.git.wordpress.org/
synced 2025-01-18 05:18:42 +01:00
Tests: Share fixtures in term endpoint tests.
See #30017. git-svn-id: https://develop.svn.wordpress.org/trunk@38941 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
bfce3fda86
commit
8a883144b6
@ -10,17 +10,23 @@
|
||||
* @group restapi
|
||||
*/
|
||||
class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
protected static $administrator;
|
||||
protected static $subscriber;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->administrator = $this->factory->user->create( array(
|
||||
public static function wpSetUpBeforeClass( $factory ) {
|
||||
self::$administrator = $factory->user->create( array(
|
||||
'role' => 'administrator',
|
||||
) );
|
||||
$this->subscriber = $this->factory->user->create( array(
|
||||
self::$subscriber = $factory->user->create( array(
|
||||
'role' => 'subscriber',
|
||||
) );
|
||||
}
|
||||
|
||||
public static function wpTearDownAfterClass() {
|
||||
self::delete_user( self::$administrator );
|
||||
self::delete_user( self::$subscriber );
|
||||
}
|
||||
|
||||
public function test_register_routes() {
|
||||
$routes = $this->server->get_routes();
|
||||
$this->assertArrayHasKey( '/wp/v2/tags', $routes );
|
||||
@ -450,7 +456,7 @@ class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
}
|
||||
|
||||
public function test_create_item() {
|
||||
wp_set_current_user( $this->administrator );
|
||||
wp_set_current_user( self::$administrator );
|
||||
$request = new WP_REST_Request( 'POST', '/wp/v2/tags' );
|
||||
$request->set_param( 'name', 'My Awesome Term' );
|
||||
$request->set_param( 'description', 'This term is so awesome.' );
|
||||
@ -466,7 +472,7 @@ class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
}
|
||||
|
||||
public function test_create_item_incorrect_permissions() {
|
||||
wp_set_current_user( $this->subscriber );
|
||||
wp_set_current_user( self::$subscriber );
|
||||
$request = new WP_REST_Request( 'POST', '/wp/v2/tags' );
|
||||
$request->set_param( 'name', 'Incorrect permissions' );
|
||||
$response = $this->server->dispatch( $request );
|
||||
@ -474,14 +480,14 @@ class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
}
|
||||
|
||||
public function test_create_item_missing_arguments() {
|
||||
wp_set_current_user( $this->administrator );
|
||||
wp_set_current_user( self::$administrator );
|
||||
$request = new WP_REST_Request( 'POST', '/wp/v2/tags' );
|
||||
$response = $this->server->dispatch( $request );
|
||||
$this->assertErrorResponse( 'rest_missing_callback_param', $response, 400 );
|
||||
}
|
||||
|
||||
public function test_create_item_parent_non_hierarchical_taxonomy() {
|
||||
wp_set_current_user( $this->administrator );
|
||||
wp_set_current_user( self::$administrator );
|
||||
|
||||
$request = new WP_REST_Request( 'POST', '/wp/v2/tags' );
|
||||
$request->set_param( 'name', 'My Awesome Term' );
|
||||
@ -491,7 +497,7 @@ class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
}
|
||||
|
||||
public function test_update_item() {
|
||||
wp_set_current_user( $this->administrator );
|
||||
wp_set_current_user( self::$administrator );
|
||||
$orig_args = array(
|
||||
'name' => 'Original Name',
|
||||
'description' => 'Original Description',
|
||||
@ -511,7 +517,7 @@ class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
}
|
||||
|
||||
public function test_update_item_invalid_term() {
|
||||
wp_set_current_user( $this->administrator );
|
||||
wp_set_current_user( self::$administrator );
|
||||
$request = new WP_REST_Request( 'POST', '/wp/v2/tags/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER );
|
||||
$request->set_param( 'name', 'Invalid Term' );
|
||||
$response = $this->server->dispatch( $request );
|
||||
@ -519,7 +525,7 @@ class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
}
|
||||
|
||||
public function test_update_item_incorrect_permissions() {
|
||||
wp_set_current_user( $this->subscriber );
|
||||
wp_set_current_user( self::$subscriber );
|
||||
$term = get_term_by( 'id', $this->factory->tag->create(), 'post_tag' );
|
||||
$request = new WP_REST_Request( 'POST', '/wp/v2/tags/' . $term->term_id );
|
||||
$request->set_param( 'name', 'Incorrect permissions' );
|
||||
@ -528,7 +534,7 @@ class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
}
|
||||
|
||||
public function test_update_item_parent_non_hierarchical_taxonomy() {
|
||||
wp_set_current_user( $this->administrator );
|
||||
wp_set_current_user( self::$administrator );
|
||||
$term = get_term_by( 'id', $this->factory->tag->create(), 'post_tag' );
|
||||
|
||||
$request = new WP_REST_Request( 'POST', '/wp/v2/tags/' . $term->term_id );
|
||||
@ -538,7 +544,7 @@ class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
}
|
||||
|
||||
public function test_delete_item() {
|
||||
wp_set_current_user( $this->administrator );
|
||||
wp_set_current_user( self::$administrator );
|
||||
$term = get_term_by( 'id', $this->factory->tag->create( array( 'name' => 'Deleted Tag' ) ), 'post_tag' );
|
||||
$request = new WP_REST_Request( 'DELETE', '/wp/v2/tags/' . $term->term_id );
|
||||
$request->set_param( 'force', true );
|
||||
@ -549,7 +555,7 @@ class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
}
|
||||
|
||||
public function test_delete_item_force_false() {
|
||||
wp_set_current_user( $this->administrator );
|
||||
wp_set_current_user( self::$administrator );
|
||||
$term = get_term_by( 'id', $this->factory->tag->create( array( 'name' => 'Deleted Tag' ) ), 'post_tag' );
|
||||
$request = new WP_REST_Request( 'DELETE', '/wp/v2/tags/' . $term->term_id );
|
||||
// force defaults to false
|
||||
@ -558,14 +564,14 @@ class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
}
|
||||
|
||||
public function test_delete_item_invalid_term() {
|
||||
wp_set_current_user( $this->administrator );
|
||||
wp_set_current_user( self::$administrator );
|
||||
$request = new WP_REST_Request( 'DELETE', '/wp/v2/tags/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER );
|
||||
$response = $this->server->dispatch( $request );
|
||||
$this->assertErrorResponse( 'rest_term_invalid', $response, 404 );
|
||||
}
|
||||
|
||||
public function test_delete_item_incorrect_permissions() {
|
||||
wp_set_current_user( $this->subscriber );
|
||||
wp_set_current_user( self::$subscriber );
|
||||
$term = get_term_by( 'id', $this->factory->tag->create(), 'post_tag' );
|
||||
$request = new WP_REST_Request( 'DELETE', '/wp/v2/tags/' . $term->term_id );
|
||||
$response = $this->server->dispatch( $request );
|
||||
@ -652,7 +658,7 @@ class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
'update_callback' => array( $this, 'additional_field_update_callback' ),
|
||||
) );
|
||||
|
||||
wp_set_current_user( $this->administrator );
|
||||
wp_set_current_user( self::$administrator );
|
||||
$tag_id = $this->factory->tag->create();
|
||||
// Check for error on update.
|
||||
$request = new WP_REST_Request( 'POST', sprintf( '/wp/v2/tags/%d', $tag_id ) );
|
||||
|
Loading…
x
Reference in New Issue
Block a user