ODPresentationTest.php 29 KB

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