- Timestamp:
- 10/27/2016 02:56:28 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-categories-controller.php
r38942 r38975 12 12 */ 13 13 class WP_Test_REST_Categories_Controller extends WP_Test_REST_Controller_Testcase { 14 15 public function setUp() { 16 parent::setUp(); 17 $this->administrator = $this->factory->user->create( array( 14 protected static $administrator; 15 protected static $subscriber; 16 17 public static function wpSetUpBeforeClass( $factory ) { 18 self::$administrator = $factory->user->create( array( 18 19 'role' => 'administrator', 19 20 ) ); 20 $this->subscriber = $this->factory->user->create( array(21 self::$subscriber = $factory->user->create( array( 21 22 'role' => 'subscriber', 22 23 ) ); 24 } 25 26 public static function wpTearDownAfterClass() { 27 self::delete_user( self::$administrator ); 28 self::delete_user( self::$subscriber ); 23 29 } 24 30 … … 573 579 574 580 public function test_create_item() { 575 wp_set_current_user( $this->administrator );581 wp_set_current_user( self::$administrator ); 576 582 $request = new WP_REST_Request( 'POST', '/wp/v2/categories' ); 577 583 $request->set_param( 'name', 'My Awesome Term' ); … … 589 595 590 596 public function test_create_item_invalid_taxonomy() { 591 wp_set_current_user( $this->administrator );597 wp_set_current_user( self::$administrator ); 592 598 $request = new WP_REST_Request( 'POST', '/wp/v2/invalid-taxonomy' ); 593 599 $request->set_param( 'name', 'Invalid Taxonomy' ); … … 597 603 598 604 public function test_create_item_incorrect_permissions() { 599 wp_set_current_user( $this->subscriber );605 wp_set_current_user( self::$subscriber ); 600 606 $request = new WP_REST_Request( 'POST', '/wp/v2/categories' ); 601 607 $request->set_param( 'name', 'Incorrect permissions' ); … … 605 611 606 612 public function test_create_item_missing_arguments() { 607 wp_set_current_user( $this->administrator );613 wp_set_current_user( self::$administrator ); 608 614 $request = new WP_REST_Request( 'POST', '/wp/v2/categories' ); 609 615 $response = $this->server->dispatch( $request ); … … 612 618 613 619 public function test_create_item_with_parent() { 614 wp_set_current_user( $this->administrator );620 wp_set_current_user( self::$administrator ); 615 621 $parent = wp_insert_term( 'test-category', 'category' ); 616 622 $request = new WP_REST_Request( 'POST', '/wp/v2/categories' ); … … 624 630 625 631 public function test_create_item_invalid_parent() { 626 wp_set_current_user( $this->administrator );632 wp_set_current_user( self::$administrator ); 627 633 $term = get_term_by( 'id', $this->factory->category->create(), 'category' ); 628 634 … … 635 641 636 642 public function test_update_item() { 637 wp_set_current_user( $this->administrator );643 wp_set_current_user( self::$administrator ); 638 644 $orig_args = array( 639 645 'name' => 'Original Name', … … 655 661 656 662 public function test_update_item_invalid_taxonomy() { 657 wp_set_current_user( $this->administrator );663 wp_set_current_user( self::$administrator ); 658 664 $request = new WP_REST_Request( 'POST', '/wp/v2/invalid-taxonomy/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); 659 665 $request->set_param( 'name', 'Invalid Taxonomy' ); … … 663 669 664 670 public function test_update_item_invalid_term() { 665 wp_set_current_user( $this->administrator );671 wp_set_current_user( self::$administrator ); 666 672 $request = new WP_REST_Request( 'POST', '/wp/v2/categories/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); 667 673 $request->set_param( 'name', 'Invalid Term' ); … … 671 677 672 678 public function test_update_item_incorrect_permissions() { 673 wp_set_current_user( $this->subscriber );679 wp_set_current_user( self::$subscriber ); 674 680 $term = get_term_by( 'id', $this->factory->category->create(), 'category' ); 675 681 $request = new WP_REST_Request( 'POST', '/wp/v2/categories/' . $term->term_id ); … … 680 686 681 687 public function test_update_item_parent() { 682 wp_set_current_user( $this->administrator );688 wp_set_current_user( self::$administrator ); 683 689 $parent = get_term_by( 'id', $this->factory->category->create(), 'category' ); 684 690 $term = get_term_by( 'id', $this->factory->category->create(), 'category' ); … … 694 700 695 701 public function test_update_item_invalid_parent() { 696 wp_set_current_user( $this->administrator );702 wp_set_current_user( self::$administrator ); 697 703 $term = get_term_by( 'id', $this->factory->category->create(), 'category' ); 698 704 … … 704 710 705 711 public function test_delete_item() { 706 wp_set_current_user( $this->administrator );712 wp_set_current_user( self::$administrator ); 707 713 $term = get_term_by( 'id', $this->factory->category->create( array( 'name' => 'Deleted Category' ) ), 'category' ); 708 714 $request = new WP_REST_Request( 'DELETE', '/wp/v2/categories/' . $term->term_id ); … … 715 721 716 722 public function test_delete_item_force_false() { 717 wp_set_current_user( $this->administrator );723 wp_set_current_user( self::$administrator ); 718 724 $term = get_term_by( 'id', $this->factory->category->create( array( 'name' => 'Deleted Category' ) ), 'category' ); 719 725 $request = new WP_REST_Request( 'DELETE', '/wp/v2/categories/' . $term->term_id ); … … 724 730 725 731 public function test_delete_item_invalid_taxonomy() { 726 wp_set_current_user( $this->administrator );732 wp_set_current_user( self::$administrator ); 727 733 $request = new WP_REST_Request( 'DELETE', '/wp/v2/invalid-taxonomy/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); 728 734 $response = $this->server->dispatch( $request ); … … 731 737 732 738 public function test_delete_item_invalid_term() { 733 wp_set_current_user( $this->administrator );739 wp_set_current_user( self::$administrator ); 734 740 $request = new WP_REST_Request( 'DELETE', '/wp/v2/categories/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); 735 741 $response = $this->server->dispatch( $request ); … … 738 744 739 745 public function test_delete_item_incorrect_permissions() { 740 wp_set_current_user( $this->subscriber );746 wp_set_current_user( self::$subscriber ); 741 747 $term = get_term_by( 'id', $this->factory->category->create(), 'category' ); 742 748 $request = new WP_REST_Request( 'DELETE', '/wp/v2/categories/' . $term->term_id );
Note: See TracChangeset
for help on using the changeset viewer.