RosterContext.php 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * Copyright 2014 Fabian Grutschus. All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without modification,
  6. * are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  16. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  17. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  19. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  20. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  21. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  22. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. *
  26. * The views and conclusions contained in the software and documentation are those
  27. * of the authors and should not be interpreted as representing official policies,
  28. * either expressed or implied, of the copyright holders.
  29. *
  30. * @author Fabian Grutschus <f.grutschus@lubyte.de>
  31. * @copyright 2014 Fabian Grutschus. All rights reserved.
  32. * @license BSD
  33. * @link http://github.com/fabiang/xmpp
  34. */
  35. namespace Fabiang\Xmpp\Integration;
  36. use Behat\Behat\Context\BehatContext;
  37. use Behat\Behat\Exception\PendingException;
  38. class RosterContext extends BehatContext
  39. {
  40. /**
  41. * @Given /^Test response data for roster request$/
  42. */
  43. public function testResponseDataForRosterRequest()
  44. {
  45. $this->getConnection()->setData(array(
  46. "<?xml version='1.0'?>"
  47. . "<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'>",
  48. "<stream:features></stream:features>",
  49. "<iq from='test@localhost' to='test@localhost/1234567890' id='fabiang_xmpp_52dfea36bbc83' type='result'>"
  50. . "<query xmlns='jabber:iq:roster'>"
  51. . "<item subscription='both' name='John Doe' jid='john.doe@localhost'>"
  52. . "<group>MyGroup</group>"
  53. . "<group>MyOtherGroup</group>"
  54. . "</item>"
  55. . "</query>"
  56. . "</iq>"
  57. ));
  58. }
  59. /**
  60. * @Given /^Roster request send$/
  61. */
  62. public function rosterRequestSend()
  63. {
  64. $this->getConnection()->send(
  65. '<iq type="get" id="fabiang_xmpp_1234"><query xmlns="jabber:iq:roster"/></iq>'
  66. );
  67. }
  68. /**
  69. * @Then /^options object should contain roster data$/
  70. */
  71. public function optionsObjectShouldContainRosterData()
  72. {
  73. $users = $this->getConnection()->getOptions()->getUsers();
  74. assertCount(1, $users);
  75. /* @var $user \Fabiang\Xmpp\Protocol\User\User */
  76. $user = $users[0];
  77. assertSame('John Doe', $user->getName());
  78. assertSame('john.doe@localhost', $user->getJid());
  79. assertSame('both', $user->getSubscription());
  80. assertSame(array('MyGroup', 'MyOtherGroup'), $user->getGroups());
  81. }
  82. /**
  83. *
  84. * @return \Fabiang\Xmpp\Connection\Test
  85. */
  86. public function getConnection()
  87. {
  88. return $this->getMainContext()->getConnection();
  89. }
  90. }