XMLObjTest.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * XMPPHP: The PHP XMPP Library
  4. * Copyright (C) 2008 Nathanael C. Fritz
  5. * This file is part of SleekXMPP.
  6. *
  7. * XMPPHP is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * XMPPHP is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with XMPPHP; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * @category xmpphp
  22. * @package XMPPHP
  23. * @author Nathanael C. Fritz <JID: fritzy@netflint.net>
  24. * @author Stephan Wentz <JID: stephan@jabber.wentz.it>
  25. * @author Michael Garvin <JID: gar@netflint.net>
  26. * @copyright 2008 Nathanael C. Fritz
  27. */
  28. /** XMPPHP_XMLObj */
  29. require_once CLASS_DIR . 'XMPPHP' . DIRECTORY_SEPARATOR . 'XMLObj.php';
  30. /**
  31. * XMPPHP XMLObjectTest
  32. *
  33. * @package XMPPHP
  34. * @author Nathanael C. Fritz <JID: fritzy@netflint.net>
  35. * @author Stephan Wentz <JID: stephan@jabber.wentz.it>
  36. * @author Michael Garvin <JID: gar@netflint.net>
  37. * @copyright 2008 Nathanael C. Fritz
  38. * @version $Id$
  39. */
  40. class XMPPHP_XMLObjTest extends PHPUnit_Framework_TestCase
  41. {
  42. public function testToStringNameNamespace()
  43. {
  44. $xmlobj = new XMPPHP_XMLObj('testname', 'testNameSpace');
  45. $expected = '<testname xmlns="testNameSpace"></testname>';
  46. $result = $xmlobj->toString();
  47. $this->assertSame($expected, $result);
  48. }
  49. public function testToStringNameNamespaceAttr()
  50. {
  51. $xmlobj = new XMPPHP_XMLObj('testName', 'testNameSpace', ['attr1' => 'valA', 'attr2' => 'valB']);
  52. $expected = '<testname xmlns="testNameSpace" attr1="valA" attr2="valB"></testname>';
  53. $result = $xmlobj->toString();
  54. $this->assertSame($expected, $result);
  55. }
  56. public function testToStringNameNamespaceData()
  57. {
  58. $xmlobj = new XMPPHP_XMLObj('testName', 'testNameSpace', [], 'I am test data');
  59. $expected = '<testname xmlns="testNameSpace">I am test data</testname>';
  60. $result = $xmlobj->toString();
  61. $this->assertSame($expected, $result);
  62. }
  63. public function testToStringNameNamespaceSub()
  64. {
  65. $xmlobj = new XMPPHP_XMLObj('testName', 'testNameSpace');
  66. $sub1 = new XMPPHP_XMLObj('subName', 'subNameSpace');
  67. $xmlobj->subs = [$sub1];
  68. $expected = '<testname xmlns="testNameSpace"><subname xmlns="subNameSpace"></subname></testname>';
  69. $result = $xmlobj->toString();
  70. $this->assertSame($expected, $result);
  71. }
  72. }