XEEValidatorTest.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. class XEEValidatorTest extends PHPUnit_Framework_TestCase
  3. {
  4. public function setUp()
  5. {
  6. if (!defined('PHPEXCEL_ROOT')) {
  7. define('PHPEXCEL_ROOT', APPLICATION_PATH . '/');
  8. }
  9. require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
  10. }
  11. /**
  12. * @dataProvider providerInvalidXML
  13. * @expectedException PHPExcel_Reader_Exception
  14. */
  15. public function testInvalidXML($filename)
  16. {
  17. $reader = $this->getMockForAbstractClass('PHPExcel_Reader_Abstract');
  18. $expectedResult = 'FAILURE: Should throw an Exception rather than return a value';
  19. $result = $reader->securityScanFile($filename);
  20. $this->assertEquals($expectedResult, $result);
  21. }
  22. public function providerInvalidXML()
  23. {
  24. $tests = [];
  25. foreach(glob('rawTestData/Reader/XEETestInvalid*.xml') as $file) {
  26. $tests[] = [realpath($file), true];
  27. }
  28. return $tests;
  29. }
  30. /**
  31. * @dataProvider providerValidXML
  32. */
  33. public function testValidXML($filename, $expectedResult)
  34. {
  35. $reader = $this->getMockForAbstractClass('PHPExcel_Reader_Abstract');
  36. $result = $reader->securityScanFile($filename);
  37. $this->assertEquals($expectedResult, $result);
  38. }
  39. public function providerValidXML()
  40. {
  41. $tests = [];
  42. foreach(glob('rawTestData/Reader/XEETestValid*.xml') as $file) {
  43. $tests[] = [realpath($file), file_get_contents($file)];
  44. }
  45. return $tests;
  46. }
  47. }