2015-04-29 21:23:14 +00:00
|
|
|
<?php
|
|
|
|
|
2016-08-31 17:18:12 +00:00
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Reader;
|
2015-04-29 21:23:14 +00:00
|
|
|
|
2016-08-31 17:18:12 +00:00
|
|
|
use PhpOffice\PhpSpreadsheet\Reader\BaseReader;
|
2017-05-17 22:02:17 +00:00
|
|
|
use PHPUnit_Framework_TestCase;
|
2016-08-14 04:08:43 +00:00
|
|
|
|
2017-05-17 22:02:17 +00:00
|
|
|
class XEEValidatorTest extends PHPUnit_Framework_TestCase
|
2015-04-29 21:23:14 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @dataProvider providerInvalidXML
|
2016-08-31 17:18:12 +00:00
|
|
|
* @expectedException \PhpOffice\PhpSpreadsheet\Reader\Exception
|
2016-12-22 14:43:37 +00:00
|
|
|
*
|
|
|
|
* @param mixed $filename
|
2015-04-29 21:23:14 +00:00
|
|
|
*/
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testInvalidXML($filename)
|
|
|
|
{
|
2016-08-14 04:08:43 +00:00
|
|
|
$reader = $this->getMockForAbstractClass(BaseReader::class);
|
2015-04-29 21:23:14 +00:00
|
|
|
$expectedResult = 'FAILURE: Should throw an Exception rather than return a value';
|
2015-05-17 13:00:02 +00:00
|
|
|
$result = $reader->securityScanFile($filename);
|
|
|
|
$this->assertEquals($expectedResult, $result);
|
|
|
|
}
|
2015-04-29 21:23:14 +00:00
|
|
|
|
|
|
|
public function providerInvalidXML()
|
|
|
|
{
|
|
|
|
$tests = [];
|
2016-10-16 21:12:26 +00:00
|
|
|
foreach (glob(__DIR__ . '/../../data/Reader/XEE/XEETestInvalid*.xml') as $file) {
|
2016-10-23 18:16:36 +00:00
|
|
|
$tests[basename($file)] = [realpath($file)];
|
2015-04-29 21:23:14 +00:00
|
|
|
}
|
2016-08-16 15:33:57 +00:00
|
|
|
|
2015-04-29 21:23:14 +00:00
|
|
|
return $tests;
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2015-04-29 21:23:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerValidXML
|
2016-12-22 14:43:37 +00:00
|
|
|
*
|
|
|
|
* @param mixed $filename
|
|
|
|
* @param mixed $expectedResult
|
2015-04-29 21:23:14 +00:00
|
|
|
*/
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testValidXML($filename, $expectedResult)
|
|
|
|
{
|
2016-08-14 04:08:43 +00:00
|
|
|
$reader = $this->getMockForAbstractClass(BaseReader::class);
|
2015-05-17 13:00:02 +00:00
|
|
|
$result = $reader->securityScanFile($filename);
|
|
|
|
$this->assertEquals($expectedResult, $result);
|
|
|
|
}
|
2015-04-29 21:23:14 +00:00
|
|
|
|
|
|
|
public function providerValidXML()
|
|
|
|
{
|
2016-08-16 15:33:57 +00:00
|
|
|
$tests = [];
|
2016-10-16 21:12:26 +00:00
|
|
|
foreach (glob(__DIR__ . '/../../data/Reader/XEE/XEETestValid*.xml') as $file) {
|
2016-10-23 18:16:36 +00:00
|
|
|
$tests[basename($file)] = [realpath($file), file_get_contents($file)];
|
2015-04-29 21:23:14 +00:00
|
|
|
}
|
2016-08-16 15:33:57 +00:00
|
|
|
|
2015-04-29 21:23:14 +00:00
|
|
|
return $tests;
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2015-04-29 21:23:14 +00:00
|
|
|
}
|