Proyectos de Subversion Moodle

Rev

Rev 11 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 1441
Línea 22... Línea 22...
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
23
 */
Línea 24... Línea 24...
24
 
24
 
Línea -... Línea 25...
-
 
25
namespace tool_brickfield\local\htmlchecker\common\checks;
-
 
26
 
25
namespace tool_brickfield\local\htmlchecker\common\checks;
27
use tool_brickfield\local\htmlchecker\brickfield_accessibility;
Línea 26... Línea 28...
26
 
28
 
Línea 27... Línea 29...
27
defined('MOODLE_INTERNAL') || die();
29
defined('MOODLE_INTERNAL') || die();
28
 
30
 
-
 
31
require_once('all_checks.php');
-
 
32
 
29
require_once('all_checks.php');
33
/**
30
 
34
 * Class img_alt_is_too_long_testcase
31
/**
35
 *
32
 * Class img_alt_is_too_long_testcase
36
 * @covers \tool_brickfield\local\htmlchecker\common\checks\img_alt_is_too_long
Línea -... Línea 37...
-
 
37
 */
-
 
38
final class img_alt_is_too_long_test extends all_checks {
-
 
39
    /** @var string Check type */
33
 */
40
    protected $checktype = 'img_alt_is_too_long';
34
class img_alt_is_too_long_test extends all_checks {
41
 
-
 
42
    /**
35
    /** @var string Check type */
43
     * Get test HTML with an image tag.
-
 
44
     *
-
 
45
     * @param string $alttext
36
    protected $checktype = 'img_alt_is_too_long';
46
     * @return string
37
 
47
     */
38
    /** @var string Html fail */
48
    protected function get_test_html(string $alttext): string {
39
    private $htmlfail = <<<EOD
49
        return <<<EOD
40
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
50
<!DOCTYPE HTML>
41
<html>
51
<html lang="en">
42
    <head>
-
 
43
        <title>Image alt attributes must not be too long</title>
-
 
44
    </head>
-
 
45
    <body>
-
 
46
    <img src="rex.jpg" alt="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent accumsan, ante varius viverra aliquam,
-
 
47
     dolor risus scelerisque massa, ut lacinia ipsum felis id est. Nullam convallis odio ante, in commodo elit fermentum sed.
52
    <head>
48
     Vivamus ullamcorper tincidunt sagittis. Sed et semper sapien. Quisque malesuada lacus nec libero cursus, aliquam malesuada
53
        <title>Image alt attributes must not be too long</title>
49
     neque ultricies. Cras sit amet enim vel orci tristique porttitor a vitae urna. Suspendisse mi leo, hendrerit et eleifend a,
54
    </head>
-
 
55
    <body>
-
 
56
    <img src="rex.jpg" alt="$alttext">
-
 
57
    </body>
-
 
58
</html>
-
 
59
EOD;
-
 
60
    }
-
 
61
 
-
 
62
    /**
-
 
63
     * Image alt text data provider.
-
 
64
     *
-
 
65
     * @return array
-
 
66
     */
-
 
67
    public static function img_alt_text_provider(): array {
-
 
68
        return [
-
 
69
            'Alt text <= 750 characters' => [
-
 
70
                true,
-
 
71
                str_repeat("Hello world!", 60),
-
 
72
            ],
-
 
73
            'Alt text > 750 characters' => [
-
 
74
                false,
-
 
75
                str_repeat("Hello world!", 65),
-
 
76
            ],
-
 
77
            'Multi-byte alt text <= 750 characters' => [
-
 
78
                true,
-
 
79
                str_repeat('こんにちは、世界!', 83),
-
 
80
            ],
-
 
81
            'Multi-byte alt text > 750 characters' => [
Línea 50... Línea -...
50
     mollis at ex. Maecenas eget magna nec sem dignissim pharetra vel nec ex. Donec in porta lectus. Aenean porttitor euismod
-
 
51
     lectus, sodales eleifend ex egestas in. Donec sed metus sodales, lobortis velit quis, dictum arcu.">
-
 
52
    </body>
-
 
53
</html>
-
 
54
EOD;
-
 
55
 
-
 
56
    /** @var string Html pass */
-
 
57
    private $htmlpass = <<<EOD
-
 
58
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
-
 
59
<html>
-
 
60
    <head>
-
 
61
        <title>Image alt attributes must not be too long</title>
-
 
62
    </head>
82
                false,
63
    <body>
83
                str_repeat('こんにちは、世界!', 90),
-
 
84
            ],
-
 
85
        ];
-
 
86
    }
-
 
87
 
64
    <img src="rex.jpg" alt="this is an image of rex">
88
    /**
65
    </body>
89
     * Test for image alt attributes being too long
-
 
90
     *
66
</html>
91
     * @dataProvider img_alt_text_provider
-
 
92
     * @param bool $expectedpass Whether the test is expected to pass or fail.
-
 
93
     * @param string $alttext The alt text to test.
-
 
94
     */
67
EOD;
95
    public function test_check(bool $expectedpass, string $alttext): void {
-
 
96
        $html = $this->get_test_html($alttext);
-
 
97
        $results = $this->get_checker_results($html);
Línea -... Línea 98...
-
 
98
        if ($expectedpass) {
68
    /**
99
            $this->assertEmpty($results);
-
 
100
        } else {
-
 
101
            $this->assertEquals('img', $results[0]->element->tagName);
-
 
102
        }
-
 
103
    }
69
     * Test for image alt attributes being too long
104
 
-
 
105
    /**
-
 
106
     * Test the severity of the {@see img_alt_is_too_long} check.
70
     */
107
     *
71
    public function test_check(): void {
108
     * @return void