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

XMPPResponseTest.php « http « unit « tests - github.com/nextcloud/jsxc.nextcloud.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a0c00ac4f96aaa0280d82a68aaf6c525f31ca067 (plain)
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
58
59
60
61
<?php

namespace OCA\OJSXC\Http {

	use OCA\OJSXC\Db\Message;
	use OCA\OJSXC\Db\Stanza;
	use PHPUnit\Framework\TestCase;

	class XMPPResponseTest extends TestCase
	{
		public function writingProvider()
		{
			$stanza1 = new Stanza();
			$stanza1->setFrom('test', 'test.be');
			$stanza1->setTo('test.be');
			$stanza1->setStanza('abc');

			$stanza2 = new Message();
			$stanza2->setAttrId('4-msg');
			$stanza2->setFrom('test', 'test.be');
			$stanza2->setTo('test.be');
			$stanza2->setStanza('abc');
			$stanza2->setType('testtype');
			$stanza2->setValue('abcvalue');

			return [
				[
					[new Stanza('')],
					'<body xmlns="http://jabber.org/protocol/httpbind"></body>'
				],
				[
					[$stanza1],
					'<body xmlns="http://jabber.org/protocol/httpbind">abc</body>'
				],
				[
					[$stanza1, $stanza2],
					'<body xmlns="http://jabber.org/protocol/httpbind">abc<message to="test.be" from="test@test.be" type="testtype" xmlns="jabber:client" id="4-msg">abcvalue</message></body>'
				],
				[
					[$stanza1, new Stanza(''), $stanza2],
					'<body xmlns="http://jabber.org/protocol/httpbind">abc<message to="test.be" from="test@test.be" type="testtype" xmlns="jabber:client" id="4-msg">abcvalue</message></body>'
				],
			];
		}

		/**
		 * @dataProvider writingProvider
		 */
		public function testWriting($stanzas, $expected)
		{
			$stanzaLogger = $this->getMockBuilder('OCA\OJSXC\StanzaLogger')->disableOriginalConstructor()->getMock();
			$response = new XMPPResponse($stanzaLogger);
			foreach ($stanzas as $stanza) {
				$response->write($stanza);
			}
			$result = $response->render();
			$this->assertEquals($expected, $result);
		}
	}

}