PhpPresentationTest.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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;
  18. use PhpOffice\PhpPresentation\DocumentLayout;
  19. use PhpOffice\PhpPresentation\DocumentProperties;
  20. use PhpOffice\PhpPresentation\PhpPresentation;
  21. use PhpOffice\PhpPresentation\PresentationProperties;
  22. /**
  23. * Test class for PhpPresentation
  24. *
  25. * @coversDefaultClass PhpOffice\PhpPresentation\PhpPresentation
  26. */
  27. class PhpPresentationTest extends \PHPUnit_Framework_TestCase
  28. {
  29. /**
  30. * Test create new instance
  31. */
  32. public function testConstruct()
  33. {
  34. $object = new PhpPresentation();
  35. $slide = $object->getSlide();
  36. $this->assertEquals(new DocumentProperties(), $object->getDocumentProperties());
  37. $this->assertEquals(new DocumentLayout(), $object->getLayout());
  38. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Slide', $object->getSlide());
  39. $this->assertEquals(1, count($object->getAllSlides()));
  40. $this->assertEquals(0, $object->getIndex($slide));
  41. $this->assertEquals(1, $object->getSlideCount());
  42. $this->assertEquals(0, $object->getActiveSlideIndex());
  43. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Slide\\Iterator', $object->getSlideIterator());
  44. }
  45. public function testProperties()
  46. {
  47. $object = new PhpPresentation();
  48. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\DocumentProperties', $object->getProperties());
  49. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\DocumentProperties', $object->getDocumentProperties());
  50. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\PhpPresentation', $object->setProperties(new DocumentProperties()));
  51. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\DocumentProperties', $object->getProperties());
  52. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\DocumentProperties', $object->getDocumentProperties());
  53. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\PhpPresentation', $object->setDocumentProperties(new DocumentProperties()));
  54. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\DocumentProperties', $object->getProperties());
  55. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\DocumentProperties', $object->getDocumentProperties());
  56. }
  57. public function testPresentationProperties()
  58. {
  59. $object = new PhpPresentation();
  60. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\PresentationProperties', $object->getPresentationProperties());
  61. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\PhpPresentation', $object->setPresentationProperties(new PresentationProperties()));
  62. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\PresentationProperties', $object->getPresentationProperties());
  63. }
  64. /**
  65. * Test add external slide
  66. */
  67. public function testAddExternalSlide()
  68. {
  69. $origin = new PhpPresentation();
  70. $slide = $origin->getSlide();
  71. $object = new PhpPresentation();
  72. $object->addExternalSlide($slide);
  73. $this->assertEquals(2, $object->getSlideCount());
  74. }
  75. /**
  76. * Test copy presentation
  77. */
  78. public function testCopy()
  79. {
  80. $object = new PhpPresentation();
  81. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\PhpPresentation', $object->copy());
  82. }
  83. /**
  84. * Test remove slide by index exception
  85. *
  86. * @expectedException Exception
  87. * @expectedExceptionMessage Slide index is out of bounds.
  88. */
  89. public function testRemoveSlideByIndexException()
  90. {
  91. $object = new PhpPresentation();
  92. $object->removeSlideByIndex(1);
  93. }
  94. /**
  95. * Test get slide exception
  96. *
  97. * @expectedException Exception
  98. * @expectedExceptionMessage Slide index is out of bounds.
  99. */
  100. public function testGetSlideException()
  101. {
  102. $object = new PhpPresentation();
  103. $object->getSlide(1);
  104. }
  105. /**
  106. * Test set active slide index exception
  107. *
  108. * @expectedException Exception
  109. * @expectedExceptionMessage Active slide index is out of bounds.
  110. */
  111. public function testSetActiveSlideIndexException()
  112. {
  113. $object = new PhpPresentation();
  114. $object->setActiveSlideIndex(1);
  115. }
  116. /**
  117. * @deprecated
  118. */
  119. public function testMarkAsFinal()
  120. {
  121. $object = new PhpPresentation();
  122. $this->assertFalse($object->isMarkedAsFinal());
  123. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\PresentationProperties', $object->markAsFinal(true));
  124. $this->assertTrue($object->isMarkedAsFinal());
  125. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\PresentationProperties', $object->markAsFinal(false));
  126. $this->assertFalse($object->isMarkedAsFinal());
  127. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\PresentationProperties', $object->markAsFinal());
  128. $this->assertTrue($object->isMarkedAsFinal());
  129. }
  130. /**
  131. * @deprecated
  132. */
  133. public function testZoom()
  134. {
  135. $object = new PhpPresentation();
  136. $this->assertEquals(1, $object->getZoom());
  137. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\PresentationProperties', $object->setZoom(0.3));
  138. $this->assertEquals(0.3, $object->getZoom());
  139. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\PresentationProperties', $object->setZoom());
  140. $this->assertEquals(1, $object->getZoom());
  141. }
  142. }