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 134 135 136 137 138 139 140 141
|
<?php
namespace Roundcube\Tests\Framework;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
/**
* Test class to test html class
*/
class Framework_Html extends TestCase
{
/**
* Class constructor
*/
function test_class()
{
$object = new \html();
$this->assertInstanceOf(\html::class, $object, "Class constructor");
}
/**
* Data for test_attrib_string()
*/
static function data_attrib_string()
{
return [
[
[], null, '',
],
[
['test' => 'test'], null, ' test="test"',
],
[
['test' => 'test'], ['test'], ' test="test"',
],
[
['test' => 'test'], ['other'], '',
],
[
['checked' => true], null, ' checked="checked"',
],
[
['checked' => ''], null, '',
],
[
['onclick' => ''], null, '',
],
[
['size' => 5], null, ' size="5"',
],
[
['size' => 'test'], null, '',
],
[
['data-test' => 'test'], null, ' data-test="test"',
],
];
}
/**
* Test for attrib_string()
* @dataProvider data_attrib_string
*/
#[DataProvider('data_attrib_string')]
function test_attrib_string($arg1, $arg2, $expected)
{
$this->assertEquals($expected, \html::attrib_string($arg1, $arg2));
}
/**
* Data for test_quote()
*/
static function data_quote()
{
return [
['abc', 'abc'],
['?', '?'],
['"', '"'],
['<', '<'],
['>', '>'],
['&', '&'],
['&', '&amp;'],
];
}
/**
* Test for quote()
* @dataProvider data_quote
*/
#[DataProvider('data_quote')]
function test_quote($str, $expected)
{
$this->assertEquals($expected, \html::quote($str));
}
/**
* Data for test_parse_attrib_string()
*/
static function data_parse_attrib_string()
{
return [
[
'',
[],
],
[
'test="test1-val"',
['test' => 'test1-val'],
],
[
'test1="test1-val" test2=test2-val',
['test1' => 'test1-val', 'test2' => 'test2-val'],
],
[
' test1="test1\'val" test2=\'test2"val\' ',
['test1' => 'test1\'val', 'test2' => 'test2"val'],
],
[
'expression="test == true ? \' test\' : \'\'" ',
['expression' => 'test == true ? \' test\' : \'\''],
],
[
'href="http://domain.tld/страница"',
['href' => 'http://domain.tld/страница'],
],
];
}
/**
* Test for parse_attrib_string()
* @dataProvider data_parse_attrib_string
*/
#[DataProvider('data_parse_attrib_string')]
function test_parse_attrib_string($arg1, $expected)
{
$this->assertEquals($expected, \html::parse_attrib_string($arg1));
}
}
|