AssertHtmlTestCase.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. namespace Cake\Test\Fixture;
  3. use Cake\TestSuite\TestCase;
  4. /**
  5. * This class helps in indirectly testing the functionalities of CakeTestCase::assertHtml
  6. *
  7. */
  8. class AssertHtmlTestCase extends TestCase {
  9. /**
  10. * test that assertHtml knows how to handle correct quoting.
  11. *
  12. * @return void
  13. */
  14. public function testAssertHtmlQuotes() {
  15. $input = '<a href="/test.html" class="active">My link</a>';
  16. $pattern = array(
  17. 'a' => array('href' => '/test.html', 'class' => 'active'),
  18. 'My link',
  19. '/a'
  20. );
  21. $this->assertHtml($pattern, $input);
  22. $input = "<a href='/test.html' class='active'>My link</a>";
  23. $pattern = array(
  24. 'a' => array('href' => '/test.html', 'class' => 'active'),
  25. 'My link',
  26. '/a'
  27. );
  28. $this->assertHtml($pattern, $input);
  29. $input = "<a href='/test.html' class='active'>My link</a>";
  30. $pattern = array(
  31. 'a' => array('href' => 'preg:/.*\.html/', 'class' => 'active'),
  32. 'My link',
  33. '/a'
  34. );
  35. $this->assertHtml($pattern, $input);
  36. }
  37. /**
  38. * testNumericValuesInExpectationForAssertHtml
  39. *
  40. * @return void
  41. */
  42. public function testNumericValuesInExpectationForAssertHtml() {
  43. $value = 220985;
  44. $input = '<p><strong>' . $value . '</strong></p>';
  45. $pattern = array(
  46. '<p',
  47. '<strong',
  48. $value,
  49. '/strong',
  50. '/p'
  51. );
  52. $this->assertHtml($pattern, $input);
  53. $input = '<p><strong>' . $value . '</strong></p><p><strong>' . $value . '</strong></p>';
  54. $pattern = array(
  55. '<p',
  56. '<strong',
  57. $value,
  58. '/strong',
  59. '/p',
  60. '<p',
  61. '<strong',
  62. $value,
  63. '/strong',
  64. '/p',
  65. );
  66. $this->assertHtml($pattern, $input);
  67. $input = '<p><strong>' . $value . '</strong></p><p id="' . $value . '"><strong>' . $value . '</strong></p>';
  68. $pattern = array(
  69. '<p',
  70. '<strong',
  71. $value,
  72. '/strong',
  73. '/p',
  74. 'p' => array('id' => $value),
  75. '<strong',
  76. $value,
  77. '/strong',
  78. '/p',
  79. );
  80. $this->assertHtml($pattern, $input);
  81. }
  82. /**
  83. * testBadAssertHtml
  84. *
  85. * @return void
  86. */
  87. public function testBadAssertHtml() {
  88. $input = '<a href="/test.html" class="active">My link</a>';
  89. $pattern = array(
  90. 'a' => array('hRef' => '/test.html', 'clAss' => 'active'),
  91. 'My link2',
  92. '/a'
  93. );
  94. $this->assertHtml($pattern, $input);
  95. }
  96. /**
  97. * testBadAssertHtml
  98. *
  99. * @return void
  100. */
  101. public function testBadAssertHtml2() {
  102. $input = '<a href="/test.html" class="active">My link</a>';
  103. $pattern = array(
  104. '<a' => array('href' => '/test.html', 'class' => 'active'),
  105. 'My link',
  106. '/a'
  107. );
  108. $this->assertHtml($pattern, $input);
  109. }
  110. }