1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
<?php
namespace OCA\OJSXC\Db;
use Sabre\Xml\Writer;
use OCA\OJSXC\Utility\TestCase;
class IqRosterTest extends TestCase
{
public function testIqRoster()
{
$expected = '<body xmlns="http://jabber.org/protocol/httpbind"><iq to="john@localhost" type="result" id="4434"><query xmlns="jabber:iq:roster"><item jid="test@test.be" name="Test Test" subscription="both"></item><item jid="test2@test.be" name="Test2 Test" subscription="both"></item></query></iq></body>';
$writer = new Writer();
$writer->openMemory();
$writer->startElement('body');
$writer->writeAttribute('xmlns', 'http://jabber.org/protocol/httpbind');
$iqRoster = new IQRoster();
$iqRoster->setType('result');
$iqRoster->setTo('john', 'localhost');
$iqRoster->setQid(4434);
$iqRoster->addItem('test@test.be', 'Test Test');
$iqRoster->addItem('test2@test.be', 'Test2 Test');
$this->assertEquals('result', $iqRoster->getType());
$this->assertEquals('john', $iqRoster->getUnSanitizedTo());
$this->assertEquals('john@localhost', $iqRoster->to);
$this->assertEquals(4434, $iqRoster->getQid());
$this->assertEquals([
[
"name" => "item",
"attributes" => [
"jid" => "test@test.be",
"name" => "Test Test",
"subscription" => "both"
],
"value" => ''
],
[
"name" => "item",
"attributes" => [
"jid" => "test2@test.be",
"name" => "Test2 Test",
"subscription" => "both"
],
"value" => ''
],
], $iqRoster->getItems());
$writer->write($iqRoster); // needed to test the xmlSerialize function
$writer->endElement();
$result = $writer->outputMemory();
$this->assertEquals($expected, $result);
}
}
|