Proyectos de Subversion Moodle

Rev

Rev 11 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
/**
18
 * tool_brickfield check test.
19
 *
20
 * @package    tool_brickfield
21
 * @copyright  2020 onward: Brickfield Education Labs, https://www.brickfield.ie
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
namespace tool_brickfield\local\htmlchecker\common\checks;
26
 
27
defined('MOODLE_INTERNAL') || die();
28
 
29
require_once('all_checks.php');
30
 
31
/**
32
 * Class table_data_should_have_th_test
1441 ariadna 33
 *
34
 * @covers \tool_brickfield\local\htmlchecker\common\checks\table_data_should_have_th
1 efrain 35
 */
1441 ariadna 36
final class table_data_should_have_th_test extends all_checks {
1 efrain 37
    /** @var string Check type */
38
    public $checktype = 'table_data_should_have_th';
39
 
40
    /** @var string Html fail 1 */
41
    private $htmlfail1 = <<<EOD
42
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
43
<html>
44
    <head>
45
    <title>Table should have at least one th - fail</title>
46
    </head>
47
    <body>
48
        <table>
49
            <thead>
50
                <tr>
51
 
52
                </tr>
53
            </thead>
54
            <tbody>
55
                <tr>
56
                    <td>This is a tables data</td>
57
                </tr>
58
            </tbody>
59
        </table>
60
    </body>
61
</html>
62
EOD;
63
 
64
    /** @var string Html fail 2 */
65
    private $htmlfail2 = <<<EOD
66
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
67
<html>
68
    <head>
69
        <title>Table should have at least one th - fail</title>
70
    </head>
71
    <body>
72
        <table>
73
            <tr>
74
 
75
            </tr>
76
            <tr>
77
                <td>This is a tables data</td>
78
            </tr>
79
        </table>
80
    </body>
81
</html>
82
EOD;
83
 
84
    /** @var string Html pass 1 */
85
    private $htmlpass1 = <<<EOD
86
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
87
<html>
88
    <head>
89
        <title>Table should have at least one th - pass</title>
90
    </head>
91
    <body>
92
        <table>
93
            <thead>
94
                <tr><th>This is table heading</th></tr>
95
            </thead>
96
            <tbody>
97
                <tr><td>This is a tables data</td></tr>
98
            </tbody>
99
        </table>
100
    </body>
101
</html>
102
EOD;
103
 
104
    /** @var string Html pass 2 */
105
    private $htmlpass2 = <<<EOD
106
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
107
<html>
108
    <head>
109
        <title>Table should have at least one th - pass</title>
110
    </head>
111
    <body>
112
        <table>
113
            <tr><th>This is table heading</th></tr>
114
            <tr><td>This is a tables data</td></tr>
115
        </table>
116
    </body>
117
</html>
118
EOD;
1441 ariadna 119
 
120
    /** @var string HTML that should not get flagged. */
121
    private $htmlpass3 = <<<EOD
122
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
123
<html>
124
    <head>
125
        <title>Table should have at least one th - pass</title>
126
    </head>
127
    <body>
128
        <table>
129
            <thead>
130
                <tr>
131
                    <th>
132
                        This is table heading
133
                    </th>
134
                </tr>
135
            </thead>
136
            <tbody>
137
                <tr>
138
                    <td>
139
                        This is a tables data
140
                    </td>
141
                </tr>
142
            </tbody>
143
        </table>
144
    </body>
145
</html>
146
EOD;
147
 
148
    /** @var string HTML that should not get flagged. */
149
    private $htmlpass4 = <<<EOD
150
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
151
<html>
152
    <head>
153
        <title>Table should have at least one th - pass</title>
154
    </head>
155
    <body>
156
        <table>
157
            <tr>
158
                <th>
159
                    This is table heading
160
                </th>
161
            </tr>
162
            <tr>
163
                <td>
164
                    This is a tables data
165
                </td>
166
            </tr>
167
        </table>
168
    </body>
169
</html>
170
EOD;
171
 
172
    /** @var string HTML that should not get flagged. */
173
    private $htmlpass5 = <<<EOD
174
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
175
<html>
176
    <head>
177
        <title>Table should have at least one th - pass</title>
178
    </head>
179
    <body>
180
        <table>
181
            <thead>
182
                <tr>
183
                    <th>
184
                        This is table heading
185
                    </th>
186
                </tr>
187
            </thead>
188
            <tbody>
189
                <tr>
190
                    <th>
191
                        This is a table heading in table data
192
                    </th>
193
                </tr>
194
                <tr>
195
                    <td>
196
                        This is a tables data
197
                    </td>
198
                </tr>
199
            </tbody>
200
        </table>
201
    </body>
202
</html>
203
EOD;
204
 
205
    /** @var string HTML that should not get flagged. */
206
    private $htmlpass6 = <<<EOD
207
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
208
<html>
209
    <head>
210
        <title>Table should have at least one th - pass</title>
211
    </head>
212
    <body>
213
        <table>
214
            <tbody>
215
                <tr>
216
                    <th>
217
                        This is a table heading in table data
218
                    </th>
219
                </tr>
220
                <tr>
221
                    <td>
222
                        This is a tables data
223
                    </td>
224
                </tr>
225
            </tbody>
226
        </table>
227
    </body>
228
</html>
229
EOD;
1 efrain 230
    /**
231
     * Test that th does not exist
232
     */
11 efrain 233
    public function test_check_fail(): void {
1 efrain 234
        $results = $this->get_checker_results($this->htmlfail1);
235
        $this->assertTrue($results[0]->element->tagName == 'table');
236
 
237
        $results = $this->get_checker_results($this->htmlfail2);
238
        $this->assertTrue($results[0]->element->tagName == 'table');
239
    }
240
 
241
    /**
242
     * Test that th does exist
243
     */
11 efrain 244
    public function test_check_pass(): void {
1 efrain 245
        $results = $this->get_checker_results($this->htmlpass1);
246
        $this->assertEmpty($results);
247
 
248
        $results = $this->get_checker_results($this->htmlpass2);
249
        $this->assertEmpty($results);
1441 ariadna 250
 
251
        $results = $this->get_checker_results($this->htmlpass3);
252
        $this->assertEmpty($results);
253
 
254
        $results = $this->get_checker_results($this->htmlpass4);
255
        $this->assertEmpty($results);
256
 
257
        $results = $this->get_checker_results($this->htmlpass5);
258
        $this->assertEmpty($results);
259
 
260
        $results = $this->get_checker_results($this->htmlpass6);
261
        $this->assertEmpty($results);
1 efrain 262
    }
263
}