summaryrefslogtreecommitdiff
path: root/tests/test_tools/simpletest/selector.php
blob: 901815ad226c9ca0512a7c6b9eeef6783a9d2d5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
    /**
     *	Base include file for SimpleTest.
     *	@package	SimpleTest
     *	@subpackage	WebTester
     *	@version	$Id: selector.php 1398 2006-09-08 19:31:03Z xue $
     */

    /**#@+
     * include SimpleTest files
     */
    require_once(dirname(__FILE__) . '/tag.php');
    require_once(dirname(__FILE__) . '/encoding.php');
    /**#@-*/

    /**
     *    Used to extract form elements for testing against.
     *    Searches by name attribute.
	 *    @package SimpleTest
	 *    @subpackage WebTester
     */
    class SimpleByName {
        protected $_name;

        /**
         *    Stashes the name for later comparison.
         *    @param string $name     Name attribute to match.
         */
        function SimpleByName($name) {
            $this->_name = $name;
        }

        /**
         *    Compares with name attribute of widget.
         *    @param SimpleWidget $widget    Control to compare.
         *    @access public
         */
        function isMatch($widget) {
            return ($widget->getName() == $this->_name);
        }
    }

    /**
     *    Used to extract form elements for testing against.
     *    Searches by visible label or alt text.
	 *    @package SimpleTest
	 *    @subpackage WebTester
     */
    class SimpleByLabel {
        protected $_label;

        /**
         *    Stashes the name for later comparison.
         *    @param string $label     Visible text to match.
         */
        function SimpleByLabel($label) {
            $this->_label = $label;
        }

        /**
         *    Comparison. Compares visible text of widget or
         *    related label.
         *    @param SimpleWidget $widget    Control to compare.
         *    @access public
         */
        function isMatch($widget) {
            if (! method_exists($widget, 'isLabel')) {
                return false;
            }
            return $widget->isLabel($this->_label);
        }
    }

    /**
     *    Used to extract form elements for testing against.
     *    Searches dy id attribute.
	 *    @package SimpleTest
	 *    @subpackage WebTester
     */
    class SimpleById {
        protected $_id;

        /**
         *    Stashes the name for later comparison.
         *    @param string $id     ID atribute to match.
         */
        function SimpleById($id) {
            $this->_id = $id;
        }

        /**
         *    Comparison. Compares id attribute of widget.
         *    @param SimpleWidget $widget    Control to compare.
         *    @access public
         */
        function isMatch($widget) {
            return $widget->isId($this->_id);
        }
    }

    /**
     *    Used to extract form elements for testing against.
     *    Searches by visible label, name or alt text.
	 *    @package SimpleTest
	 *    @subpackage WebTester
     */
    class SimpleByLabelOrName {
        protected $_label;

        /**
         *    Stashes the name/label for later comparison.
         *    @param string $label     Visible text to match.
         */
        function SimpleByLabelOrName($label) {
            $this->_label = $label;
        }

        /**
         *    Comparison. Compares visible text of widget or
         *    related label or name.
         *    @param SimpleWidget $widget    Control to compare.
         *    @access public
         */
        function isMatch($widget) {
            if (method_exists($widget, 'isLabel')) {
                if ($widget->isLabel($this->_label)) {
                    return true;
                }
            }
            return ($widget->getName() == $this->_label);
        }
    }
?>