Proyectos de Subversion Moodle

Rev

Ir a la última revisión | | 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 img_alt_not_placeholder_testcase
33
 */
34
class img_alt_not_place_holder_test extends all_checks {
35
    /** @var string Check type */
36
    protected $checktype = 'img_alt_not_place_holder';
37
 
38
    /** @var string Html fail 1 */
39
    private $htmlfail1 = <<<EOD
40
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
41
<html>
42
    <head>
43
        <title>Image alt attributes match the specified string array in imgAltNotPlaceHolder- fail</title>
44
    </head>
45
    <body>
46
    <img src="rex.jpg" alt="nbsp">
47
    </body>
48
</html>
49
EOD;
50
 
51
    /** @var string Html fail 2 */
52
    private $htmlfail2 = <<<EOD
53
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
54
<html>
55
    <head>
56
        <title>Image alt attributes match the specified string array in imgAltNotPlaceHolder- fail</title>
57
    </head>
58
    <body>
59
    <img src="rex.jpg" alt="&nbsp;">
60
    </body>
61
</html>
62
EOD;
63
 
64
    /** @var string Html fail 3 */
65
    private $htmlfail3 = <<<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>Image alt attributes match the specified string array in imgAltNotPlaceHolder- fail</title>
70
    </head>
71
    <body>
72
    <img src="rex.jpg" alt="spacer">
73
    </body>
74
</html>
75
EOD;
76
 
77
    /** @var string Html fail 4 */
78
    private $htmlfail4 = <<<EOD
79
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
80
<html>
81
    <head>
82
        <title>Image alt attributes match the specified string array in imgAltNotPlaceHolder- fail</title>
83
    </head>
84
    <body>
85
    <img src="rex.jpg" alt="image">
86
    </body>
87
</html>
88
EOD;
89
 
90
    /** @var string Html fail 5 */
91
    private $htmlfail5 = <<<EOD
92
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
93
<html>
94
    <head>
95
        <title>Image alt attributes match the specified string array in imgAltNotPlaceHolder- fail</title>
96
    </head>
97
    <body>
98
    <img src="rex.jpg" alt="img">
99
    </body>
100
</html>
101
EOD;
102
 
103
    /** @var string Html fail 6 */
104
    private $htmlfail6 = <<<EOD
105
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
106
<html>
107
    <head>
108
        <title>Image alt attributes match the specified string array in imgAltNotPlaceHolder- fail</title>
109
    </head>
110
    <body>
111
    <img src="rex.jpg" alt="photo">
112
    </body>
113
</html>
114
EOD;
115
 
116
    /** @var string Html pass 1 */
117
    private $htmlpass1 = <<<EOD
118
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
119
<html>
120
    <head>
121
        <title>Image alt attributes must not match the string array specified in imgAltNotPlaceHolder - pass</title>
122
    </head>
123
    <body>
124
    <img src="rex.jpg" alt="A mountian with a sunset">
125
    </body>
126
</html>
127
EOD;
128
 
129
    /**
130
     * Notes:  espacio & imagen & foto within the 'es' lang_string, all pass - they shouldn't.
131
     */
132
 
133
    /**
134
     * Test for the each en string specified in $strings - line 43 in imgAltNotPlaceHolder.
135
     */
136
    public function test_failcheck() {
137
        $results = $this->get_checker_results($this->htmlfail1);
138
        $this->assertTrue($results[0]->element->tagName == 'img');
139
 
140
        $results = $this->get_checker_results($this->htmlfail2);
141
        $this->assertTrue($results[0]->element->tagName == 'img');
142
 
143
        $results = $this->get_checker_results($this->htmlfail3);
144
        $this->assertTrue($results[0]->element->tagName == 'img');
145
 
146
        $results = $this->get_checker_results($this->htmlfail4);
147
        $this->assertTrue($results[0]->element->tagName == 'img');
148
 
149
        $results = $this->get_checker_results($this->htmlfail5);
150
        $this->assertTrue($results[0]->element->tagName == 'img');
151
 
152
        $results = $this->get_checker_results($this->htmlfail6);
153
        $this->assertTrue($results[0]->element->tagName == 'img');
154
    }
155
 
156
    /**
157
     * Test with alt that was not specified in the $strings array.
158
     */
159
    public function test_passcheck1() {
160
        $results = $this->get_checker_results($this->htmlpass1);
161
        $this->assertEmpty($results);
162
    }
163
}