mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-10-09 13:26:33 +00:00
32e59142a3
Fix #647, which went stale in 2019 and is now reopened. Fix #849, which went stale in 2019 and is now reopened. Html Reader currently echoes any warning messages from Dom::loadHtml when it parses Html input. These are generally not needed, and may cause PhpSpreadsheet to fail needlessly. A new property `$suppressLoadWarnings` is added. It will additionally default to `null`, which will avoid any BC breaks. However, the default will be changed to `true` in a future release. Should the caller be interested in any messages which are suppressed when `true` is in effect, these are available through new method `getLibxmlMessages` after the Html has been loaded.
50 lines
1.5 KiB
PHP
50 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Reader\Html;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Reader\Html;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/**
|
|
* Dom loadHtml usually succeeds even with invalid Html,
|
|
* although it will generate warning messages.
|
|
* This member demonstrates a method less intrusive than
|
|
* set_error_handler to detect if there has been a problem.
|
|
*/
|
|
class HtmlLibxmlTest extends TestCase
|
|
{
|
|
public function testLoadInvalidString(): void
|
|
{
|
|
$libxml = libxml_use_internal_errors();
|
|
$html = '<table<>';
|
|
$reader = new Html();
|
|
$reader->setSuppressLoadWarnings(true);
|
|
$reader->loadFromString($html);
|
|
self::assertNotEmpty($reader->getLibxmlMessages());
|
|
self::assertSame($libxml, libxml_use_internal_errors());
|
|
}
|
|
|
|
public function testLoadValidString(): void
|
|
{
|
|
$libxml = libxml_use_internal_errors();
|
|
$html = '<table>';
|
|
$reader = new Html();
|
|
$reader->setSuppressLoadWarnings(true);
|
|
$reader->loadFromString($html);
|
|
self::assertEmpty($reader->getLibxmlMessages());
|
|
self::assertSame($libxml, libxml_use_internal_errors());
|
|
}
|
|
|
|
public function testLoadValidStringNoSuppress(): void
|
|
{
|
|
$libxml = libxml_use_internal_errors();
|
|
$html = '<table>';
|
|
$reader = new Html();
|
|
$reader->loadFromString($html);
|
|
self::assertEmpty($reader->getLibxmlMessages());
|
|
self::assertSame($libxml, libxml_use_internal_errors());
|
|
}
|
|
}
|