diff options
-rw-r--r-- | src/PhpBB3.php | 14 | ||||
-rw-r--r-- | test/PhpBB3Test.php | 17 |
2 files changed, 30 insertions, 1 deletions
diff --git a/src/PhpBB3.php b/src/PhpBB3.php index ca75c24..3c6a508 100644 --- a/src/PhpBB3.php +++ b/src/PhpBB3.php @@ -44,13 +44,25 @@ class PhpBB3 { return $names[$id]; } + public function getTopicId($postId) { + throw_if_null($post_id); + + global $db; + + $sql = 'SELECT topic_id FROM ' . POSTS_TABLE . ' ' . + 'WHERE post_id = ' . $post_id; + + $row = $this->get_exactly_one_row($sql); + return $row ? $row['topic_id'] : false; + } + public function getTopicAndForumIds($post_id) { throw_if_null($post_id); global $db; $sql = 'SELECT topic_id, forum_id FROM ' . POSTS_TABLE . ' ' . - 'WHERE post_id = "' . $db->sql_escape($post_id) . '"'; + 'WHERE post_id = ' . $post_id; $row = $this->get_exactly_one_row($sql); return $row; diff --git a/test/PhpBB3Test.php b/test/PhpBB3Test.php index ee9246a..d43b386 100644 --- a/test/PhpBB3Test.php +++ b/test/PhpBB3Test.php @@ -67,6 +67,23 @@ EOF; } /** + * @dataProvider providerGetTopicId + */ + public function testGetTopicId($post_id, $expected, $ex) { + if ($ex) $this->setExpectedException($ex); + $run = 'getTopicId(' . $post_id . ')'; + $this->assertEquals($expected, $this->exec_kludge($run)); + } + + public function providerGetTopicId() { + return array( + array(null, null, 'Exception'), + array('bogus', false, null), + array(2, 2, null) + ); + } + + /** * @dataProvider providerGetTopicAndForumIds */ public function testGetTopicAndForumIds($post_id, $expected, $ex) { |