selector.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. /**
  3. * Base include file for SimpleTest.
  4. * @package SimpleTest
  5. * @subpackage WebTester
  6. * @version $Id: selector.php 1786 2008-04-26 17:32:20Z pp11 $
  7. */
  8. /**#@+
  9. * include SimpleTest files
  10. */
  11. require_once(dirname(__FILE__) . '/tag.php');
  12. require_once(dirname(__FILE__) . '/encoding.php');
  13. /**#@-*/
  14. /**
  15. * Used to extract form elements for testing against.
  16. * Searches by name attribute.
  17. * @package SimpleTest
  18. * @subpackage WebTester
  19. */
  20. class SimpleByName {
  21. private $name;
  22. /**
  23. * Stashes the name for later comparison.
  24. * @param string $name Name attribute to match.
  25. */
  26. function __construct($name) {
  27. $this->name = $name;
  28. }
  29. /**
  30. * Accessor for name.
  31. * @returns string $name Name to match.
  32. */
  33. function getName() {
  34. return $this->name;
  35. }
  36. /**
  37. * Compares with name attribute of widget.
  38. * @param SimpleWidget $widget Control to compare.
  39. * @access public
  40. */
  41. function isMatch($widget) {
  42. return ($widget->getName() == $this->name);
  43. }
  44. }
  45. /**
  46. * Used to extract form elements for testing against.
  47. * Searches by visible label or alt text.
  48. * @package SimpleTest
  49. * @subpackage WebTester
  50. */
  51. class SimpleByLabel {
  52. private $label;
  53. /**
  54. * Stashes the name for later comparison.
  55. * @param string $label Visible text to match.
  56. */
  57. function __construct($label) {
  58. $this->label = $label;
  59. }
  60. /**
  61. * Comparison. Compares visible text of widget or
  62. * related label.
  63. * @param SimpleWidget $widget Control to compare.
  64. * @access public
  65. */
  66. function isMatch($widget) {
  67. if (! method_exists($widget, 'isLabel')) {
  68. return false;
  69. }
  70. return $widget->isLabel($this->label);
  71. }
  72. }
  73. /**
  74. * Used to extract form elements for testing against.
  75. * Searches dy id attribute.
  76. * @package SimpleTest
  77. * @subpackage WebTester
  78. */
  79. class SimpleById {
  80. private $id;
  81. /**
  82. * Stashes the name for later comparison.
  83. * @param string $id ID atribute to match.
  84. */
  85. function __construct($id) {
  86. $this->id = $id;
  87. }
  88. /**
  89. * Comparison. Compares id attribute of widget.
  90. * @param SimpleWidget $widget Control to compare.
  91. * @access public
  92. */
  93. function isMatch($widget) {
  94. return $widget->isId($this->id);
  95. }
  96. }
  97. /**
  98. * Used to extract form elements for testing against.
  99. * Searches by visible label, name or alt text.
  100. * @package SimpleTest
  101. * @subpackage WebTester
  102. */
  103. class SimpleByLabelOrName {
  104. private $label;
  105. /**
  106. * Stashes the name/label for later comparison.
  107. * @param string $label Visible text to match.
  108. */
  109. function __construct($label) {
  110. $this->label = $label;
  111. }
  112. /**
  113. * Comparison. Compares visible text of widget or
  114. * related label or name.
  115. * @param SimpleWidget $widget Control to compare.
  116. * @access public
  117. */
  118. function isMatch($widget) {
  119. if (method_exists($widget, 'isLabel')) {
  120. if ($widget->isLabel($this->label)) {
  121. return true;
  122. }
  123. }
  124. return ($widget->getName() == $this->label);
  125. }
  126. }
  127. ?>