Code Duplication    Length = 32-33 lines in 2 locations

projects/plugins/jetpack/tests/php/json-api/test-class.json-api-jetpack-sync-endpoints.php 2 locations

@@ 44-75 (lines=32) @@
41
	/**
42
	 * Unit test for the `/sites/%s/sync/health` endpoint with valid input.
43
	 */
44
	public function test_modify_sync_health() {
45
		global $blog_id;
46
47
		$endpoint = new Jetpack_JSON_API_Sync_Modify_Health_Endpoint(
48
			array(
49
				'description'             => 'Update sync health',
50
				'method'                  => 'POST',
51
				'group'                   => '__do_not_document',
52
				'path'                    => '/sites/%s/sync/health',
53
				'stat'                    => 'write-sync-health',
54
				'allow_jetpack_site_auth' => true,
55
				'path_labels'             => array(
56
					'$site' => '(int|string) The site ID, The site domain',
57
				),
58
				'request_format'          => array(
59
					'status' => '(string) Sync Health Status of site',
60
				),
61
				'response_format'         => array(
62
					'response' => '(string) Current Sync Health ',
63
				),
64
				'example_request'         => 'https://public-api.wordpress.com/rest/v1.1/sites/example.wordpress.org/sync/health',
65
			)
66
		);
67
68
		// set input.
69
		$endpoint->api->post_body    = '{ "status": "in_sync" }';
70
		$endpoint->api->content_type = 'application/json';
71
72
		$response = $endpoint->callback( 'sync/health', $blog_id );
73
74
		$this->assertEquals( 'in_sync', $response['success'] );
75
	}
76
77
	/**
78
	 * Unit test for the `/sites/%s/sync/health` endpoint with invalid input.
@@ 80-112 (lines=33) @@
77
	/**
78
	 * Unit test for the `/sites/%s/sync/health` endpoint with invalid input.
79
	 */
80
	public function test_modify_sync_health_error() {
81
		global $blog_id;
82
83
		$endpoint = new Jetpack_JSON_API_Sync_Modify_Health_Endpoint(
84
			array(
85
				'description'             => 'Update sync health',
86
				'method'                  => 'POST',
87
				'group'                   => '__do_not_document',
88
				'path'                    => '/sites/%s/sync/health',
89
				'stat'                    => 'write-sync-health',
90
				'allow_jetpack_site_auth' => true,
91
				'path_labels'             => array(
92
					'$site' => '(int|string) The site ID, The site domain',
93
				),
94
				'request_format'          => array(
95
					'status' => '(string) Sync Health Status of site',
96
				),
97
				'response_format'         => array(
98
					'response' => '(string) Current Sync Health ',
99
				),
100
				'example_request'         => 'https://public-api.wordpress.com/rest/v1.1/sites/example.wordpress.org/sync/health',
101
			)
102
		);
103
104
		// set input.
105
		$endpoint->api->post_body    = '{ "status": "bad_falue" }';
106
		$endpoint->api->content_type = 'application/json';
107
108
		$response = $endpoint->callback( 'sync/health', $blog_id );
109
110
		// Verify WP_Error returned on invalid stati.
111
		$this->assertInstanceOf( 'WP_Error', $response );
112
	}
113
}
114