Files
roundcubemail/tests/Framework/Html.php
Michael Voříšek 54f4aa33f9 Fix CS - imports (#9316)
* fix Tests\Browser\TestCase imports

* fix remaining imports

* fix PHPUnit\Framework\TestCase imports

* import GuzzleHttp\Client

* fix remaining

* "php_unit_method_casing" is not todo

* fix "single_line_comment_spacing"

* fix 2nd commit done using older fixer
2024-01-21 19:13:31 +01:00

138 lines
3.2 KiB
PHP

<?php
use PHPUnit\Framework\TestCase;
/**
* Test class to test html class
*/
class Framework_Html extends TestCase
{
/**
* Class constructor
*/
public function test_class()
{
$object = new html();
$this->assertInstanceOf('html', $object, 'Class constructor');
}
/**
* Data for test_attrib_string()
*/
public function provide_attrib_string_cases(): iterable
{
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 provide_attrib_string_cases
*/
public function test_attrib_string($arg1, $arg2, $expected)
{
$this->assertSame($expected, html::attrib_string($arg1, $arg2));
}
/**
* Data for test_quote()
*/
public function provide_quote_cases(): iterable
{
return [
['abc', 'abc'],
['?', '?'],
['"', '&quot;'],
['<', '&lt;'],
['>', '&gt;'],
['&', '&amp;'],
['&amp;', '&amp;amp;'],
];
}
/**
* Test for quote()
*
* @dataProvider provide_quote_cases
*/
public function test_quote($str, $expected)
{
$this->assertSame($expected, html::quote($str));
}
/**
* Data for test_parse_attrib_string()
*/
public function provide_parse_attrib_string_cases(): iterable
{
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 provide_parse_attrib_string_cases
*/
public function test_parse_attrib_string($arg1, $expected)
{
$this->assertSame($expected, html::parse_attrib_string($arg1));
}
}