Passed
Push — master ( b44fdc...0d29c4 )
by Benjamin
02:28
created

APITest::test_wp_version_requires_authentication()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
rs 10
c 1
b 0
f 0
1
<?php
2
/**
3
 * Class APITest
4
 *
5
 * @package WPSiteMonitor
6
 * @since 1.0.0
7
 */
8
9
use Tests\Test_Case;
10
use WPSiteMonitor\API;
11
12
/**
13
 * API test case.
14
 */
15
class APITest extends Test_Case {
16
17
	/**
18
	 * @var WP_REST_Server;
19
	 */
20
	protected $server;
21
22
	protected $api;
23
24
	public function setUp() {
25
		parent::setUp();
26
27
		$this->server = rest_get_server();
28
		$this->api = new API();
29
	}
30
31
	/**
32
	 * Assert that REST API namespace for the plugin exists.
33
	 */
34
	public function test_rest_api_plugin_namespace_exists() {
35
		$namespaces = $this->server->get_namespaces();
36
37
		$this->assertContains( self::API_NAMESPACE, $namespaces );
38
	}
39
40
	/**
41
	 * Assert that WordPress version endpoint exists.
42
	 */
43
	public function test_wp_version_endpoint_exists() {
44
		$routes = $this->server->get_routes();
45
46
		$this->assertArrayHasKey( '/' . self::API_NAMESPACE . '/wp-version', $routes );
47
	}
48
49
	/**
50
	 * Assert that 'wp-version' endpoint returns the version number.
51
	 */
52
	public function test_wp_version_is_returned() {
53
		global $wp_version;
54
		$returned_version = $this->api->get_wp_version();
55
56
		$this->assertEquals( $wp_version, $returned_version );
57
	}
58
59
	/**
60
	 * Assert that 'wp-version' endpoint requires authentication.
61
	 */
62
	public function test_wp_version_requires_authentication() {
63
		$this->assertFalse( $this->api->check_permissions() );
64
	}
65
}
66