PageRenderTime 37ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/simpletestlib/selector.php

https://bitbucket.org/ceu/moodle_demo
PHP | 133 lines | 48 code | 13 blank | 72 comment | 5 complexity | 171c8dd30f06bb5adec35af93e21162b MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * Base include file for SimpleTest.
  4. * @package SimpleTest
  5. * @subpackage WebTester
  6. * @version $Id$
  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. var $_name;
  22. /**
  23. * Stashes the name for later comparison.
  24. * @param string $name Name attribute to match.
  25. */
  26. function SimpleByName($name) {
  27. $this->_name = $name;
  28. }
  29. /**
  30. * Compares with name attribute of widget.
  31. * @param SimpleWidget $widget Control to compare.
  32. * @access public
  33. */
  34. function isMatch($widget) {
  35. return ($widget->getName() == $this->_name);
  36. }
  37. }
  38. /**
  39. * Used to extract form elements for testing against.
  40. * Searches by visible label or alt text.
  41. * @package SimpleTest
  42. * @subpackage WebTester
  43. */
  44. class SimpleByLabel {
  45. var $_label;
  46. /**
  47. * Stashes the name for later comparison.
  48. * @param string $label Visible text to match.
  49. */
  50. function SimpleByLabel($label) {
  51. $this->_label = $label;
  52. }
  53. /**
  54. * Comparison. Compares visible text of widget or
  55. * related label.
  56. * @param SimpleWidget $widget Control to compare.
  57. * @access public
  58. */
  59. function isMatch($widget) {
  60. if (! method_exists($widget, 'isLabel')) {
  61. return false;
  62. }
  63. return $widget->isLabel($this->_label);
  64. }
  65. }
  66. /**
  67. * Used to extract form elements for testing against.
  68. * Searches dy id attribute.
  69. * @package SimpleTest
  70. * @subpackage WebTester
  71. */
  72. class SimpleById {
  73. var $_id;
  74. /**
  75. * Stashes the name for later comparison.
  76. * @param string $id ID atribute to match.
  77. */
  78. function SimpleById($id) {
  79. $this->_id = $id;
  80. }
  81. /**
  82. * Comparison. Compares id attribute of widget.
  83. * @param SimpleWidget $widget Control to compare.
  84. * @access public
  85. */
  86. function isMatch($widget) {
  87. return $widget->isId($this->_id);
  88. }
  89. }
  90. /**
  91. * Used to extract form elements for testing against.
  92. * Searches by visible label, name or alt text.
  93. * @package SimpleTest
  94. * @subpackage WebTester
  95. */
  96. class SimpleByLabelOrName {
  97. var $_label;
  98. /**
  99. * Stashes the name/label for later comparison.
  100. * @param string $label Visible text to match.
  101. */
  102. function SimpleByLabelOrName($label) {
  103. $this->_label = $label;
  104. }
  105. /**
  106. * Comparison. Compares visible text of widget or
  107. * related label or name.
  108. * @param SimpleWidget $widget Control to compare.
  109. * @access public
  110. */
  111. function isMatch($widget) {
  112. if (method_exists($widget, 'isLabel')) {
  113. if ($widget->isLabel($this->_label)) {
  114. return true;
  115. }
  116. }
  117. return ($widget->getName() == $this->_label);
  118. }
  119. }
  120. ?>