2016-10-23 19:18:59 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Reader;
|
|
|
|
|
2017-01-22 08:39:23 +00:00
|
|
|
use PhpOffice\PhpSpreadsheet\Reader\Html;
|
2017-11-08 15:48:01 +00:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2016-10-23 19:18:59 +00:00
|
|
|
|
2017-11-08 15:48:01 +00:00
|
|
|
class HtmlTest extends TestCase
|
2016-10-23 19:18:59 +00:00
|
|
|
{
|
|
|
|
public function testCsvWithAngleBracket()
|
|
|
|
{
|
|
|
|
$filename = __DIR__ . '/../../data/Reader/HTML/csv_with_angle_bracket.csv';
|
2017-08-02 21:13:08 +00:00
|
|
|
$reader = new Html();
|
2017-09-20 05:55:42 +00:00
|
|
|
self::assertFalse($reader->canRead($filename));
|
2016-10-23 19:18:59 +00:00
|
|
|
}
|
2017-12-11 02:08:41 +00:00
|
|
|
|
|
|
|
public function providerCanReadVerySmallFile()
|
|
|
|
{
|
|
|
|
$padding = str_repeat('a', 2048);
|
|
|
|
|
|
|
|
return [
|
|
|
|
[true, ' <html> ' . $padding . ' </html> '],
|
|
|
|
[true, ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html>' . $padding . '</html>'],
|
|
|
|
[true, '<html></html>'],
|
|
|
|
[false, ''],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerCanReadVerySmallFile
|
|
|
|
*
|
|
|
|
* @param bool $expected
|
|
|
|
* @param string $content
|
|
|
|
*/
|
|
|
|
public function testCanReadVerySmallFile($expected, $content)
|
|
|
|
{
|
|
|
|
$filename = tempnam(sys_get_temp_dir(), 'html');
|
|
|
|
file_put_contents($filename, $content);
|
|
|
|
|
|
|
|
$reader = new Html();
|
|
|
|
$actual = $reader->canRead($filename);
|
|
|
|
unlink($filename);
|
|
|
|
|
|
|
|
self::assertSame($expected, $actual);
|
|
|
|
}
|
2016-10-23 19:18:59 +00:00
|
|
|
}
|