mirror of
https://github.com/danielstjules/Stringy.git
synced 2025-08-16 02:04:09 +02:00
html encode and decode
This commit is contained in:
@@ -1023,4 +1023,26 @@ abstract class CommonTest extends PHPUnit_Framework_TestCase
|
||||
array('fòô', 'bàř', '[[:alpha:]]{3}', 'fòô', 'msr', 'UTF-8')
|
||||
);
|
||||
}
|
||||
|
||||
public function htmlEncodeProvider()
|
||||
{
|
||||
return array(
|
||||
array('&', '&'),
|
||||
array('"', '"'),
|
||||
array(''', "'", ENT_QUOTES),
|
||||
array('<', '<'),
|
||||
array('>', '>'),
|
||||
);
|
||||
}
|
||||
|
||||
public function htmlDecodeProvider()
|
||||
{
|
||||
return array(
|
||||
array('&', '&'),
|
||||
array('"', '"'),
|
||||
array("'", ''', ENT_QUOTES),
|
||||
array('<', '<'),
|
||||
array('>', '>'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -647,4 +647,24 @@ class StaticStringyTestCase extends CommonTest
|
||||
$this->assertInternalType('string', $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider htmlEncodeProvider()
|
||||
*/
|
||||
public function testHtmlEncode($expected, $str, $flags = ENT_COMPAT, $encoding = null)
|
||||
{
|
||||
$result = S::htmlEncode($str, $flags, $encoding);
|
||||
$this->assertInternalType('string', $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider htmlDecodeProvider()
|
||||
*/
|
||||
public function testHtmlDecode($expected, $str, $flags = ENT_COMPAT, $encoding = null)
|
||||
{
|
||||
$result = S::htmlDecode($str, $flags, $encoding);
|
||||
$this->assertInternalType('string', $result);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
}
|
||||
|
@@ -911,4 +911,28 @@ class StringyTestCase extends CommonTest
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider htmlEncodeProvider()
|
||||
*/
|
||||
public function testHtmlEncode($expected, $str, $flags = ENT_COMPAT, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->htmlEncode($flags);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider htmlDecodeProvider()
|
||||
*/
|
||||
public function testHtmlDecode($expected, $str, $flags = ENT_COMPAT, $encoding = null)
|
||||
{
|
||||
$stringy = S::create($str, $encoding);
|
||||
$result = $stringy->htmlDecode($flags);
|
||||
$this->assertStringy($result);
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals($str, $stringy);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user