]> git.wh0rd.org - tt-rss.git/commitdiff
add some basic API unit tests
authorAndrew Dolgov <noreply@fakecake.org>
Wed, 26 Apr 2017 21:24:17 +0000 (00:24 +0300)
committerAndrew Dolgov <noreply@fakecake.org>
Wed, 26 Apr 2017 21:24:17 +0000 (00:24 +0300)
classes/api.php
classes/db/prefs.php
tests/ApiTest.php [new file with mode: 0644]

index 8ffe68cc0d1fdfd7d9b48742312941b39b1dc019..3737cf07efa8ef6f6bb96830c38f2a18e35a3116 100644 (file)
@@ -887,4 +887,4 @@ class API extends Handler {
        }
 
 
-}
\ No newline at end of file
+}
index a2662949053d14e595d1f440e88fd20040703359..26562298d5a161d8df13cbf8627f3d3ac46f8935 100644 (file)
@@ -174,7 +174,7 @@ class Db_Prefs {
                        db_query("UPDATE ttrss_user_prefs SET
                                value = '$value' WHERE pref_name = '$pref_name'
                                        $profile_qpart
-                                       AND owner_uid = " . $_SESSION["uid"]);
+                                       AND owner_uid = " . $user_id);
 
                        if ($user_id == $_SESSION["uid"]) {
                                $this->cache[$pref_name]["type"] = $type_name;
@@ -183,4 +183,4 @@ class Db_Prefs {
                }
        }
 
-}
\ No newline at end of file
+}
diff --git a/tests/ApiTest.php b/tests/ApiTest.php
new file mode 100644 (file)
index 0000000..7a620d8
--- /dev/null
@@ -0,0 +1,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']);
+
+       }
+}