aboutsummaryrefslogtreecommitdiffstats
path: root/lib/htmlpurifier/tests/HTMLPurifier/AttrTransform/InputTest.php
blob: 2603ff1beaa386d00b3365e5658f0976f5fc3fec (plain) (blame)
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
<?php

class HTMLPurifier_AttrTransform_InputTest extends HTMLPurifier_AttrTransformHarness
{

    function setUp() {
        parent::setUp();
        $this->obj = new HTMLPurifier_AttrTransform_Input();
    }

    function testEmptyInput() {
        $this->assertResult(array());
    }

    function testInvalidCheckedWithEmpty() {
        $this->assertResult(array('checked' => 'checked'), array());
    }

    function testInvalidCheckedWithPassword() {
        $this->assertResult(array(
            'checked' => 'checked',
            'type' => 'password'
        ), array(
            'type' => 'password'
        ));
    }

    function testValidCheckedWithUcCheckbox() {
        $this->assertResult(array(
            'checked' => 'checked',
            'type' => 'CHECKBOX',
            'value' => 'bar',
        ));
    }

    function testInvalidMaxlength() {
        $this->assertResult(array(
            'maxlength' => '10',
            'type' => 'checkbox',
            'value' => 'foo',
        ), array(
            'type' => 'checkbox',
            'value' => 'foo',
        ));
    }

    function testValidMaxLength() {
        $this->assertResult(array(
            'maxlength' => '10',
        ));
    }

    // these two are really bad test-cases

    function testSizeWithCheckbox() {
        $this->assertResult(array(
            'type' => 'checkbox',
            'value' => 'foo',
            'size' => '100px',
        ), array(
            'type' => 'checkbox',
            'value' => 'foo',
            'size' => '100',
        ));
    }

    function testSizeWithText() {
        $this->assertResult(array(
            'type' => 'password',
            'size' => '100px', // spurious value, to indicate no validation takes place
        ), array(
            'type' => 'password',
            'size' => '100px',
        ));
    }

    function testInvalidSrc() {
        $this->assertResult(array(
            'src' => 'img.png',
        ), array());
    }

    function testMissingValue() {
        $this->assertResult(array(
            'type' => 'checkbox',
        ), array(
            'type' => 'checkbox',
            'value' => '',
        ));
    }

}

// vim: et sw=4 sts=4