Code Duplication    Length = 28-30 lines in 2 locations

tests/phpunit/tests/rest-api/rest-comments-controller.php 1 location

@@ 2911-2940 (lines=30) @@
2908
        $wp_rest_additional_fields = array();
2909
    }
2910
2911
    public function test_additional_field_update_errors() 
2912
    {
2913
        $schema = array(
2914
         'type'        => 'integer',
2915
         'description' => 'Some integer of mine',
2916
         'enum'        => array( 1, 2, 3, 4 ),
2917
         'context'     => array( 'view', 'edit' ),
2918
        );
2919
2920
        register_rest_field(
2921
            'comment', 'my_custom_int', array(
2922
            'schema'          => $schema,
2923
            'get_callback'    => array( $this, 'additional_field_get_callback' ),
2924
            'update_callback' => array( $this, 'additional_field_update_callback' ),
2925
            ) 
2926
        );
2927
2928
        wp_set_current_user(self::$admin_id);
2929
2930
        // Check for error on update.
2931
        $request = new WP_REST_Request('POST', sprintf('/wp/v2/comments/%d', self::$approved_id));
2932
        $request->set_body_params(
2933
            array(
2934
            'my_custom_int' => 'returnError',
2935
            'content' => 'abc',
2936
            )
2937
        );
2938
2939
        $response = $this->server->dispatch($request);
2940
2941
        $this->assertErrorResponse('rest_invalid_param', $response, 400);
2942
2943
        global $wp_rest_additional_fields;

tests/phpunit/tests/rest-api/rest-posts-controller.php 1 location

@@ 2978-3005 (lines=28) @@
2975
        $wp_rest_additional_fields = array();
2976
    }
2977
2978
    public function test_additional_field_update_errors() 
2979
    {
2980
        $schema = array(
2981
         'type'        => 'integer',
2982
         'description' => 'Some integer of mine',
2983
         'enum'        => array( 1, 2, 3, 4 ),
2984
         'context'     => array( 'view', 'edit' ),
2985
        );
2986
2987
        register_rest_field(
2988
            'post', 'my_custom_int', array(
2989
            'schema'          => $schema,
2990
            'get_callback'    => array( $this, 'additional_field_get_callback' ),
2991
            'update_callback' => array( $this, 'additional_field_update_callback' ),
2992
            ) 
2993
        );
2994
2995
        wp_set_current_user(self::$editor_id);
2996
        // Check for error on update.
2997
        $request = new WP_REST_Request('POST', sprintf('/wp/v2/posts/%d', self::$post_id));
2998
        $request->set_body_params(
2999
            array(
3000
            'my_custom_int' => 'returnError',
3001
            ) 
3002
        );
3003
3004
        $response = $this->server->dispatch($request);
3005
3006
        $this->assertErrorResponse('rest_invalid_param', $response, 400);
3007
3008
        global $wp_rest_additional_fields;