diff options
author | uckelman <uckelman@nomic.net> | 2010-04-13 20:26:06 +0000 |
---|---|---|
committer | uckelman <uckelman@nomic.net> | 2010-04-13 20:26:06 +0000 |
commit | 1118926f9e87bfe9ec4f78cb560877fc8081cf28 (patch) | |
tree | c99f86a40ed67f35d8d26768bc3275a32f45e058 | |
parent | efb659524b05b011359c87c2558eb5eaafbdb7f4 (diff) |
Added full registerMessage().
git-svn-id: https://vassalengine.svn.sourceforge.net/svnroot/vassalengine/site-src/trunk@6700 67b53d14-2c14-4ace-a08f-0dab2b34000c
-rw-r--r-- | src/Bridge.php | 16 | ||||
-rw-r--r-- | test/BridgeTest.php | 41 |
2 files changed, 54 insertions, 3 deletions
diff --git a/src/Bridge.php b/src/Bridge.php index 54f9880..9d59564 100644 --- a/src/Bridge.php +++ b/src/Bridge.php @@ -84,6 +84,22 @@ class Bridge { return $count == 1; } + public function registerMessage($postId, $messageId, + $inReplyTo, $references) { + throw_if_null($postId); + throw_if_null($messageId); + + $sql = 'INSERT IGNORE INTO posts ' . + '(post_id, message_id, in_reply_to, refs) ' . + 'VALUES (' . $postId . ', ' + . $this->db->quote($messageId) . ', ' + . $this->quote($inReplyTo) . ', ' + . $this->quote($references) . ')'; + + $count = $this->db->exec($sql); + return $count == 1; + } + public function unregisterMessage($messageId) { throw_if_null($messageId); diff --git a/test/BridgeTest.php b/test/BridgeTest.php index c0c7da1..28ef8d5 100644 --- a/test/BridgeTest.php +++ b/test/BridgeTest.php @@ -96,9 +96,9 @@ class BridgeTest extends PHPUnit_Framework_TestCase { } /** - * @dataProvider providerRegisterMessage + * @dataProvider providerRegisterMessage3 */ - public function testRegisterMessage($messageId, $inReplyTo, $refs, + public function testRegisterMessage3($messageId, $inReplyTo, $refs, $expected, $ex) { if ($ex) $this->setExpectedException($ex); $bridge = new Bridge($this->db); @@ -108,7 +108,7 @@ class BridgeTest extends PHPUnit_Framework_TestCase { ); } - public function providerRegisterMessage() { + public function providerRegisterMessage3() { return array( array(null, null, null, null, 'Exception'), array( @@ -129,6 +129,41 @@ class BridgeTest extends PHPUnit_Framework_TestCase { } /** + * @dataProvider providerRegisterMessage4 + */ + public function testRegisterMessage4($postId, $messageId, $inReplyTo, $refs, + $expected, $ex) { + if ($ex) $this->setExpectedException($ex); + $bridge = new Bridge($this->db); + $this->assertEquals( + $expected, + $bridge->registerMessage($postId, $messageId, $inReplyTo, $refs) + ); + } + + public function providerRegisterMessage4() { + return array( + array(null, null, null, null, 'Exception'), + array( + 2, + '<20100302094228.33F0310091@charybdis.ellipsis.cx>', + null, + null, + false, + null + ), + array( + 2, + '<10100302094228.33F0310091@charybdis.ellipsis.cx>', + null, + null, + true, + null + ) + ); + } + + /** * @dataProvider providerUnregisterMessage */ public function testUnregisterMessage($messageId, $ex) { |