Sheet names are stored as attributes of an XML entity. We therefore need a different escaping strategy, escaping quotes.
83 lines
2.3 KiB
PHP
83 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace Box\Spout\Common\Helper\Escaper;
|
|
|
|
use Box\Spout\Common\Helper\Escaper;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/**
|
|
* Class XLSXTest
|
|
*/
|
|
class XLSXTest extends TestCase
|
|
{
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function dataProviderForTestEscape()
|
|
{
|
|
return [
|
|
['test', 'test'],
|
|
['adam\'s "car"', 'adam's "car"'],
|
|
["\n", "\n"],
|
|
["\r", "\r"],
|
|
["\t", "\t"],
|
|
[chr(0), '_x0000_'],
|
|
[chr(4), '_x0004_'],
|
|
['_x0000_', '_x005F_x0000_'],
|
|
[chr(21), '_x0015_'],
|
|
['control ' . chr(21) . ' character', 'control _x0015_ character'],
|
|
['control\'s ' . chr(21) . ' "character"', 'control's _x0015_ "character"'],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @dataProvider dataProviderForTestEscape
|
|
*
|
|
* @param string $stringToEscape
|
|
* @param string $expectedEscapedString
|
|
* @return void
|
|
*/
|
|
public function testEscape($stringToEscape, $expectedEscapedString)
|
|
{
|
|
$escaper = new Escaper\XLSX();
|
|
$escapedString = $escaper->escape($stringToEscape);
|
|
|
|
$this->assertEquals($expectedEscapedString, $escapedString, 'Incorrect escaped string');
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function dataProviderForTestUnescape()
|
|
{
|
|
return [
|
|
['test', 'test'],
|
|
['adam's "car"', 'adam's "car"'],
|
|
["\n", "\n"],
|
|
["\r", "\r"],
|
|
["\t", "\t"],
|
|
['_x0000_', chr(0)],
|
|
['_x0004_', chr(4)],
|
|
['_x005F_x0000_', '_x0000_'],
|
|
['_x0015_', chr(21)],
|
|
['control _x0015_ character', 'control ' . chr(21) . ' character'],
|
|
['control's _x0015_ "character"', 'control's ' . chr(21) . ' "character"'],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @dataProvider dataProviderForTestUnescape
|
|
*
|
|
* @param string $stringToUnescape
|
|
* @param string $expectedUnescapedString
|
|
* @return void
|
|
*/
|
|
public function testUnescape($stringToUnescape, $expectedUnescapedString)
|
|
{
|
|
$escaper = new Escaper\XLSX();
|
|
$unescapedString = $escaper->unescape($stringToUnescape);
|
|
|
|
$this->assertEquals($expectedUnescapedString, $unescapedString, 'Incorrect escaped string');
|
|
}
|
|
}
|