summaryrefslogtreecommitdiff
path: root/tests/ApiTest.php
blob: 7a620d86ea96e79cd898e682a5c92f79fa57feb8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
use PHPUnit\Framework\TestCase;

set_include_path(dirname(__DIR__) ."/include" . PATH_SEPARATOR .
	dirname(__DIR__) . PATH_SEPARATOR .
	get_include_path());

require_once "autoload.php";

final class ApiTest extends TestCase {

	public function __construct() {
		init_plugins();
		initialize_user_prefs(1);
		set_pref('ENABLE_API_ACCESS', true, 1);

		parent::__construct();
	}

	public function apiCall($args, $method) {
		$_REQUEST = $args;

		$api = new API($args);
		ob_start();
		$api->$method();
		$rv = json_decode(ob_get_contents(), true);
		ob_end_clean();

		return $rv;
	}

	public function testBasicAuth() {
		$this->assertEquals(true,
			authenticate_user("admin", "password"));
	}

	public function testVersion() {

		$ret = $this->apiCall([], "getVersion");

		$this->assertStringStartsWith(
			VERSION_STATIC,
			$ret['content']['version']);
	}

	public function testLogin() {

		$ret = $this->apiCall(["op" => "login",
			"user" => "admin",
			"password" => "password"], "login");

		$this->assertNotEmpty($ret['content']['session_id']);
	}

	public function testGetUnread() {
		$this->testLogin();
		$ret = $this->apiCall([],"getUnread");

		$this->assertNotEmpty($ret['content']['unread']);
	}

	public function testGetFeeds() {
		$this->testLogin();
		$ret = $this->apiCall([], "getFeeds");

		$this->assertEquals("http://tt-rss.org/forum/rss.php",
			$ret['content'][0]['feed_url']);

	}
}