SessionContext.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. use Fabiang\Xmpp\EventListener\Stream\Session;
  39. class SessionContext extends BehatContext
  40. {
  41. /**
  42. *
  43. * @var Session
  44. */
  45. protected $listener;
  46. /**
  47. * @Given /^Test response data for session$/
  48. */
  49. public function testResponseDataForSession()
  50. {
  51. $this->getConnection()->setData(array(
  52. "<?xml version='1.0'?>"
  53. . "<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'>",
  54. "<stream:features><session xmlns='urn:ietf:params:xml:ns:xmpp-session'/></stream:features>",
  55. "<iq type='result' id='fabiang_xmpp_1234'><session xmlns='urn:ietf:params:xml:ns:xmpp-session'/></iq>"
  56. ));
  57. }
  58. /**
  59. * @Given /^Test response data for empty session$/
  60. */
  61. public function testResponseDataForEmptySession()
  62. {
  63. $this->getConnection()->setData(array(
  64. "<?xml version='1.0'?>"
  65. . "<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'>",
  66. "<stream:features><session xmlns='urn:ietf:params:xml:ns:xmpp-session'/></stream:features>",
  67. "<iq type='result' id='fabiang_xmpp_1234'/>"
  68. ));
  69. }
  70. /**
  71. * @Given /^manipulating id$/
  72. */
  73. public function manipulatingId()
  74. {
  75. $listeners = $this->getConnection()->getInputStream()->getEventManager()->getEventList();
  76. $listener = array_filter($listeners['{jabber:client}iq'], function ($listener) {
  77. return ($listener[0] instanceof Session);
  78. });
  79. $this->listener = $listener[0][0];
  80. $this->listener->setId('fabiang_xmpp_1234');
  81. }
  82. /**
  83. * @Then /^request for session send$/
  84. */
  85. public function requestForSessionSend()
  86. {
  87. $buffer = $this->getConnection()->getBuffer();
  88. assertRegExp(
  89. '#^<iq type="set" id="fabiang_xmpp_[^"]+"><session xmlns="urn:ietf:params:xml:ns:xmpp-session"/></iq>$#',
  90. $buffer[1]
  91. );
  92. }
  93. /**
  94. * @Then /^session listener is not blocking$/
  95. */
  96. public function sessionListenerIsNotBlocking()
  97. {
  98. assertFalse($this->listener->isBlocking());
  99. }
  100. /**
  101. *
  102. * @return \Fabiang\Xmpp\Connection\Test
  103. */
  104. public function getConnection()
  105. {
  106. return $this->getMainContext()->getConnection();
  107. }
  108. }