DomQueryTest.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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_Test
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2015 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. * @see Zend_Test_PHPUnit_Constraint_DomQuery
  24. */
  25. require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Test
  29. * @subpackage UnitTests
  30. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. * @group Zend_Test
  33. * @group Zend_Test_PHPUnit
  34. */
  35. class Zend_Test_PHPUnit_Constraint_DomQueryTest extends PHPUnit_Framework_TestCase
  36. {
  37. /**
  38. * @group ZF-4010
  39. */
  40. public function testShouldAllowMatchingOfAttributeValues()
  41. {
  42. $html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  43. <html>
  44. <head>
  45. <title>ZF Issue ZF-4010</title>
  46. </head>
  47. <body>
  48. <form>
  49. <fieldset id="fieldset-input"><legend>Inputs</legend>
  50. <ol>
  51. <li><input type="text" name="input[0]" id="input-0" value="value1" /></li>
  52. <li><input type="text" name="input[1]" id="input-1" value="value2" /></li>
  53. <li><input type="text" name="input[2]" id="input-2" value="" /></li>
  54. </ol>
  55. </fieldset>
  56. </form>
  57. </body>
  58. </html>';
  59. $assertion = new Zend_Test_PHPUnit_Constraint_DomQuery('input#input-0 @value');
  60. $result = $assertion->evaluate($html,
  61. Zend_Test_PHPUnit_Constraint_DomQuery::ASSERT_CONTENT_CONTAINS, 'value1');
  62. $this->assertTrue($result);
  63. }
  64. /**
  65. * @group issue-303
  66. */
  67. public function testShouldAllowMatchingZeroCounts()
  68. {
  69. $html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  70. <html>
  71. <head>
  72. <title>ZF Issue ZF-4010</title>
  73. </head>
  74. <body>
  75. <form>
  76. <fieldset id="fieldset-input"><legend>Inputs</legend>
  77. <ol>
  78. <li><input type="text" name="input[0]" id="input-0" value="value1" /></li>
  79. <li><input type="text" name="input[1]" id="input-1" value="value2" /></li>
  80. <li><input type="text" name="input[2]" id="input-2" value="" /></li>
  81. </ol>
  82. </fieldset>
  83. </form>
  84. </body>
  85. </html>';
  86. $assertion = new Zend_Test_PHPUnit_Constraint_DomQuery('input#input-3 @value');
  87. $result = $assertion->evaluate($html,
  88. Zend_Test_PHPUnit_Constraint_DomQuery::ASSERT_CONTENT_COUNT, 0);
  89. $this->assertTrue($result);
  90. }
  91. }