Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/jsxc.nextcloud.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobia De Koninck <tobia@ledfan.be>2017-07-30 15:20:17 +0300
committerTobia De Koninck <tobia@ledfan.be>2017-07-30 15:22:34 +0300
commitef2703dad6f26b1590384f724ba35e319b0a9104 (patch)
treeab34ad11d2e1db621c0b7794f452b692cbb92cda /tests/integration/db
parentbcad36c33adbade5dd84ba6ef2a38969e36fe53e (diff)
Small fixes + test hooks, rosterpush and rosterrefresh
Diffstat (limited to 'tests/integration/db')
-rw-r--r--tests/integration/db/IqRosterPushTest.php36
-rw-r--r--tests/integration/db/PresenceMapperTest.php63
-rw-r--r--tests/integration/db/StanzaMapperTest.php31
3 files changed, 130 insertions, 0 deletions
diff --git a/tests/integration/db/IqRosterPushTest.php b/tests/integration/db/IqRosterPushTest.php
new file mode 100644
index 0000000..e6e8c0d
--- /dev/null
+++ b/tests/integration/db/IqRosterPushTest.php
@@ -0,0 +1,36 @@
+<?php
+namespace OCA\OJSXC\Db;
+
+use Sabre\Xml\Writer;
+use OCA\OJSXC\Utility\TestCase;
+
+class IqRosterPushTest extends TestCase
+{
+ public function testIqRoster()
+ {
+ $expected = '<body xmlns="http://jabber.org/protocol/httpbind"><iq to="jan@localhost" type="set" id="4"><query xmlns="jabber:iq:roster"><item jid="john@localhost" name="john" subscription="both"></item></query></iq></body>';
+
+ $writer = new Writer();
+ $writer->openMemory();
+ $writer->startElement('body');
+ $writer->writeAttribute('xmlns', 'http://jabber.org/protocol/httpbind');
+
+ $iqRosterPush = new IQRosterPush();
+ $iqRosterPush->setJid('john@localhost');
+ $iqRosterPush->setTo('jan@localhost');
+ $iqRosterPush->setName('john');
+ $iqRosterPush->setSubscription('both');
+
+ $this->assertEquals($iqRosterPush->getJid(), 'john@localhost');
+ $this->assertEquals($iqRosterPush->getTo(), 'jan@localhost');
+ $this->assertEquals($iqRosterPush->getName(), 'john');
+ $this->assertEquals($iqRosterPush->getSubscription(), 'both');
+
+ $writer->write($iqRosterPush); // needed to test the xmlSerialize function
+
+ $writer->endElement();
+ $result = $writer->outputMemory();
+
+ $this->assertEquals($expected, $result);
+ }
+}
diff --git a/tests/integration/db/PresenceMapperTest.php b/tests/integration/db/PresenceMapperTest.php
index 11968c1..23b1624 100644
--- a/tests/integration/db/PresenceMapperTest.php
+++ b/tests/integration/db/PresenceMapperTest.php
@@ -480,4 +480,67 @@ class PresenceMapperTest extends MapperTestUtility
$this->assertArrayDbResultsEqual($expected, $result, ['userid', 'last_active', 'presence']);
}
+
+ public function deletePresenceProvider()
+ {
+ $input1 = new PresenceEntity();
+ $input1->setPresence('online');
+ $input1->setUserid('admin');
+ $input1->setLastActive(1000);
+
+ $input2 = new PresenceEntity();
+ $input2->setPresence('unavailable');
+ $input2->setUserid('foo');
+ $input2->setLastActive(1000);
+
+ $input3 = new PresenceEntity();
+ $input3->setPresence('xa');
+ $input3->setUserid('derp');
+ $input3->setLastActive(600);
+
+ $input4 = new PresenceEntity();
+ $input4->setPresence('chat');
+ $input4->setUserid('derpina');
+ $input4->setLastActive(400);
+
+ return [
+ [
+ [$input1, $input2, $input3, $input4],
+ [
+ [
+ 'userid' => 'foo',
+ 'presence' => 'unavailable',
+ 'last_active' => '1000',
+ ],
+ [
+ 'userid' => 'derp',
+ 'presence' => 'xa',
+ 'last_active' => '600',
+ ],
+ [
+ 'userid' => 'derpina',
+ 'presence' => 'chat',
+ 'last_active' => '400',
+ ],
+ ]
+ ]
+ ];
+ }
+
+ /**
+ * @dataProvider deletePresenceProvider
+ */
+
+ public function testDeletePresence($inputs, $expected)
+ {
+ foreach ($inputs as $input) {
+ $this->mapper->setPresence($input);
+ }
+
+ $this->mapper->deletePresence('admin');
+
+ $result = $this->fetchAllAsArray();
+
+ $this->assertArrayDbResultsEqual($expected, $result, ['userid', 'last_active', 'presence']);
+ }
}
diff --git a/tests/integration/db/StanzaMapperTest.php b/tests/integration/db/StanzaMapperTest.php
index a2c09b0..279b2a1 100644
--- a/tests/integration/db/StanzaMapperTest.php
+++ b/tests/integration/db/StanzaMapperTest.php
@@ -111,4 +111,35 @@ class StanzaMapperTest extends MapperTestUtility
$this->assertEquals($stanza2->getTo(), $result[0]->getTo());
$this->assertEquals($stanza2->getStanza(), $result[0]->getStanza());
}
+
+
+ public function testDeleteByTo()
+ {
+ $stanza1 = new Stanza();
+ $stanza1->setFrom('jan@localhost');
+ $stanza1->setTo('john@localhost');
+ $stanza1->setStanza('abcd1');
+ $this->mapper->insert($stanza1);
+
+ $stanza2 = new Stanza();
+ $stanza2->setFrom('thomas@localhost');
+ $stanza2->setTo('jan@localhost');
+ $stanza2->setStanza('abcd2');
+ $this->mapper->insert($stanza2);
+
+ // check if two elements are inserted
+ $result = $this->fetchAllAsArray();
+ $this->assertArrayDbResultsEqual([
+ ['from' => 'jan@localhost', 'to' => 'john@localhost', 'stanza' => 'abcd1'],
+ ['from' => 'thomas@localhost', 'to' => 'jan@localhost', 'stanza' => 'abcd2']
+ ], $result, ['from', 'to', 'stanza']);
+
+
+ $this->mapper->deleteByTo('jan@localhost');
+
+ $result = $this->fetchAllAsArray();
+ $this->assertArrayDbResultsEqual([
+ ['from' => 'jan@localhost', 'to' => 'john@localhost', 'stanza' => 'abcd1']
+ ], $result, ['from', 'to', 'stanza']);
+ }
}