add api test for labels, api: fix setArticleLabel assign not handled correctly

This commit is contained in:
Andrew Dolgov 2017-04-27 09:04:23 +03:00
parent 7c437c476c
commit 3517d363d3
2 changed files with 33 additions and 7 deletions

View File

@ -479,7 +479,7 @@ class API extends Handler {
$article_ids = array_filter(explode(",", $this->dbh->escape_string($_REQUEST["article_ids"])), is_numeric); $article_ids = array_filter(explode(",", $this->dbh->escape_string($_REQUEST["article_ids"])), is_numeric);
$label_id = (int) $this->dbh->escape_string($_REQUEST['label_id']); $label_id = (int) $this->dbh->escape_string($_REQUEST['label_id']);
$assign = (bool) $this->dbh->escape_string($_REQUEST['assign']) == "true"; $assign = (bool) ($this->dbh->escape_string($_REQUEST['assign']) == "true");
$label = $this->dbh->escape_string(label_find_caption( $label = $this->dbh->escape_string(label_find_caption(
feed_to_label_id($label_id), $_SESSION["uid"])); feed_to_label_id($label_id), $_SESSION["uid"]));

View File

@ -78,13 +78,16 @@ final class ApiTest extends TestCase {
$this->assertInternalType('array', $ret['content']); $this->assertInternalType('array', $ret['content']);
$this->assertEquals(2, sizeof($ret['content'])); $this->assertGreaterThanOrEqual(2, sizeof($ret['content']));
foreach ($ret['content'] as $cat) { foreach ($ret['content'] as $cat) {
$this->assertNotEmpty($cat['title']); $this->assertNotEmpty($cat['title']);
$this->assertNotNull($cat['id']); $this->assertNotNull($cat['id']);
$this->assertGreaterThanOrEqual(0, $cat['unread']); $this->assertGreaterThanOrEqual(0, $cat['unread']);
$this->assertContains($cat['title'],
['Special', 'Labels', 'Uncategorized']);
} }
} }
@ -121,15 +124,14 @@ final class ApiTest extends TestCase {
$ret = $this->apiCall(['feed_id' => -4], "getHeadlines"); $ret = $this->apiCall(['feed_id' => -4], "getHeadlines");
$this->assertInternalType('array', $ret['content'][0]); $this->assertInternalType('array', $ret['content'][0]);
$id = $ret['content'][0]['id']; $article_id = $ret['content'][0]['id'];
$title = $ret['content'][0]['title']; $title = $ret['content'][0]['title'];
$ret = $this->apiCall(['article_id' => $id], "getArticle"); $ret = $this->apiCall(['article_id' => $article_id], "getArticle");
$this->assertInternalType('array', $ret['content']); $this->assertInternalType('array', $ret['content']);
$this->assertNotEmpty($ret['content'][0]['content']); $this->assertNotEmpty($ret['content'][0]['content']);
$this->assertEquals($title, $ret['content'][0]['title']); $this->assertEquals($title, $ret['content'][0]['title']);
} }
public function testCounters() { public function testCounters() {
@ -207,6 +209,8 @@ final class ApiTest extends TestCase {
public function testLabels() { public function testLabels() {
// create label
label_create('Test', '', '', 1); label_create('Test', '', '', 1);
$this->testLogin(); $this->testLogin();
@ -214,11 +218,33 @@ final class ApiTest extends TestCase {
$this->assertInternalType('array', $ret['content']); $this->assertInternalType('array', $ret['content']);
$this->assertEquals('Test', $ret['content'][0]['caption']); $this->assertEquals('Test', $ret['content'][0]['caption']);
$label_id = feed_to_label_id($ret['content'][0]['id']); $label_feed_id = $ret['content'][0]['id'];
$label_id = feed_to_label_id($label_feed_id);
$this->assertLessThan(0, $label_feed_id);
$this->assertGreaterThan(0, $label_id); $this->assertGreaterThan(0, $label_id);
// TODO: assign label to article // assign/remove label to article
$ret = $this->apiCall(['feed_id' => -4, 'view_mode' => 'adaptive'], "getHeadlines");
$this->assertInternalType('array', $ret['content'][0]);
$article_id = $ret['content'][0]['id'];
$ret = $this->apiCall(['article_ids' => $article_id,
'label_id' => $label_feed_id, "assign" => "true"],
"setArticleLabel");
$ret = $this->apiCall(['article_id' => $article_id], "getArticle");
$this->assertContains($label_feed_id, $ret['content'][0]['labels'][0]);
$ret = $this->apiCall(['article_ids' => $article_id,
'label_id' => $label_feed_id, "assign" => "false"],
"setArticleLabel");
$ret = $this->apiCall(['article_id' => $article_id], "getArticle");
$this->assertEmpty($ret['content'][0]['labels']);
// clean up and check
label_remove($label_id, 1); label_remove($label_id, 1);