PowerPoint97Test.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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\PowerPoint97;
  19. /**
  20. * Test class for PowerPoint97 reader
  21. *
  22. * @coversDefaultClass PhpOffice\PhpPresentation\Reader\PowerPoint97
  23. */
  24. class PowerPoint97Test extends \PHPUnit_Framework_TestCase
  25. {
  26. /**
  27. * Test can read
  28. */
  29. public function testCanRead()
  30. {
  31. $file = PHPPRESENTATION_TESTS_BASE_DIR . '/resources/files/Sample_00_01.ppt';
  32. $object = new PowerPoint97();
  33. $this->assertTrue($object->canRead($file));
  34. }
  35. /**
  36. * Test cant read
  37. */
  38. public function testCantRead()
  39. {
  40. $file = PHPPRESENTATION_TESTS_BASE_DIR . '/resources/files/serialized.phppt';
  41. $object = new PowerPoint97();
  42. $this->assertFalse($object->canRead($file));
  43. }
  44. /**
  45. * @expectedException \Exception
  46. * @expectedExceptionMessage Could not open for reading! File does not exist.
  47. */
  48. public function testLoadFileNotExists()
  49. {
  50. $object = new PowerPoint97();
  51. $object->load('');
  52. }
  53. /**
  54. * @expectedException \Exception
  55. * @expectedExceptionMessage Invalid file format for PhpOffice\PhpPresentation\Reader\PowerPoint97:
  56. */
  57. public function testLoadFileBadFormat()
  58. {
  59. $file = PHPPRESENTATION_TESTS_BASE_DIR . '/resources/files/Sample_01_Simple.pptx';
  60. $object = new PowerPoint97();
  61. $object->load($file);
  62. }
  63. /**
  64. * @expectedException \Exception
  65. * @expectedExceptionMessage Could not open for reading! File does not exist.
  66. */
  67. public function testFileSupportsNotExists()
  68. {
  69. $object = new PowerPoint97();
  70. $object->fileSupportsUnserializePhpPresentation('');
  71. }
  72. public function testLoadFile01()
  73. {
  74. $file = PHPPRESENTATION_TESTS_BASE_DIR . '/resources/files/Sample_00_01.ppt';
  75. $object = new PowerPoint97();
  76. $oPhpPresentation = $object->load($file);
  77. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\PhpPresentation', $oPhpPresentation);
  78. $this->assertEquals(1, $oPhpPresentation->getSlideCount());
  79. $oSlide = $oPhpPresentation->getSlide(0);
  80. $this->assertCount(2, $oSlide->getShapeCollection());
  81. }
  82. public function testLoadFile02()
  83. {
  84. $file = PHPPRESENTATION_TESTS_BASE_DIR . '/resources/files/Sample_00_02.ppt';
  85. $object = new PowerPoint97();
  86. $oPhpPresentation = $object->load($file);
  87. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\PhpPresentation', $oPhpPresentation);
  88. $this->assertEquals(4, $oPhpPresentation->getSlideCount());
  89. $oSlide = $oPhpPresentation->getSlide(0);
  90. $this->assertCount(2, $oSlide->getShapeCollection());
  91. $oSlide = $oPhpPresentation->getSlide(1);
  92. $this->assertCount(3, $oSlide->getShapeCollection());
  93. $oSlide = $oPhpPresentation->getSlide(2);
  94. $this->assertCount(3, $oSlide->getShapeCollection());
  95. $oSlide = $oPhpPresentation->getSlide(3);
  96. $this->assertCount(3, $oSlide->getShapeCollection());
  97. }
  98. public function testLoadFile03()
  99. {
  100. $file = PHPPRESENTATION_TESTS_BASE_DIR . '/resources/files/Sample_00_03.ppt';
  101. $object = new PowerPoint97();
  102. $oPhpPresentation = $object->load($file);
  103. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\PhpPresentation', $oPhpPresentation);
  104. $this->assertEquals(1, $oPhpPresentation->getSlideCount());
  105. $oSlide = $oPhpPresentation->getSlide(0);
  106. $this->assertCount(1, $oSlide->getShapeCollection());
  107. }
  108. public function testLoadFile04()
  109. {
  110. $file = PHPPRESENTATION_TESTS_BASE_DIR . '/resources/files/Sample_00_04.ppt';
  111. $object = new PowerPoint97();
  112. $oPhpPresentation = $object->load($file);
  113. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\PhpPresentation', $oPhpPresentation);
  114. $this->assertEquals(1, $oPhpPresentation->getSlideCount());
  115. $oSlide = $oPhpPresentation->getSlide(0);
  116. $this->assertCount(4, $oSlide->getShapeCollection());
  117. }
  118. }