diff options
author | Tobia De Koninck <tobia@ledfan.be> | 2017-10-11 18:40:04 +0300 |
---|---|---|
committer | Tobia De Koninck <tobia@ledfan.be> | 2017-10-11 18:40:15 +0300 |
commit | 75b7a02f9478b23365d5fb4b3bbac2d3114498e5 (patch) | |
tree | ec2a273e245870f656cd9475c517c4248961c873 /tests/unit | |
parent | 7bf730e4037bb327e301370671e3314f861d1ae0 (diff) |
Add and fix tests for only including enabled users in the roster
Signed-off-by: Tobia De Koninck <tobia@ledfan.be>
Diffstat (limited to 'tests/unit')
-rw-r--r-- | tests/unit/stanzahandlers/IQTest.php | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/tests/unit/stanzahandlers/IQTest.php b/tests/unit/stanzahandlers/IQTest.php index 6c15c56..50824bf 100644 --- a/tests/unit/stanzahandlers/IQTest.php +++ b/tests/unit/stanzahandlers/IQTest.php @@ -50,18 +50,28 @@ class IQTest extends PHPUnit_Framework_TestCase $user1->expects($this->any()) ->method('getUID') ->will($this->returnValue('john')); + $user1->expects($this->any()) ->method('getDisplayName') ->will($this->returnValue('John')); + $user1->expects($this->any()) + ->method('isEnabled') + ->will($this->returnValue(true)); + $user2 = $this->getMockBuilder('OCP\IUser')->disableOriginalConstructor()->getMock(); $user2->expects($this->any()) ->method('getUID') ->will($this->returnValue('richard')); + $user2->expects($this->any()) ->method('getDisplayName') ->will($this->returnValue('Richard')); + $user2->expects($this->any()) + ->method('isEnabled') + ->will($this->returnValue(true)); + $expected1 = new IQRoster(); $expected1->setType('result'); @@ -175,4 +185,77 @@ class IQTest extends PHPUnit_Framework_TestCase $this->assertEquals($expected, $result); } } + + public function testIqRosterWithDisabledUsers() + { + $user1 = $this->getMockBuilder('OCP\IUser')->disableOriginalConstructor()->getMock(); + $user1->expects($this->any()) + ->method('getUID') + ->will($this->returnValue('jan')); + + $user1->expects($this->any()) + ->method('getDisplayName') + ->will($this->returnValue('Jan')); + + $user1->expects($this->any()) + ->method('isEnabled') + ->will($this->returnValue(true)); + + $user2 = $this->getMockBuilder('OCP\IUser')->disableOriginalConstructor()->getMock(); + $user2->expects($this->any()) + ->method('getUID') + ->will($this->returnValue('richard')); + + $user2->expects($this->any()) + ->method('getDisplayName') + ->will($this->returnValue('Richard')); + + $user2->expects($this->any()) + ->method('isEnabled') + ->will($this->returnValue(false)); + + $expected = new IQRoster(); + $expected->setType('result'); + $expected->setTo('john'); + $expected->setQid('f9a26583-3c59-4f09-89be-964ce265fbfd:sendIQ'); + $expected->addItem('jan@localhost', 'Jan'); + + $this->config->expects($this->once()) + ->method('getSystemValue') + ->with('debug') + ->will($this->returnValue(false)); + + $this->userManager->expects($this->once()) + ->method('search') + ->with('') + ->will($this->returnValue([$user1, $user2])); + + $result = $this->iq->handle( + [ + 'name' => '{jabber:client}iq', + 'value' => + [ + 0 => + [ + 'name' => '{jabber:iq:roster}query', + 'value' => null, + 'attributes' => [] + ] + ], + 'attributes' => + [ + 'type' => 'get', + 'id' => 'f9a26583-3c59-4f09-89be-964ce265fbfd:sendIQ', + ], + ] + ); + + $this->assertEquals($expected->getFrom(), $result->getFrom()); + $this->assertEquals($expected->getId(), $result->getId()); + $this->assertEquals($expected->getItems(), $result->getItems()); + $this->assertEquals($expected->getQid(), $result->getQid()); + $this->assertEquals($expected->getTo(), $result->getTo()); + $this->assertEquals($expected->getType(), $result->getType()); + $this->assertEquals($expected->getStanza(), $result->getStanza()); + } } |