1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheetTests; |
4
|
|
|
|
5
|
|
|
use PhpOffice\PhpSpreadsheet\Exception as SpException; |
6
|
|
|
use PhpOffice\PhpSpreadsheet\Settings; |
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
|
9
|
|
|
class SettingsTest extends TestCase |
10
|
|
|
{ |
11
|
|
|
protected function tearDown(): void |
12
|
|
|
{ |
13
|
|
|
Settings::setCache(null); |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
public function testGetXMLSettings(): void |
17
|
|
|
{ |
18
|
|
|
$result = Settings::getLibXmlLoaderOptions(); |
19
|
|
|
self::assertTrue((bool) ((LIBXML_DTDLOAD | LIBXML_DTDATTR) & $result)); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function testSetXMLSettings(): void |
23
|
|
|
{ |
24
|
|
|
$original = Settings::getLibXmlLoaderOptions(); |
25
|
|
|
Settings::setLibXmlLoaderOptions(LIBXML_DTDLOAD | LIBXML_DTDATTR | LIBXML_DTDVALID); |
26
|
|
|
$result = Settings::getLibXmlLoaderOptions(); |
27
|
|
|
self::assertTrue((bool) ((LIBXML_DTDLOAD | LIBXML_DTDATTR | LIBXML_DTDVALID) & $result)); |
28
|
|
|
Settings::setLibXmlLoaderOptions($original); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testInvalidChartRenderer(): void |
32
|
|
|
{ |
33
|
|
|
$this->expectException(SpException::class); |
34
|
|
|
$this->expectExceptionMessage('Chart renderer must implement'); |
35
|
|
|
Settings::setChartRenderer(self::class); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testInvalidRequestFactory(): void |
39
|
|
|
{ |
40
|
|
|
$this->expectException(SpException::class); |
41
|
|
|
$this->expectExceptionMessage('HTTP client must be configured'); |
42
|
|
|
Settings::getRequestFactory(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testCache(): void |
46
|
|
|
{ |
47
|
|
|
$cache1 = Settings::getCache(); |
48
|
|
|
self::assertNotNull($cache1); |
49
|
|
|
Settings::setCache(null); |
50
|
|
|
$cache2 = Settings::getCache(); |
51
|
|
|
self::assertEquals($cache1, $cache2); |
52
|
|
|
self::assertNotSame($cache1, $cache2); |
53
|
|
|
$array = ['A1' => 10, 'B2' => 20]; |
54
|
|
|
$cache2->setMultiple($array); |
55
|
|
|
self::assertSame($array, $cache2->getMultiple(array_keys($array))); |
56
|
|
|
self::assertNull($cache2->get('C3')); |
57
|
|
|
$cache2->clear(); |
58
|
|
|
self::assertNull($cache2->get('A1')); |
59
|
|
|
self::assertNull($cache2->get('B2')); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|