SerializedTest.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * This file is part of PHPPresentation - A pure PHP library for reading and writing
  4. * presentations documents.
  5. *
  6. * PHPPresentation is free software distributed under the terms of the GNU Lesser
  7. * General Public License version 3 as published by the Free Software Foundation.
  8. *
  9. * For the full copyright and license information, please read the LICENSE
  10. * file that was distributed with this source code. For the full list of
  11. * contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors.
  12. *
  13. * @copyright 2009-2015 PHPPresentation contributors
  14. * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
  15. * @link https://github.com/PHPOffice/PHPPresentation
  16. */
  17. namespace PhpOffice\PhpPresentation\Tests\Reader;
  18. use PhpOffice\PhpPresentation\Reader\Serialized;
  19. /**
  20. * Test class for serialized reader
  21. *
  22. * @coversDefaultClass PhpOffice\PhpPresentation\Reader\Serialized
  23. */
  24. class SerializedTest extends \PHPUnit_Framework_TestCase
  25. {
  26. /**
  27. * Test can read
  28. */
  29. public function testCanRead()
  30. {
  31. $file = PHPPRESENTATION_TESTS_BASE_DIR . '/resources/files/serialized.phppt';
  32. $object = new Serialized();
  33. $this->assertTrue($object->canRead($file));
  34. }
  35. /**
  36. * @expectedException \Exception
  37. * @expectedExceptionMessage Could not open for reading! File does not exist.
  38. */
  39. public function testLoadFileNotExists()
  40. {
  41. $object = new Serialized();
  42. $object->load('');
  43. }
  44. /**
  45. * @expectedException \Exception
  46. * @expectedExceptionMessage Invalid file format for PhpOffice\PhpPresentation\Reader\Serialized:
  47. */
  48. public function testLoadFileBadFormat()
  49. {
  50. $file = PHPPRESENTATION_TESTS_BASE_DIR . '/resources/files/Sample_01_Simple.pptx';
  51. $object = new Serialized();
  52. $object->load($file);
  53. }
  54. /**
  55. * @expectedException \Exception
  56. * @expectedExceptionMessage Could not open for reading! File does not exist.
  57. */
  58. public function testFileSupportsNotExists()
  59. {
  60. $object = new Serialized();
  61. $object->fileSupportsUnserializePhpPresentation('');
  62. }
  63. public function testLoadSerializedFileNotExists()
  64. {
  65. $file = tempnam(sys_get_temp_dir(), 'PhpPresentation_Serialized');
  66. $oArchive = new \ZipArchive();
  67. $oArchive->open($file, \ZipArchive::CREATE);
  68. $oArchive->addFromString('PhpPresentation.xml', '');
  69. $oArchive->close();
  70. $object = new Serialized();
  71. $this->assertNull($object->load($file));
  72. }
  73. }