Code Duplication    Length = 28-29 lines in 2 locations

tests/test-rest-tags-controller.php 1 location

@@ 637-665 (lines=29) @@
634
		$wp_rest_additional_fields = array();
635
	}
636
637
	public function test_additional_field_update_errors() {
638
		$schema = array(
639
			'type'        => 'integer',
640
			'description' => 'Some integer of mine',
641
			'enum'        => array( 1, 2, 3, 4 ),
642
			'context'     => array( 'view', 'edit' ),
643
		);
644
645
		register_rest_field( 'tag', 'my_custom_int', array(
646
			'schema'          => $schema,
647
			'get_callback'    => array( $this, 'additional_field_get_callback' ),
648
			'update_callback' => array( $this, 'additional_field_update_callback' ),
649
		) );
650
651
		wp_set_current_user( $this->administrator );
652
		$tag_id = $this->factory->tag->create();
653
		// Check for error on update.
654
		$request = new WP_REST_Request( 'POST', sprintf( '/wp/v2/tags/%d', $tag_id ) );
655
		$request->set_body_params( array(
656
			'my_custom_int' => 'returnError',
657
		) );
658
659
		$response = $this->server->dispatch( $request );
660
661
		$this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
662
663
		global $wp_rest_additional_fields;
664
		$wp_rest_additional_fields = array();
665
	}
666
667
	public function additional_field_get_callback( $object, $request ) {
668
		return 123;

tests/test-rest-posts-controller.php 1 location

@@ 1855-1882 (lines=28) @@
1852
		$wp_rest_additional_fields = array();
1853
	}
1854
1855
	public function test_additional_field_update_errors() {
1856
		$schema = array(
1857
			'type'        => 'integer',
1858
			'description' => 'Some integer of mine',
1859
			'enum'        => array( 1, 2, 3, 4 ),
1860
			'context'     => array( 'view', 'edit' ),
1861
		);
1862
1863
		register_rest_field( 'post', 'my_custom_int', array(
1864
			'schema'          => $schema,
1865
			'get_callback'    => array( $this, 'additional_field_get_callback' ),
1866
			'update_callback' => array( $this, 'additional_field_update_callback' ),
1867
		) );
1868
1869
		wp_set_current_user( $this->editor_id );
1870
		// Check for error on update.
1871
		$request = new WP_REST_Request( 'POST', sprintf( '/wp/v2/posts/%d', $this->post_id ) );
1872
		$request->set_body_params( array(
1873
			'my_custom_int' => 'returnError',
1874
		) );
1875
1876
		$response = $this->server->dispatch( $request );
1877
1878
		$this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
1879
1880
		global $wp_rest_additional_fields;
1881
		$wp_rest_additional_fields = array();
1882
	}
1883
1884
	public function additional_field_get_callback( $object ) {
1885
		return get_post_meta( $object['id'], 'my_custom_int', true );