1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Reader; |
4
|
|
|
|
5
|
|
|
use PhpOffice\PhpSpreadsheet\Reader\BaseReader; |
6
|
|
|
use PhpOffice\PhpSpreadsheet\Reader\Exception; |
7
|
|
|
use PhpOffice\PhpSpreadsheet\Reader\Xml; |
8
|
|
|
use PHPUnit_Framework_TestCase; |
9
|
|
|
|
10
|
|
|
class XEEValidatorTest extends PHPUnit_Framework_TestCase |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @dataProvider providerInvalidXML |
14
|
|
|
* @expectedException \PhpOffice\PhpSpreadsheet\Reader\Exception |
15
|
|
|
* |
16
|
|
|
* @param mixed $filename |
17
|
|
|
*/ |
18
|
|
|
public function testInvalidXML($filename) |
19
|
|
|
{ |
20
|
|
|
$reader = $this->getMockForAbstractClass(BaseReader::class); |
21
|
|
|
$expectedResult = 'FAILURE: Should throw an Exception rather than return a value'; |
22
|
|
|
$result = $reader->securityScanFile($filename); |
23
|
|
|
$this->assertEquals($expectedResult, $result); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
View Code Duplication |
public function providerInvalidXML() |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
$tests = []; |
29
|
|
|
foreach (glob(__DIR__ . '/../../data/Reader/XEE/XEETestInvalidUTF*.xml') as $file) { |
30
|
|
|
$tests[basename($file)] = [realpath($file)]; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
return $tests; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @dataProvider providerInvalidSimpleXML |
38
|
|
|
* @expectedException \PhpOffice\PhpSpreadsheet\Reader\Exception |
39
|
|
|
* |
40
|
|
|
* @param $filename |
41
|
|
|
*/ |
42
|
|
|
public function testInvalidSimpleXML($filename) |
43
|
|
|
{ |
44
|
|
|
$xmlReader = new Xml(); |
45
|
|
|
$xmlReader->trySimpleXMLLoadString($filename); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
View Code Duplication |
public function providerInvalidSimpleXML() |
|
|
|
|
49
|
|
|
{ |
50
|
|
|
$tests = []; |
51
|
|
|
foreach (glob(__DIR__ . '/../../data/Reader/XEE/XEETestInvalidSimpleXML*.xml') as $file) { |
52
|
|
|
$tests[basename($file)] = [realpath($file)]; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
return $tests; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @dataProvider providerValidXML |
60
|
|
|
* |
61
|
|
|
* @param mixed $filename |
62
|
|
|
* @param mixed $expectedResult |
63
|
|
|
*/ |
64
|
|
|
public function testValidXML($filename, $expectedResult) |
65
|
|
|
{ |
66
|
|
|
$reader = $this->getMockForAbstractClass(BaseReader::class); |
67
|
|
|
$result = $reader->securityScanFile($filename); |
68
|
|
|
$this->assertEquals($expectedResult, $result); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
View Code Duplication |
public function providerValidXML() |
|
|
|
|
72
|
|
|
{ |
73
|
|
|
$tests = []; |
74
|
|
|
foreach (glob(__DIR__ . '/../../data/Reader/XEE/XEETestValid*.xml') as $file) { |
75
|
|
|
$tests[basename($file)] = [realpath($file), file_get_contents($file)]; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return $tests; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.