2
0

XmlTest.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Log
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. require_once dirname(__FILE__)."/../../../TestHelper.php";
  23. /** PHPUnit_Framework_TestCase */
  24. require_once 'PHPUnit/Framework/TestCase.php';
  25. /** Zend_Log_Formatter_Xml */
  26. require_once 'Zend/Log/Formatter/Xml.php';
  27. /**
  28. * @category Zend
  29. * @package Zend_Log
  30. * @subpackage UnitTests
  31. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  32. * @license http://framework.zend.com/license/new-bsd New BSD License
  33. * @group Zend_Log
  34. */
  35. class Zend_Log_Formatter_XmlTest extends PHPUnit_Framework_TestCase
  36. {
  37. public function testDefaultFormat()
  38. {
  39. $f = new Zend_Log_Formatter_Xml();
  40. $line = $f->format(array('message' => 'foo', 'priority' => 42));
  41. $this->assertContains('foo', $line);
  42. $this->assertContains((string)42, $line);
  43. }
  44. public function testConfiguringElementMapping()
  45. {
  46. $f = new Zend_Log_Formatter_Xml('log', array('foo' => 'bar'));
  47. $line = $f->format(array('bar' => 'baz'));
  48. $this->assertContains('<log><foo>baz</foo></log>', $line);
  49. }
  50. public function testXmlDeclarationIsStripped()
  51. {
  52. $f = new Zend_Log_Formatter_Xml();
  53. $line = $f->format(array('message' => 'foo', 'priority' => 42));
  54. $this->assertNotContains('<\?xml version=', $line);
  55. }
  56. public function testXmlValidates()
  57. {
  58. $f = new Zend_Log_Formatter_Xml();
  59. $line = $f->format(array('message' => 'foo', 'priority' => 42));
  60. $sxml = @simplexml_load_string($line);
  61. $this->assertType('SimpleXMLElement', $sxml, 'Formatted XML is invalid');
  62. }
  63. /**
  64. * @group ZF-2062
  65. * @group ZF-4190
  66. */
  67. public function testHtmlSpecialCharsInMessageGetEscapedForValidXml()
  68. {
  69. $f = new Zend_Log_Formatter_Xml();
  70. $line = $f->format(array('message' => '&key1=value1&key2=value2', 'priority' => 42));
  71. $this->assertContains("&amp;", $line);
  72. $this->assertTrue(substr_count($line, "&amp;") == 2);
  73. }
  74. /**
  75. * @group ZF-2062
  76. * @group ZF-4190
  77. */
  78. public function testFixingBrokenCharsSoXmlIsValid()
  79. {
  80. $f = new Zend_Log_Formatter_Xml();
  81. $line = $f->format(array('message' => '&amp', 'priority' => 42));
  82. $this->assertContains('&amp;amp', $line);
  83. }
  84. }