PhpSpreadsheet/tests/PhpSpreadsheetTests/Reader/Security/XmlScannerTest.php

58 lines
1.5 KiB
PHP
Raw Normal View History

2018-11-19 21:47:34 +00:00
<?php
namespace PhpOffice\PhpSpreadsheetTests\Reader\Security;
use PHPUnit\Framework\TestCase;
2018-11-19 22:22:59 +00:00
use PhpOffice\PhpSpreadsheet\Reader\Security\XmlScanner;
2018-11-19 21:47:34 +00:00
class XmlScannerTest extends TestCase
{
/**
* @dataProvider providerValidXML
*
* @param mixed $filename
* @param mixed $expectedResult
*/
public function testValidXML($filename, $expectedResult)
{
$reader = new XmlScanner();
$result = $reader->scanFile($filename);
self::assertEquals($expectedResult, $result);
}
public function providerValidXML()
{
$tests = [];
2018-11-19 22:22:59 +00:00
foreach (glob(__DIR__ . '/../../../data/Reader/Xml/XEETestValid*.xml') as $file) {
2018-11-19 21:47:34 +00:00
$tests[basename($file)] = [realpath($file), file_get_contents($file)];
}
return $tests;
}
/**
* @dataProvider providerInvalidXML
*
* @param mixed $filename
*/
public function testInvalidXML($filename)
{
$this->expectException(\PhpOffice\PhpSpreadsheet\Reader\Exception::class);
$reader = new XmlScanner();
$expectedResult = 'FAILURE: Should throw an Exception rather than return a value';
$result = $reader->scanFile($filename);
self::assertEquals($expectedResult, $result);
}
public function providerInvalidXML()
{
$tests = [];
2018-11-19 22:22:59 +00:00
foreach (glob(__DIR__ . '/../../../data/Reader/Xml/XEETestInvalidUTF*.xml') as $file) {
2018-11-19 21:47:34 +00:00
$tests[basename($file)] = [realpath($file)];
}
return $tests;
}
}