PowerPoint2007Test.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. namespace PhpOffice\PhpPresentation\Tests\Writer;
  3. use PhpOffice\PhpPresentation\Tests\PhpPresentationTestCase;
  4. use PhpOffice\PhpPresentation\Writer\PowerPoint2007;
  5. /**
  6. * Test class for PowerPoint2007
  7. *
  8. * @coversDefaultClass PowerPoint2007
  9. */
  10. class PowerPoint2007Test extends PhpPresentationTestCase
  11. {
  12. protected $writerName = 'PowerPoint2007';
  13. /**
  14. * Test create new instance
  15. */
  16. public function testConstruct()
  17. {
  18. $objectPrefix = 'PhpOffice\\PhpPresentation\\Writer\\PowerPoint2007\\';
  19. $object = new PowerPoint2007($this->oPresentation);
  20. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\PhpPresentation', $object->getPhpPresentation());
  21. $this->assertEquals('./', $object->getDiskCachingDirectory());
  22. $this->assertInstanceOf("{$objectPrefix}LayoutPack\\PackDefault", $object->getLayoutPack());
  23. }
  24. /**
  25. * Test save
  26. */
  27. public function testSave()
  28. {
  29. $filename = tempnam(sys_get_temp_dir(), 'PhpPresentation');
  30. $object = new PowerPoint2007($this->oPresentation);
  31. $object->save($filename);
  32. $this->assertTrue(file_exists($filename));
  33. unlink($filename);
  34. }
  35. /**
  36. * Test save with empty filename
  37. *
  38. * @expectedException \Exception
  39. * @expectedExceptionMessage Filename is empty
  40. */
  41. public function testSaveEmptyException()
  42. {
  43. $object = new PowerPoint2007($this->oPresentation);
  44. $object->save('');
  45. }
  46. /**
  47. * Test save with empty assignation
  48. *
  49. * @expectedException \Exception
  50. * @expectedExceptionMessage No PhpPresentation assigned.
  51. */
  52. public function testSaveUnassignedException()
  53. {
  54. $object = new PowerPoint2007();
  55. $object->save('filename.pptx');
  56. }
  57. /**
  58. * Test get PhpPresentation exception
  59. *
  60. * @expectedException \Exception
  61. * @expectedExceptionMessage No PhpPresentation assigned.
  62. */
  63. public function testGetPhpPresentationException()
  64. {
  65. $object = new PowerPoint2007();
  66. $object->getPhpPresentation();
  67. }
  68. /**
  69. * Test disk caching
  70. */
  71. public function testDiskCaching()
  72. {
  73. $object = new PowerPoint2007($this->oPresentation);
  74. $this->assertFalse($object->hasDiskCaching());
  75. $object->setUseDiskCaching(true);
  76. $this->assertTrue($object->hasDiskCaching());
  77. $this->assertEquals('./', $object->getDiskCachingDirectory());
  78. $object->setUseDiskCaching(true, sys_get_temp_dir());
  79. $this->assertTrue($object->hasDiskCaching());
  80. $this->assertEquals(sys_get_temp_dir(), $object->getDiskCachingDirectory());
  81. }
  82. /**
  83. * Test set/get disk caching exception
  84. *
  85. * @expectedException \Exception
  86. * @expectedExceptionMessage Directory does not exist: foo
  87. */
  88. public function testCachingException()
  89. {
  90. $object = new PowerPoint2007($this->oPresentation);
  91. $object->setUseDiskCaching(true, 'foo');
  92. }
  93. /**
  94. * Test LayoutPack
  95. * @deprecated 0.7
  96. */
  97. public function testLayoutPack()
  98. {
  99. $oLayoutPack = $this->getMockBuilder('PhpOffice\\PhpPresentation\\Writer\\PowerPoint2007\\LayoutPack\\AbstractLayoutPack')->getMock();
  100. $object = new PowerPoint2007();
  101. $this->assertInstanceOf("PhpOffice\\PhpPresentation\\Writer\\PowerPoint2007\\LayoutPack\\AbstractLayoutPack", $object->getLayoutPack());
  102. $this->assertInstanceOf("PhpOffice\\PhpPresentation\\Writer\\PowerPoint2007", $object->setLayoutPack());
  103. $this->assertNull($object->getLayoutPack());
  104. $this->assertInstanceOf("PhpOffice\\PhpPresentation\\Writer\\PowerPoint2007", $object->setLayoutPack($oLayoutPack));
  105. $this->assertInstanceOf("PhpOffice\\PhpPresentation\\Writer\\PowerPoint2007\\LayoutPack\\AbstractLayoutPack", $object->getLayoutPack());
  106. }
  107. public function testZoom()
  108. {
  109. $this->assertZipXmlElementExists('ppt/viewProps.xml', '/p:viewPr/p:slideViewPr/p:cSldViewPr/p:cViewPr/p:scale/a:sx');
  110. $this->assertZipXmlAttributeEquals('ppt/viewProps.xml', '/p:viewPr/p:slideViewPr/p:cSldViewPr/p:cViewPr/p:scale/a:sx', 'n', 100);
  111. $this->assertZipXmlAttributeEquals('ppt/viewProps.xml', '/p:viewPr/p:slideViewPr/p:cSldViewPr/p:cViewPr/p:scale/a:sx', 'd', 100);
  112. $this->assertZipXmlElementExists('ppt/viewProps.xml', '/p:viewPr/p:slideViewPr/p:cSldViewPr/p:cViewPr/p:scale/a:sy');
  113. $this->assertZipXmlAttributeEquals('ppt/viewProps.xml', '/p:viewPr/p:slideViewPr/p:cSldViewPr/p:cViewPr/p:scale/a:sy', 'n', 100);
  114. $this->assertZipXmlAttributeEquals('ppt/viewProps.xml', '/p:viewPr/p:slideViewPr/p:cSldViewPr/p:cViewPr/p:scale/a:sy', 'd', 100);
  115. $value = rand(1, 100);
  116. $this->oPresentation->getPresentationProperties()->setZoom($value);
  117. $this->resetPresentationFile();
  118. $this->assertZipXmlElementExists('ppt/viewProps.xml', '/p:viewPr/p:slideViewPr/p:cSldViewPr/p:cViewPr/p:scale/a:sx');
  119. $this->assertZipXmlAttributeEquals('ppt/viewProps.xml', '/p:viewPr/p:slideViewPr/p:cSldViewPr/p:cViewPr/p:scale/a:sx', 'n', $value * 100);
  120. $this->assertZipXmlAttributeEquals('ppt/viewProps.xml', '/p:viewPr/p:slideViewPr/p:cSldViewPr/p:cViewPr/p:scale/a:sx', 'd', 100);
  121. $this->assertZipXmlElementExists('ppt/viewProps.xml', '/p:viewPr/p:slideViewPr/p:cSldViewPr/p:cViewPr/p:scale/a:sy');
  122. $this->assertZipXmlAttributeEquals('ppt/viewProps.xml', '/p:viewPr/p:slideViewPr/p:cSldViewPr/p:cViewPr/p:scale/a:sy', 'n', $value * 100);
  123. $this->assertZipXmlAttributeEquals('ppt/viewProps.xml', '/p:viewPr/p:slideViewPr/p:cSldViewPr/p:cViewPr/p:scale/a:sy', 'd', 100);
  124. }
  125. public function testFeatureThumbnail()
  126. {
  127. $imagePath = PHPPRESENTATION_TESTS_BASE_DIR.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'PhpPresentationLogo.png';
  128. $xPathManifest = '/Relationships/Relationship[@Target=\'docProps/thumbnail.jpeg\'][@Type=\'http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail\']';
  129. $this->assertZipFileExists('_rels/.rels');
  130. $this->assertZipXmlElementNotExists('_rels/.rels', $xPathManifest);
  131. $this->oPresentation->getPresentationProperties()->setThumbnailPath($imagePath);
  132. $this->resetPresentationFile();
  133. $this->assertZipFileExists('_rels/.rels');
  134. $this->assertZipXmlElementExists('_rels/.rels', $xPathManifest);
  135. }
  136. }