From: Andrew Dolgov Date: Wed, 26 Apr 2017 21:24:17 +0000 (+0300) Subject: add some basic API unit tests X-Git-Tag: 17.12~223 X-Git-Url: https://git.wh0rd.org/?p=tt-rss.git;a=commitdiff_plain;h=891df346377be014bbad14c229421d92cfd332ea add some basic API unit tests --- diff --git a/classes/api.php b/classes/api.php index 8ffe68cc..3737cf07 100644 --- a/classes/api.php +++ b/classes/api.php @@ -887,4 +887,4 @@ class API extends Handler { } -} \ No newline at end of file +} diff --git a/classes/db/prefs.php b/classes/db/prefs.php index a2662949..26562298 100644 --- a/classes/db/prefs.php +++ b/classes/db/prefs.php @@ -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 index 00000000..7a620d86 --- /dev/null +++ b/tests/ApiTest.php @@ -0,0 +1,70 @@ +$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']); + + } +}