| 3643 | public function test_publish_action_ldo_registered() { |
| 3644 | |
| 3645 | $response = rest_get_server()->dispatch( new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' ) ); |
| 3646 | $data = $response->get_data(); |
| 3647 | $schema = $data['schema']; |
| 3648 | |
| 3649 | $this->assertArrayHasKey( 'links', $schema ); |
| 3650 | $publish = wp_list_filter( $schema['links'], array( 'rel' => 'https://api.w.org/action-publish' ) ); |
| 3651 | |
| 3652 | $this->assertCount( 1, $publish, 'LDO found on schema.' ); |
| 3653 | } |
| 3654 | |
| 3655 | public function test_sticky_action_ldo_registered_for_posts() { |
| 3656 | |
| 3657 | $response = rest_get_server()->dispatch( new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' ) ); |
| 3658 | $data = $response->get_data(); |
| 3659 | $schema = $data['schema']; |
| 3660 | |
| 3661 | $this->assertArrayHasKey( 'links', $schema ); |
| 3662 | $publish = wp_list_filter( $schema['links'], array( 'rel' => 'https://api.w.org/action-sticky' ) ); |
| 3663 | |
| 3664 | $this->assertCount( 1, $publish, 'LDO found on schema.' ); |
| 3665 | } |
| 3666 | |
| 3667 | public function test_sticky_action_ldo_not_registered_for_non_posts() { |
| 3668 | |
| 3669 | $response = rest_get_server()->dispatch( new WP_REST_Request( 'OPTIONS', '/wp/v2/pages' ) ); |
| 3670 | $data = $response->get_data(); |
| 3671 | $schema = $data['schema']; |
| 3672 | |
| 3673 | $this->assertArrayHasKey( 'links', $schema ); |
| 3674 | $publish = wp_list_filter( $schema['links'], array( 'rel' => 'https://api.w.org/action-sticky' ) ); |
| 3675 | |
| 3676 | $this->assertCount( 0, $publish, 'LDO found on schema.' ); |
| 3677 | } |
| 3678 | |
| 3679 | public function test_author_action_ldo_registered_for_post_types_with_author_support() { |
| 3680 | |
| 3681 | $response = rest_get_server()->dispatch( new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' ) ); |
| 3682 | $data = $response->get_data(); |
| 3683 | $schema = $data['schema']; |
| 3684 | |
| 3685 | $this->assertArrayHasKey( 'links', $schema ); |
| 3686 | $publish = wp_list_filter( $schema['links'], array( 'rel' => 'https://api.w.org/action-assign-author' ) ); |
| 3687 | |
| 3688 | $this->assertCount( 1, $publish, 'LDO found on schema.' ); |
| 3689 | } |
| 3690 | |
| 3691 | public function test_author_action_ldo_not_registered_for_post_types_without_author_support() { |
| 3692 | |
| 3693 | remove_post_type_support( 'post', 'author' ); |
| 3694 | |
| 3695 | $response = rest_get_server()->dispatch( new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' ) ); |
| 3696 | $data = $response->get_data(); |
| 3697 | $schema = $data['schema']; |
| 3698 | |
| 3699 | $this->assertArrayHasKey( 'links', $schema ); |
| 3700 | $publish = wp_list_filter( $schema['links'], array( 'rel' => 'https://api.w.org/action-assign-author' ) ); |
| 3701 | |
| 3702 | $this->assertCount( 0, $publish, 'LDO found on schema.' ); |
| 3703 | } |
| 3704 | |
| 3705 | public function test_term_action_ldos_registered() { |
| 3706 | |
| 3707 | $response = rest_get_server()->dispatch( new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' ) ); |
| 3708 | $data = $response->get_data(); |
| 3709 | $schema = $data['schema']; |
| 3710 | |
| 3711 | $this->assertArrayHasKey( 'links', $schema ); |
| 3712 | $rels = array_flip( wp_list_pluck( $schema['links'], 'rel' ) ); |
| 3713 | |
| 3714 | $this->assertArrayHasKey( 'https://api.w.org/action-assign-categories', $rels ); |
| 3715 | $this->assertArrayHasKey( 'https://api.w.org/action-create-categories', $rels ); |
| 3716 | $this->assertArrayHasKey( 'https://api.w.org/action-assign-tags', $rels ); |
| 3717 | $this->assertArrayHasKey( 'https://api.w.org/action-create-tags', $rels ); |
| 3718 | |
| 3719 | $this->assertArrayNotHasKey( 'https://api.w.org/action-assign-post_format', $rels ); |
| 3720 | $this->assertArrayNotHasKey( 'https://api.w.org/action-create-post_format', $rels ); |
| 3721 | $this->assertArrayNotHasKey( 'https://api.w.org/action-assign-nav_menu', $rels ); |
| 3722 | $this->assertArrayNotHasKey( 'https://api.w.org/action-create-nav_menu', $rels ); |
| 3723 | } |
| 3724 | |
| 3725 | public function test_action_links_only_available_in_edit_context() { |
| 3726 | |
| 3727 | wp_set_current_user( self::$author_id ); |
| 3728 | |
| 3729 | $post = self::factory()->post->create( array( 'post_author' => self::$author_id ) ); |
| 3730 | $this->assertGreaterThan( 0, $post ); |
| 3731 | |
| 3732 | $request = new WP_REST_Request( 'GET', "/wp/v2/posts/{$post}" ); |
| 3733 | $request->set_query_params( array( 'context' => 'view' ) ); |
| 3734 | |
| 3735 | $response = rest_get_server()->dispatch( $request ); |
| 3736 | $links = $response->get_links(); |
| 3737 | |
| 3738 | $this->assertArrayNotHasKey( 'https://api.w.org/action-publish', $links ); |
| 3739 | } |
| 3740 | |
| 3741 | public function test_publish_action_link_exists_for_author() { |
| 3742 | |
| 3743 | wp_set_current_user( self::$author_id ); |
| 3744 | |
| 3745 | $post = self::factory()->post->create( array( 'post_author' => self::$author_id ) ); |
| 3746 | $this->assertGreaterThan( 0, $post ); |
| 3747 | |
| 3748 | $request = new WP_REST_Request( 'GET', "/wp/v2/posts/{$post}" ); |
| 3749 | $request->set_query_params( array( 'context' => 'edit' ) ); |
| 3750 | |
| 3751 | $response = rest_get_server()->dispatch( $request ); |
| 3752 | $links = $response->get_links(); |
| 3753 | |
| 3754 | $this->assertArrayHasKey( 'https://api.w.org/action-publish', $links ); |
| 3755 | } |
| 3756 | |
| 3757 | public function test_publish_action_link_does_not_exist_for_contributor() { |
| 3758 | |
| 3759 | wp_set_current_user( self::$contributor_id ); |
| 3760 | |
| 3761 | $post = self::factory()->post->create( array( 'post_author' => self::$contributor_id ) ); |
| 3762 | $this->assertGreaterThan( 0, $post ); |
| 3763 | |
| 3764 | $request = new WP_REST_Request( 'GET', "/wp/v2/posts/{$post}"); |
| 3765 | $request->set_query_params( array( 'context' => 'edit' ) ); |
| 3766 | |
| 3767 | $response = rest_get_server()->dispatch( $request ); |
| 3768 | $links = $response->get_links(); |
| 3769 | |
| 3770 | $this->assertArrayNotHasKey( 'https://api.w.org/action-publish', $links ); |
| 3771 | } |
| 3772 | |
| 3773 | public function test_sticky_action_exists_for_editor() { |
| 3774 | |
| 3775 | wp_set_current_user( self::$editor_id ); |
| 3776 | |
| 3777 | $post = self::factory()->post->create( array( 'post_author' => self::$author_id ) ); |
| 3778 | $this->assertGreaterThan( 0, $post ); |
| 3779 | |
| 3780 | $request = new WP_REST_Request( 'GET', "/wp/v2/posts/{$post}" ); |
| 3781 | $request->set_query_params( array( 'context' => 'edit' ) ); |
| 3782 | |
| 3783 | $response = rest_get_server()->dispatch( $request ); |
| 3784 | $links = $response->get_links(); |
| 3785 | |
| 3786 | $this->assertArrayHasKey( 'https://api.w.org/action-sticky', $links ); |
| 3787 | } |
| 3788 | |
| 3789 | public function test_sticky_action_does_not_exist_for_author() { |
| 3790 | |
| 3791 | wp_set_current_user( self::$author_id ); |
| 3792 | |
| 3793 | $post = self::factory()->post->create( array( 'post_author' => self::$author_id ) ); |
| 3794 | $this->assertGreaterThan( 0, $post ); |
| 3795 | |
| 3796 | $request = new WP_REST_Request( 'GET', "/wp/v2/posts/{$post}" ); |
| 3797 | $request->set_query_params( array( 'context' => 'edit' ) ); |
| 3798 | |
| 3799 | $response = rest_get_server()->dispatch( $request ); |
| 3800 | $links = $response->get_links(); |
| 3801 | |
| 3802 | $this->assertArrayNotHasKey( 'https://api.w.org/action-sticky', $links ); |
| 3803 | } |
| 3804 | |
| 3805 | public function test_sticky_action_does_not_exist_for_non_post_posts() { |
| 3806 | |
| 3807 | wp_set_current_user( self::$editor_id ); |
| 3808 | |
| 3809 | $post = self::factory()->post->create( array( 'post_author' => self::$author_id, 'post_type' => 'page' ) ); |
| 3810 | $this->assertGreaterThan( 0, $post ); |
| 3811 | |
| 3812 | $request = new WP_REST_Request( 'GET', "/wp/v2/posts/{$post}" ); |
| 3813 | $request->set_query_params( array( 'context' => 'edit' ) ); |
| 3814 | |
| 3815 | $response = rest_get_server()->dispatch( $request ); |
| 3816 | $links = $response->get_links(); |
| 3817 | |
| 3818 | $this->assertArrayNotHasKey( 'https://api.w.org/action-sticky', $links ); |
| 3819 | } |
| 3820 | |
| 3821 | |
| 3822 | public function test_assign_author_action_exists_for_editor() { |
| 3823 | |
| 3824 | wp_set_current_user( self::$editor_id ); |
| 3825 | |
| 3826 | $post = self::factory()->post->create( array( 'post_author' => self::$author_id ) ); |
| 3827 | $this->assertGreaterThan( 0, $post ); |
| 3828 | |
| 3829 | $request = new WP_REST_Request( 'GET', "/wp/v2/posts/{$post}" ); |
| 3830 | $request->set_query_params( array( 'context' => 'edit' ) ); |
| 3831 | |
| 3832 | $response = rest_get_server()->dispatch( $request ); |
| 3833 | $links = $response->get_links(); |
| 3834 | |
| 3835 | $this->assertArrayHasKey( 'https://api.w.org/action-assign-author', $links ); |
| 3836 | } |
| 3837 | |
| 3838 | public function test_assign_author_action_does_not_exist_for_author() { |
| 3839 | |
| 3840 | wp_set_current_user( self::$author_id ); |
| 3841 | |
| 3842 | $post = self::factory()->post->create( array( 'post_author' => self::$author_id ) ); |
| 3843 | $this->assertGreaterThan( 0, $post ); |
| 3844 | |
| 3845 | $request = new WP_REST_Request( 'GET', "/wp/v2/posts/{$post}" ); |
| 3846 | $request->set_query_params( array( 'context' => 'edit' ) ); |
| 3847 | |
| 3848 | $response = rest_get_server()->dispatch( $request ); |
| 3849 | $links = $response->get_links(); |
| 3850 | |
| 3851 | $this->assertArrayNotHasKey( 'https://api.w.org/action-assign-author', $links ); |
| 3852 | } |
| 3853 | |
| 3854 | public function test_assign_author_action_does_not_exist_for_post_types_without_author_support() { |
| 3855 | |
| 3856 | remove_post_type_support( 'post', 'author' ); |
| 3857 | |
| 3858 | wp_set_current_user( self::$editor_id ); |
| 3859 | |
| 3860 | $post = self::factory()->post->create(); |
| 3861 | $this->assertGreaterThan( 0, $post ); |
| 3862 | |
| 3863 | $request = new WP_REST_Request( 'GET', "/wp/v2/posts/{$post}" ); |
| 3864 | $request->set_query_params( array( 'context' => 'edit' ) ); |
| 3865 | |
| 3866 | $response = rest_get_server()->dispatch( $request ); |
| 3867 | $links = $response->get_links(); |
| 3868 | |
| 3869 | $this->assertArrayNotHasKey( 'https://api.w.org/action-assign-author', $links ); |
| 3870 | } |
| 3871 | |
| 3872 | public function test_create_term_action_exists_for_editor() { |
| 3873 | |
| 3874 | wp_set_current_user( self::$editor_id ); |
| 3875 | |
| 3876 | $post = self::factory()->post->create( array( 'post_author' => self::$author_id ) ); |
| 3877 | $this->assertGreaterThan( 0, $post ); |
| 3878 | |
| 3879 | $request = new WP_REST_Request( 'GET', "/wp/v2/posts/{$post}" ); |
| 3880 | $request->set_query_params( array( 'context' => 'edit' ) ); |
| 3881 | |
| 3882 | $response = rest_get_server()->dispatch( $request ); |
| 3883 | $links = $response->get_links(); |
| 3884 | |
| 3885 | $this->assertArrayHasKey( 'https://api.w.org/action-create-categories', $links ); |
| 3886 | $this->assertArrayHasKey( 'https://api.w.org/action-create-tags', $links ); |
| 3887 | $this->assertArrayNotHasKey( 'https://api.w.org/action-create-post_format', $links ); |
| 3888 | } |
| 3889 | |
| 3890 | public function test_create_term_action_non_hierarchical_exists_for_author() { |
| 3891 | |
| 3892 | wp_set_current_user( self::$author_id ); |
| 3893 | |
| 3894 | $post = self::factory()->post->create( array( 'post_author' => self::$author_id ) ); |
| 3895 | $this->assertGreaterThan( 0, $post ); |
| 3896 | |
| 3897 | $request = new WP_REST_Request( 'GET', "/wp/v2/posts/{$post}" ); |
| 3898 | $request->set_query_params( array( 'context' => 'edit' ) ); |
| 3899 | |
| 3900 | $response = rest_get_server()->dispatch( $request ); |
| 3901 | $links = $response->get_links(); |
| 3902 | |
| 3903 | $this->assertArrayHasKey( 'https://api.w.org/action-create-tags', $links ); |
| 3904 | } |
| 3905 | |
| 3906 | public function test_create_term_action_hierarchical_does_not_exists_for_author() { |
| 3907 | |
| 3908 | wp_set_current_user( self::$author_id ); |
| 3909 | |
| 3910 | $post = self::factory()->post->create( array( 'post_author' => self::$author_id ) ); |
| 3911 | $this->assertGreaterThan( 0, $post ); |
| 3912 | |
| 3913 | $request = new WP_REST_Request( 'GET', "/wp/v2/posts/{$post}" ); |
| 3914 | $request->set_query_params( array( 'context' => 'edit' ) ); |
| 3915 | |
| 3916 | $response = rest_get_server()->dispatch( $request ); |
| 3917 | $links = $response->get_links(); |
| 3918 | |
| 3919 | $this->assertArrayNotHasKey( 'https://api.w.org/action-create-categories', $links ); |
| 3920 | } |
| 3921 | |
| 3922 | public function test_assign_term_action_exists_for_contributor() { |
| 3923 | |
| 3924 | wp_set_current_user( self::$contributor_id ); |
| 3925 | |
| 3926 | $post = self::factory()->post->create( array( 'post_author' => self::$contributor_id, 'post_status' => 'draft' ) ); |
| 3927 | $this->assertGreaterThan( 0, $post ); |
| 3928 | |
| 3929 | $request = new WP_REST_Request( 'GET', "/wp/v2/posts/{$post}" ); |
| 3930 | $request->set_query_params( array( 'context' => 'edit' ) ); |
| 3931 | |
| 3932 | $response = rest_get_server()->dispatch( $request ); |
| 3933 | $links = $response->get_links(); |
| 3934 | |
| 3935 | $this->assertArrayHasKey( 'https://api.w.org/action-assign-categories', $links ); |
| 3936 | $this->assertArrayHasKey( 'https://api.w.org/action-assign-tags', $links ); |
| 3937 | } |
| 3938 | |