]> git.wh0rd.org - tt-rss.git/blob - tests/ApiTest.php
Merge branch 'master' of git.fakecake.org:tt-rss
[tt-rss.git] / tests / ApiTest.php
1 <?php
2 use PHPUnit\Framework\TestCase;
3
4 set_include_path(dirname(__DIR__) ."/include" . PATH_SEPARATOR .
5 dirname(__DIR__) . PATH_SEPARATOR .
6 get_include_path());
7
8 require_once "autoload.php";
9
10 final class ApiTest extends TestCase {
11
12 public function __construct() {
13 init_plugins();
14 initialize_user_prefs(1);
15 set_pref('ENABLE_API_ACCESS', true, 1);
16
17 parent::__construct();
18 }
19
20 public function apiCall($args, $method) {
21 $_REQUEST = $args;
22
23 $api = new API($args);
24 ob_start();
25 $api->$method();
26 $rv = json_decode(ob_get_contents(), true);
27 ob_end_clean();
28
29 return $rv;
30 }
31
32 public function testBasicAuth() {
33 $this->assertEquals(true,
34 authenticate_user("admin", "password"));
35 }
36
37 public function testVersion() {
38
39 $ret = $this->apiCall([], "getVersion");
40
41 $this->assertStringStartsWith(
42 VERSION_STATIC,
43 $ret['content']['version']);
44 }
45
46 public function testLogin() {
47
48 $ret = $this->apiCall(["op" => "login",
49 "user" => "admin",
50 "password" => "password"], "login");
51
52 $this->assertNotEmpty($ret['content']['session_id']);
53 }
54
55 public function testGetUnread() {
56 $this->testLogin();
57 $ret = $this->apiCall([],"getUnread");
58
59 $this->assertNotEmpty($ret['content']['unread']);
60 }
61
62 public function testGetFeeds() {
63 $this->testLogin();
64 $ret = $this->apiCall([], "getFeeds");
65
66 $this->assertEquals("http://tt-rss.org/forum/rss.php",
67 $ret['content'][0]['feed_url']);
68
69 }
70 }