PowerPoint2007Test.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  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\DocumentLayout;
  19. use PhpOffice\PhpPresentation\Reader\PowerPoint2007;
  20. use PhpOffice\PhpPresentation\Style\Alignment;
  21. use PhpOffice\PhpPresentation\Style\Bullet;
  22. /**
  23. * Test class for PowerPoint2007 reader
  24. *
  25. * @coversDefaultClass PhpOffice\PhpPresentation\Reader\PowerPoint2007
  26. */
  27. class PowerPoint2007Test extends \PHPUnit_Framework_TestCase
  28. {
  29. /**
  30. * Test can read
  31. */
  32. public function testCanRead()
  33. {
  34. $object = new PowerPoint2007();
  35. $file = PHPPRESENTATION_TESTS_BASE_DIR . '/resources/files/Sample_00_01.ppt';
  36. $this->assertFalse($object->canRead($file));
  37. $file = PHPPRESENTATION_TESTS_BASE_DIR . '/resources/files/serialized.phppt';
  38. $this->assertFalse($object->canRead($file));
  39. $file = PHPPRESENTATION_TESTS_BASE_DIR . '/resources/files/Sample_12.pptx';
  40. $this->assertTrue($object->canRead($file));
  41. }
  42. /**
  43. * @expectedException \Exception
  44. * @expectedExceptionMessage Could not open for reading! File does not exist.
  45. */
  46. public function testLoadFileNotExists()
  47. {
  48. $object = new PowerPoint2007();
  49. $object->load('');
  50. }
  51. /**
  52. * @expectedException \Exception
  53. * @expectedExceptionMessage Invalid file format for PhpOffice\PhpPresentation\Reader\PowerPoint2007:
  54. */
  55. public function testLoadFileBadFormat()
  56. {
  57. $file = PHPPRESENTATION_TESTS_BASE_DIR . '/resources/files/Sample_00_01.ppt';
  58. $object = new PowerPoint2007();
  59. $object->load($file);
  60. }
  61. /**
  62. * @expectedException \Exception
  63. * @expectedExceptionMessage Could not open for reading! File does not exist.
  64. */
  65. public function testFileSupportsNotExists()
  66. {
  67. $object = new PowerPoint2007();
  68. $object->fileSupportsUnserializePhpPresentation('');
  69. }
  70. public function testLoadFile01()
  71. {
  72. $file = PHPPRESENTATION_TESTS_BASE_DIR . '/resources/files/Sample_12.pptx';
  73. $object = new PowerPoint2007();
  74. $oPhpPresentation = $object->load($file);
  75. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\PhpPresentation', $oPhpPresentation);
  76. // Document Properties
  77. $this->assertEquals('PHPOffice', $oPhpPresentation->getDocumentProperties()->getCreator());
  78. $this->assertEquals('PHPPresentation Team', $oPhpPresentation->getDocumentProperties()->getLastModifiedBy());
  79. $this->assertEquals('Sample 02 Title', $oPhpPresentation->getDocumentProperties()->getTitle());
  80. $this->assertEquals('Sample 02 Subject', $oPhpPresentation->getDocumentProperties()->getSubject());
  81. $this->assertEquals('Sample 02 Description', $oPhpPresentation->getDocumentProperties()->getDescription());
  82. $this->assertEquals('office 2007 openxml libreoffice odt php', $oPhpPresentation->getDocumentProperties()->getKeywords());
  83. $this->assertEquals('Sample Category', $oPhpPresentation->getDocumentProperties()->getCategory());
  84. // Document Layout
  85. $this->assertEquals(DocumentLayout::LAYOUT_SCREEN_4X3, $oPhpPresentation->getLayout()->getDocumentLayout());
  86. $this->assertEquals(254, $oPhpPresentation->getLayout()->getCX(DocumentLayout::UNIT_MILLIMETER));
  87. $this->assertEquals(190.5, $oPhpPresentation->getLayout()->getCY(DocumentLayout::UNIT_MILLIMETER));
  88. // Slides
  89. $this->assertCount(4, $oPhpPresentation->getAllSlides());
  90. // Slide 1
  91. $oSlide1 = $oPhpPresentation->getSlide(0);
  92. $arrayShape = $oSlide1->getShapeCollection();
  93. $this->assertCount(2, $arrayShape);
  94. // Slide 1 : Shape 1
  95. $oShape = $arrayShape[0];
  96. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Drawing\\Gd', $oShape);
  97. $this->assertEquals('PHPPresentation logo', $oShape->getName());
  98. $this->assertEquals('PHPPresentation logo', $oShape->getDescription());
  99. $this->assertEquals(36, $oShape->getHeight());
  100. $this->assertEquals(10, $oShape->getOffsetX());
  101. $this->assertEquals(10, $oShape->getOffsetY());
  102. $this->assertTrue($oShape->getShadow()->isVisible());
  103. $this->assertEquals(45, $oShape->getShadow()->getDirection());
  104. $this->assertEquals(10, $oShape->getShadow()->getDistance());
  105. // Slide 1 : Shape 2
  106. $oShape = $arrayShape[1];
  107. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $oShape);
  108. $this->assertEquals(200, $oShape->getHeight());
  109. $this->assertEquals(600, $oShape->getWidth());
  110. $this->assertEquals(10, $oShape->getOffsetX());
  111. $this->assertEquals(400, $oShape->getOffsetY());
  112. $this->assertEquals(Alignment::HORIZONTAL_LEFT, $oShape->getActiveParagraph()->getAlignment()->getHorizontal());
  113. $arrayParagraphs = $oShape->getParagraphs();
  114. $this->assertCount(1, $arrayParagraphs);
  115. $oParagraph = $arrayParagraphs[0];
  116. $arrayRichText = $oParagraph->getRichTextElements();
  117. $this->assertCount(3, $arrayRichText);
  118. // Slide 1 : Shape 2 : Paragraph 1
  119. $oRichText = $arrayRichText[0];
  120. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\Run', $oRichText);
  121. $this->assertEquals('Introduction to', $oRichText->getText());
  122. $this->assertTrue($oRichText->getFont()->isBold());
  123. $this->assertEquals(28, $oRichText->getFont()->getSize());
  124. $this->assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB());
  125. // Slide 1 : Shape 2 : Paragraph 2
  126. $oRichText = $arrayRichText[1];
  127. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\BreakElement', $oRichText);
  128. // Slide 1 : Shape 2 : Paragraph 3
  129. $oRichText = $arrayRichText[2];
  130. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\Run', $oRichText);
  131. $this->assertEquals('PHPPresentation', $oRichText->getText());
  132. $this->assertTrue($oRichText->getFont()->isBold());
  133. $this->assertEquals(60, $oRichText->getFont()->getSize());
  134. $this->assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB());
  135. // Slide 2
  136. $oSlide2 = $oPhpPresentation->getSlide(1);
  137. $arrayShape = $oSlide2->getShapeCollection();
  138. $this->assertCount(3, $arrayShape);
  139. // Slide 2 : Shape 1
  140. $oShape = $arrayShape[0];
  141. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Drawing\\Gd', $oShape);
  142. $this->assertEquals('PHPPresentation logo', $oShape->getName());
  143. $this->assertEquals('PHPPresentation logo', $oShape->getDescription());
  144. $this->assertEquals(36, $oShape->getHeight());
  145. $this->assertEquals(10, $oShape->getOffsetX());
  146. $this->assertEquals(10, $oShape->getOffsetY());
  147. $this->assertTrue($oShape->getShadow()->isVisible());
  148. $this->assertEquals(45, $oShape->getShadow()->getDirection());
  149. $this->assertEquals(10, $oShape->getShadow()->getDistance());
  150. // Slide 2 : Shape 2
  151. $oShape = $arrayShape[1];
  152. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $oShape);
  153. $this->assertEquals(100, $oShape->getHeight());
  154. $this->assertEquals(930, $oShape->getWidth());
  155. $this->assertEquals(10, $oShape->getOffsetX());
  156. $this->assertEquals(50, $oShape->getOffsetY());
  157. $arrayParagraphs = $oShape->getParagraphs();
  158. $this->assertCount(1, $arrayParagraphs);
  159. $oParagraph = $arrayParagraphs[0];
  160. $this->assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal());
  161. $arrayRichText = $oParagraph->getRichTextElements();
  162. $this->assertCount(1, $arrayRichText);
  163. // Slide 2 : Shape 2 : Paragraph 1
  164. $oRichText = $arrayRichText[0];
  165. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\Run', $oRichText);
  166. $this->assertEquals('What is PHPPresentation?', $oRichText->getText());
  167. $this->assertTrue($oRichText->getFont()->isBold());
  168. $this->assertEquals(48, $oRichText->getFont()->getSize());
  169. $this->assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB());
  170. // Slide 2 : Shape 3
  171. $oShape = $arrayShape[2];
  172. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $oShape);
  173. $this->assertEquals(600, $oShape->getHeight());
  174. $this->assertEquals(930, $oShape->getWidth());
  175. $this->assertEquals(10, $oShape->getOffsetX());
  176. $this->assertEquals(130, $oShape->getOffsetY());
  177. $arrayParagraphs = $oShape->getParagraphs();
  178. $this->assertCount(4, $arrayParagraphs);
  179. // Slide 2 : Shape 3 : Paragraph 1
  180. $oParagraph = $arrayParagraphs[0];
  181. $this->assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal());
  182. $this->assertEquals(25, $oParagraph->getAlignment()->getMarginLeft());
  183. $this->assertEquals(-25, $oParagraph->getAlignment()->getIndent());
  184. $this->assertEquals(Bullet::TYPE_BULLET, $oParagraph->getBulletStyle()->getBulletType());
  185. $arrayRichText = $oParagraph->getRichTextElements();
  186. $this->assertCount(1, $arrayRichText);
  187. $oRichText = $arrayRichText[0];
  188. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\Run', $oRichText);
  189. $this->assertEquals('A class library', $oRichText->getText());
  190. $this->assertEquals(36, $oRichText->getFont()->getSize());
  191. $this->assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB());
  192. // Slide 2 : Shape 3 : Paragraph 2
  193. $oParagraph = $arrayParagraphs[1];
  194. $this->assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal());
  195. $this->assertEquals(25, $oParagraph->getAlignment()->getMarginLeft());
  196. $this->assertEquals(-25, $oParagraph->getAlignment()->getIndent());
  197. $this->assertEquals(Bullet::TYPE_BULLET, $oParagraph->getBulletStyle()->getBulletType());
  198. $arrayRichText = $oParagraph->getRichTextElements();
  199. $this->assertCount(1, $arrayRichText);
  200. $oRichText = $arrayRichText[0];
  201. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\Run', $oRichText);
  202. $this->assertEquals('Written in PHP', $oRichText->getText());
  203. $this->assertEquals(36, $oRichText->getFont()->getSize());
  204. $this->assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB());
  205. // Slide 2 : Shape 3 : Paragraph 3
  206. $oParagraph = $arrayParagraphs[2];
  207. $this->assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal());
  208. $this->assertEquals(25, $oParagraph->getAlignment()->getMarginLeft());
  209. $this->assertEquals(-25, $oParagraph->getAlignment()->getIndent());
  210. $this->assertEquals(Bullet::TYPE_BULLET, $oParagraph->getBulletStyle()->getBulletType());
  211. $arrayRichText = $oParagraph->getRichTextElements();
  212. $this->assertCount(1, $arrayRichText);
  213. $oRichText = $arrayRichText[0];
  214. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\Run', $oRichText);
  215. $this->assertEquals('Representing a presentation', $oRichText->getText());
  216. $this->assertEquals(36, $oRichText->getFont()->getSize());
  217. $this->assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB());
  218. // Slide 2 : Shape 3 : Paragraph 4
  219. $oParagraph = $arrayParagraphs[3];
  220. $this->assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal());
  221. $this->assertEquals(25, $oParagraph->getAlignment()->getMarginLeft());
  222. $this->assertEquals(-25, $oParagraph->getAlignment()->getIndent());
  223. $this->assertEquals(Bullet::TYPE_BULLET, $oParagraph->getBulletStyle()->getBulletType());
  224. $arrayRichText = $oParagraph->getRichTextElements();
  225. $this->assertCount(1, $arrayRichText);
  226. $oRichText = $arrayRichText[0];
  227. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\Run', $oRichText);
  228. $this->assertEquals('Supports writing to different file formats', $oRichText->getText());
  229. $this->assertEquals(36, $oRichText->getFont()->getSize());
  230. $this->assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB());
  231. // Slide 3
  232. $oSlide2 = $oPhpPresentation->getSlide(2);
  233. $arrayShape = $oSlide2->getShapeCollection();
  234. $this->assertCount(3, $arrayShape);
  235. // Slide 3 : Shape 1
  236. $oShape = $arrayShape[0];
  237. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Drawing\\Gd', $oShape);
  238. $this->assertEquals('PHPPresentation logo', $oShape->getName());
  239. $this->assertEquals('PHPPresentation logo', $oShape->getDescription());
  240. $this->assertEquals(36, $oShape->getHeight());
  241. $this->assertEquals(10, $oShape->getOffsetX());
  242. $this->assertEquals(10, $oShape->getOffsetY());
  243. $this->assertTrue($oShape->getShadow()->isVisible());
  244. $this->assertEquals(45, $oShape->getShadow()->getDirection());
  245. $this->assertEquals(10, $oShape->getShadow()->getDistance());
  246. // Slide 3 : Shape 2
  247. $oShape = $arrayShape[1];
  248. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $oShape);
  249. $this->assertEquals(100, $oShape->getHeight());
  250. $this->assertEquals(930, $oShape->getWidth());
  251. $this->assertEquals(10, $oShape->getOffsetX());
  252. $this->assertEquals(50, $oShape->getOffsetY());
  253. $this->assertEquals(Alignment::HORIZONTAL_LEFT, $oShape->getActiveParagraph()->getAlignment()->getHorizontal());
  254. $arrayParagraphs = $oShape->getParagraphs();
  255. $this->assertCount(1, $arrayParagraphs);
  256. $oParagraph = $arrayParagraphs[0];
  257. $arrayRichText = $oParagraph->getRichTextElements();
  258. $this->assertCount(1, $arrayRichText);
  259. // Slide 3 : Shape 2 : Paragraph 1
  260. $oRichText = $arrayRichText[0];
  261. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\Run', $oRichText);
  262. $this->assertEquals('What\'s the point?', $oRichText->getText());
  263. $this->assertTrue($oRichText->getFont()->isBold());
  264. $this->assertEquals(48, $oRichText->getFont()->getSize());
  265. $this->assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB());
  266. // Slide 3 : Shape 2
  267. $oShape = $arrayShape[2];
  268. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $oShape);
  269. $this->assertEquals(600, $oShape->getHeight());
  270. $this->assertEquals(930, $oShape->getWidth());
  271. $this->assertEquals(10, $oShape->getOffsetX());
  272. $this->assertEquals(130, $oShape->getOffsetY());
  273. $arrayParagraphs = $oShape->getParagraphs();
  274. $this->assertCount(8, $arrayParagraphs);
  275. // Slide 3 : Shape 3 : Paragraph 1
  276. $oParagraph = $arrayParagraphs[0];
  277. $this->assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal());
  278. $this->assertEquals(25, $oParagraph->getAlignment()->getMarginLeft());
  279. $this->assertEquals(-25, $oParagraph->getAlignment()->getIndent());
  280. $this->assertEquals(0, $oParagraph->getAlignment()->getLevel());
  281. $this->assertEquals(Bullet::TYPE_BULLET, $oParagraph->getBulletStyle()->getBulletType());
  282. $arrayRichText = $oParagraph->getRichTextElements();
  283. $this->assertCount(1, $arrayRichText);
  284. $oRichText = $arrayRichText[0];
  285. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\Run', $oRichText);
  286. $this->assertEquals('Generate slide decks', $oRichText->getText());
  287. $this->assertEquals(36, $oRichText->getFont()->getSize());
  288. $this->assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB());
  289. // Slide 3 : Shape 3 : Paragraph 2
  290. $oParagraph = $arrayParagraphs[1];
  291. $this->assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal());
  292. $this->assertEquals(75, $oParagraph->getAlignment()->getMarginLeft());
  293. $this->assertEquals(-25, $oParagraph->getAlignment()->getIndent());
  294. $this->assertEquals(1, $oParagraph->getAlignment()->getLevel());
  295. $this->assertEquals(Bullet::TYPE_BULLET, $oParagraph->getBulletStyle()->getBulletType());
  296. $arrayRichText = $oParagraph->getRichTextElements();
  297. $this->assertCount(1, $arrayRichText);
  298. $oRichText = $arrayRichText[0];
  299. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\Run', $oRichText);
  300. $this->assertEquals('Represent business data', $oRichText->getText());
  301. $this->assertEquals(36, $oRichText->getFont()->getSize());
  302. $this->assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB());
  303. // Slide 3 : Shape 3 : Paragraph 3
  304. $oParagraph = $arrayParagraphs[2];
  305. $this->assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal());
  306. $this->assertEquals(75, $oParagraph->getAlignment()->getMarginLeft());
  307. $this->assertEquals(-25, $oParagraph->getAlignment()->getIndent());
  308. $this->assertEquals(1, $oParagraph->getAlignment()->getLevel());
  309. $this->assertEquals(Bullet::TYPE_BULLET, $oParagraph->getBulletStyle()->getBulletType());
  310. $arrayRichText = $oParagraph->getRichTextElements();
  311. $this->assertCount(1, $arrayRichText);
  312. $oRichText = $arrayRichText[0];
  313. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\Run', $oRichText);
  314. $this->assertEquals('Show a family slide show', $oRichText->getText());
  315. $this->assertEquals(36, $oRichText->getFont()->getSize());
  316. $this->assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB());
  317. // Slide 3 : Shape 3 : Paragraph 4
  318. $oParagraph = $arrayParagraphs[3];
  319. $this->assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal());
  320. $this->assertEquals(75, $oParagraph->getAlignment()->getMarginLeft());
  321. $this->assertEquals(-25, $oParagraph->getAlignment()->getIndent());
  322. $this->assertEquals(1, $oParagraph->getAlignment()->getLevel());
  323. $this->assertEquals(Bullet::TYPE_BULLET, $oParagraph->getBulletStyle()->getBulletType());
  324. $arrayRichText = $oParagraph->getRichTextElements();
  325. $this->assertCount(1, $arrayRichText);
  326. $oRichText = $arrayRichText[0];
  327. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\Run', $oRichText);
  328. $this->assertEquals('...', $oRichText->getText());
  329. $this->assertEquals(36, $oRichText->getFont()->getSize());
  330. $this->assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB());
  331. // Slide 3 : Shape 3 : Paragraph 5
  332. $oParagraph = $arrayParagraphs[4];
  333. $this->assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal());
  334. $this->assertEquals(25, $oParagraph->getAlignment()->getMarginLeft());
  335. $this->assertEquals(-25, $oParagraph->getAlignment()->getIndent());
  336. $this->assertEquals(0, $oParagraph->getAlignment()->getLevel());
  337. $this->assertEquals(Bullet::TYPE_BULLET, $oParagraph->getBulletStyle()->getBulletType());
  338. $arrayRichText = $oParagraph->getRichTextElements();
  339. $this->assertCount(1, $arrayRichText);
  340. $oRichText = $arrayRichText[0];
  341. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\Run', $oRichText);
  342. $this->assertEquals('Export these to different formats', $oRichText->getText());
  343. $this->assertEquals(36, $oRichText->getFont()->getSize());
  344. $this->assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB());
  345. // Slide 3 : Shape 3 : Paragraph 6
  346. $oParagraph = $arrayParagraphs[5];
  347. $this->assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal());
  348. $this->assertEquals(75, $oParagraph->getAlignment()->getMarginLeft());
  349. $this->assertEquals(-25, $oParagraph->getAlignment()->getIndent());
  350. $this->assertEquals(1, $oParagraph->getAlignment()->getLevel());
  351. $this->assertEquals(Bullet::TYPE_BULLET, $oParagraph->getBulletStyle()->getBulletType());
  352. $arrayRichText = $oParagraph->getRichTextElements();
  353. $this->assertCount(1, $arrayRichText);
  354. $oRichText = $arrayRichText[0];
  355. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\Run', $oRichText);
  356. $this->assertEquals('PHPPresentation 2007', $oRichText->getText());
  357. $this->assertEquals(36, $oRichText->getFont()->getSize());
  358. $this->assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB());
  359. // Slide 3 : Shape 3 : Paragraph 7
  360. $oParagraph = $arrayParagraphs[6];
  361. $this->assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal());
  362. $this->assertEquals(75, $oParagraph->getAlignment()->getMarginLeft());
  363. $this->assertEquals(-25, $oParagraph->getAlignment()->getIndent());
  364. $this->assertEquals(1, $oParagraph->getAlignment()->getLevel());
  365. $this->assertEquals(Bullet::TYPE_BULLET, $oParagraph->getBulletStyle()->getBulletType());
  366. $arrayRichText = $oParagraph->getRichTextElements();
  367. $this->assertCount(1, $arrayRichText);
  368. $oRichText = $arrayRichText[0];
  369. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\Run', $oRichText);
  370. $this->assertEquals('Serialized', $oRichText->getText());
  371. $this->assertEquals(36, $oRichText->getFont()->getSize());
  372. $this->assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB());
  373. // Slide 3 : Shape 3 : Paragraph 8
  374. $oParagraph = $arrayParagraphs[7];
  375. $this->assertEquals(Alignment::HORIZONTAL_LEFT, $oParagraph->getAlignment()->getHorizontal());
  376. $this->assertEquals(75, $oParagraph->getAlignment()->getMarginLeft());
  377. $this->assertEquals(-25, $oParagraph->getAlignment()->getIndent());
  378. $this->assertEquals(1, $oParagraph->getAlignment()->getLevel());
  379. $this->assertEquals(Bullet::TYPE_BULLET, $oParagraph->getBulletStyle()->getBulletType());
  380. $arrayRichText = $oParagraph->getRichTextElements();
  381. $this->assertCount(1, $arrayRichText);
  382. $oRichText = $arrayRichText[0];
  383. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\Run', $oRichText);
  384. $this->assertEquals('... (more to come) ...', $oRichText->getText());
  385. $this->assertEquals(36, $oRichText->getFont()->getSize());
  386. $this->assertEquals('FF000000', $oRichText->getFont()->getColor()->getARGB());
  387. // Slide 4
  388. $oSlide3 = $oPhpPresentation->getSlide(3);
  389. $arrayShape = $oSlide3->getShapeCollection();
  390. $this->assertCount(3, $arrayShape);
  391. // Slide 4 : Shape 1
  392. $oShape = $arrayShape[0];
  393. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Drawing\\Gd', $oShape);
  394. $this->assertEquals('PHPPresentation logo', $oShape->getName());
  395. $this->assertEquals('PHPPresentation logo', $oShape->getDescription());
  396. $this->assertEquals(36, $oShape->getHeight());
  397. $this->assertEquals(10, $oShape->getOffsetX());
  398. $this->assertEquals(10, $oShape->getOffsetY());
  399. $this->assertTrue($oShape->getShadow()->isVisible());
  400. $this->assertEquals(45, $oShape->getShadow()->getDirection());
  401. $this->assertEquals(10, $oShape->getShadow()->getDistance());
  402. // Slide 4 : Shape 2
  403. $oShape = $arrayShape[1];
  404. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $oShape);
  405. $this->assertEquals(100, $oShape->getHeight());
  406. $this->assertEquals(930, $oShape->getWidth());
  407. $this->assertEquals(10, $oShape->getOffsetX());
  408. $this->assertEquals(50, $oShape->getOffsetY());
  409. $this->assertEquals(Alignment::HORIZONTAL_LEFT, $oShape->getActiveParagraph()->getAlignment()->getHorizontal());
  410. $arrayParagraphs = $oShape->getParagraphs();
  411. $this->assertCount(1, $arrayParagraphs);
  412. $oParagraph = $arrayParagraphs[0];
  413. $arrayRichText = $oParagraph->getRichTextElements();
  414. $this->assertCount(1, $arrayRichText);
  415. // Slide 4 : Shape 2 : Paragraph 1
  416. $oRichText = $arrayRichText[0];
  417. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\Run', $oRichText);
  418. $this->assertEquals('Need more info?', $oRichText->getText());
  419. $this->assertTrue($oRichText->getFont()->isBold());
  420. $this->assertEquals(48, $oRichText->getFont()->getSize());
  421. $this->assertEquals('FF000000', $oShape->getActiveParagraph()->getFont()->getColor()->getARGB());
  422. // Slide 4 : Shape 3
  423. $oShape = $arrayShape[2];
  424. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $oShape);
  425. $this->assertEquals(600, $oShape->getHeight());
  426. $this->assertEquals(930, $oShape->getWidth());
  427. $this->assertEquals(10, $oShape->getOffsetX());
  428. $this->assertEquals(130, $oShape->getOffsetY());
  429. $this->assertEquals(Alignment::HORIZONTAL_LEFT, $oShape->getActiveParagraph()->getAlignment()->getHorizontal());
  430. $arrayParagraphs = $oShape->getParagraphs();
  431. $this->assertCount(1, $arrayParagraphs);
  432. $oParagraph = $arrayParagraphs[0];
  433. $arrayRichText = $oParagraph->getRichTextElements();
  434. $this->assertCount(3, $arrayRichText);
  435. // Slide 4 : Shape 3 : Paragraph 1
  436. $oRichText = $arrayRichText[0];
  437. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\Run', $oRichText);
  438. $this->assertEquals('Check the project site on GitHub:', $oRichText->getText());
  439. $this->assertFalse($oRichText->getFont()->isBold());
  440. $this->assertEquals(36, $oRichText->getFont()->getSize());
  441. $this->assertEquals('FF000000', $oShape->getActiveParagraph()->getFont()->getColor()->getARGB());
  442. // Slide 4 : Shape 3 : Paragraph 2
  443. $oRichText = $arrayRichText[1];
  444. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\BreakElement', $oRichText);
  445. // Slide 4 : Shape 3 : Paragraph 3
  446. $oRichText = $arrayRichText[2];
  447. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText\\Run', $oRichText);
  448. $this->assertEquals('https://github.com/PHPOffice/PHPPresentation/', $oRichText->getText());
  449. $this->assertFalse($oRichText->getFont()->isBold());
  450. $this->assertEquals(32, $oRichText->getFont()->getSize());
  451. $this->assertEquals('FF000000', $oShape->getActiveParagraph()->getFont()->getColor()->getARGB());
  452. $this->assertTrue($oRichText->hasHyperlink());
  453. $this->assertEquals('https://github.com/PHPOffice/PHPPresentation/', $oRichText->getHyperlink()->getUrl());
  454. $this->assertEquals('PHPPresentation', $oRichText->getHyperlink()->getTooltip());
  455. }
  456. public function testMarkAsFinal()
  457. {
  458. $file = PHPPRESENTATION_TESTS_BASE_DIR . '/resources/files/Sample_12.pptx';
  459. $object = new PowerPoint2007();
  460. $oPhpPresentation = $object->load($file);
  461. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\PhpPresentation', $oPhpPresentation);
  462. $this->assertFalse($oPhpPresentation->getPresentationProperties()->isMarkedAsFinal());
  463. $file = PHPPRESENTATION_TESTS_BASE_DIR . '/resources/files/PPTX_MarkAsFinal.pptx';
  464. $object = new PowerPoint2007();
  465. $oPhpPresentation = $object->load($file);
  466. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\PhpPresentation', $oPhpPresentation);
  467. $this->assertTrue($oPhpPresentation->getPresentationProperties()->isMarkedAsFinal());
  468. }
  469. public function testZoom()
  470. {
  471. $file = PHPPRESENTATION_TESTS_BASE_DIR . '/resources/files/Sample_12.pptx';
  472. $object = new PowerPoint2007();
  473. $oPhpPresentation = $object->load($file);
  474. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\PhpPresentation', $oPhpPresentation);
  475. $this->assertEquals(1, $oPhpPresentation->getPresentationProperties()->getZoom());
  476. $file = PHPPRESENTATION_TESTS_BASE_DIR . '/resources/files/PPTX_Zoom.pptx';
  477. $object = new PowerPoint2007();
  478. $oPhpPresentation = $object->load($file);
  479. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\PhpPresentation', $oPhpPresentation);
  480. $this->assertEquals(2.68, $oPhpPresentation->getPresentationProperties()->getZoom());
  481. }
  482. public function testSlideLayout()
  483. {
  484. $file = PHPPRESENTATION_TESTS_BASE_DIR . '/resources/files/Issue_00150.pptx';
  485. $object = new PowerPoint2007();
  486. $oPhpPresentation = $object->load($file);
  487. $this->assertInstanceOf('PhpOffice\\PhpPresentation\\PhpPresentation', $oPhpPresentation);
  488. $masterSlides = $oPhpPresentation->getAllMasterSlides();
  489. $this->assertCount(3, $masterSlides);
  490. $this->assertCount(11, $masterSlides[0]->getAllSlideLayouts());
  491. $this->assertCount(11, $masterSlides[1]->getAllSlideLayouts());
  492. $this->assertCount(11, $masterSlides[2]->getAllSlideLayouts());
  493. }
  494. }