SettingsTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests;
  3. use PhpOffice\PhpSpreadsheet\Settings;
  4. use PHPUnit\Framework\TestCase;
  5. class SettingsTest extends TestCase
  6. {
  7. /**
  8. * @var bool
  9. */
  10. private $prevValue;
  11. protected function setUp(): void
  12. {
  13. // php 8.+ deprecated libxml_disable_entity_loader() - It's on by default
  14. if (\PHP_VERSION_ID < 80000) {
  15. $this->prevValue = libxml_disable_entity_loader();
  16. libxml_disable_entity_loader(false); // Enable entity loader
  17. }
  18. }
  19. protected function tearDown(): void
  20. {
  21. // php 8.+ deprecated libxml_disable_entity_loader() - It's on by default
  22. if (\PHP_VERSION_ID < 80000) {
  23. libxml_disable_entity_loader($this->prevValue);
  24. }
  25. }
  26. public function testGetXMLSettings(): void
  27. {
  28. $result = Settings::getLibXmlLoaderOptions();
  29. self::assertTrue((bool) ((LIBXML_DTDLOAD | LIBXML_DTDATTR) & $result));
  30. // php 8.+ deprecated libxml_disable_entity_loader() - It's on by default
  31. if (\PHP_VERSION_ID < 80000) {
  32. self::assertFalse(libxml_disable_entity_loader());
  33. }
  34. }
  35. public function testSetXMLSettings(): void
  36. {
  37. $original = Settings::getLibXmlLoaderOptions();
  38. Settings::setLibXmlLoaderOptions(LIBXML_DTDLOAD | LIBXML_DTDATTR | LIBXML_DTDVALID);
  39. $result = Settings::getLibXmlLoaderOptions();
  40. self::assertTrue((bool) ((LIBXML_DTDLOAD | LIBXML_DTDATTR | LIBXML_DTDVALID) & $result));
  41. // php 8.+ deprecated libxml_disable_entity_loader() - It's on by default
  42. if (\PHP_VERSION_ID < 80000) {
  43. self::assertFalse(libxml_disable_entity_loader());
  44. }
  45. Settings::setLibXmlLoaderOptions($original);
  46. }
  47. }