/tests/Zend/DebugTest.php

https://github.com/WebTricks/WebTricks-CMS · PHP · 121 lines · 67 code · 15 blank · 39 comment · 1 complexity · 701678a8491c7dc500fce797914cba3c MD5 · raw file

  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_Debug
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2010 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. /**
  23. * Test helper
  24. */
  25. require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'TestHelper.php';
  26. /**
  27. * Zend_Debug
  28. */
  29. require_once 'Zend/Debug.php';
  30. /**
  31. * @category Zend
  32. * @package Zend_Debug
  33. * @subpackage UnitTests
  34. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  35. * @license http://framework.zend.com/license/new-bsd New BSD License
  36. * @group Zend_Debug
  37. */
  38. class Zend_DebugTest extends PHPUnit_Framework_TestCase
  39. {
  40. public function testDebugDefaultSapi()
  41. {
  42. $sapi = php_sapi_name();
  43. Zend_Debug::setSapi(null);
  44. $data = 'string';
  45. $result = Zend_Debug::Dump($data, null, false);
  46. $this->assertEquals($sapi, Zend_Debug::getSapi());
  47. }
  48. public function testDebugDump()
  49. {
  50. Zend_Debug::setSapi('cli');
  51. $data = 'string';
  52. $result = Zend_Debug::Dump($data, null, false);
  53. $result = str_replace(array(PHP_EOL, "\n"), '_', $result);
  54. $expected = "__string(6) \"string\"__";
  55. $this->assertEquals($expected, $result);
  56. }
  57. public function testDebugCgi()
  58. {
  59. Zend_Debug::setSapi('cgi');
  60. $data = 'string';
  61. $result = Zend_Debug::Dump($data, null, false);
  62. // Has to check for two strings, because xdebug internally handles CLI vs Web
  63. $this->assertContains($result,
  64. array(
  65. "<pre>string(6) \"string\"\n</pre>",
  66. "<pre>string(6) &quot;string&quot;\n</pre>",
  67. )
  68. );
  69. }
  70. public function testDebugDumpEcho()
  71. {
  72. Zend_Debug::setSapi('cli');
  73. $data = 'string';
  74. ob_start();
  75. $result1 = Zend_Debug::Dump($data, null, true);
  76. $result2 = ob_get_contents();
  77. ob_end_clean();
  78. $this->assertContains('string(6) "string"', $result1);
  79. $this->assertEquals($result1, $result2);
  80. }
  81. public function testDebugDumpLabel()
  82. {
  83. Zend_Debug::setSapi('cli');
  84. $data = 'string';
  85. $label = 'LABEL';
  86. $result = Zend_Debug::Dump($data, $label, false);
  87. $result = str_replace(array(PHP_EOL, "\n"), '_', $result);
  88. $expected = "_{$label} _string(6) \"string\"__";
  89. $this->assertEquals($expected, $result);
  90. }
  91. /**
  92. * @group ZF-4136
  93. * @group ZF-1663
  94. */
  95. public function testXdebugEnabledAndNonCliSapiDoesNotEscapeSpecialChars()
  96. {
  97. if(!extension_loaded('xdebug')) {
  98. $this->markTestSkipped("This test only works in combination with xdebug.");
  99. }
  100. Zend_Debug::setSapi('apache');
  101. $a = array("a" => "b");
  102. $result = Zend_Debug::dump($a, "LABEL", false);
  103. $this->assertContains("<pre>", $result);
  104. $this->assertContains("</pre>", $result);
  105. }
  106. }