PptSlide 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992
  1. <?php
  2. namespace PhpPresentation\Tests\Writer\PowerPoint2007;
  3. use PhpOffice\Common\Drawing;
  4. use PhpOffice\PhpPresentation\Shape\Comment;
  5. use PhpOffice\PhpPresentation\Shape\Group;
  6. use PhpOffice\PhpPresentation\Shape\Media;
  7. use PhpOffice\PhpPresentation\Shape\RichText;
  8. use PhpOffice\PhpPresentation\Style\Alignment;
  9. use PhpOffice\PhpPresentation\Style\Bullet;
  10. use PhpOffice\PhpPresentation\Style\Color;
  11. use PhpOffice\PhpPresentation\Style\Fill;
  12. use PhpOffice\PhpPresentation\Slide\Animation;
  13. use PhpOffice\PhpPresentation\Slide\Transition;
  14. use PhpOffice\PhpPresentation\Style\Border;
  15. use PhpOffice\PhpPresentation\Tests\PhpPresentationTestCase;
  16. use PhpOffice\PhpPresentation\Writer\PowerPoint2007;
  17. /**
  18. * Test class for PowerPoint2007
  19. *
  20. * @coversDefaultClass PowerPoint2007
  21. */
  22. class PptSlideTest extends PhpPresentationTestCase
  23. {
  24. protected $writerName = 'PowerPoint2007';
  25. /**
  26. * @link https://github.com/PHPOffice/PHPPresentation/issues/42
  27. */
  28. public function testAlignmentShapeAuto()
  29. {
  30. $oSlide = $this->oPresentation->getActiveSlide();
  31. $oShape = $oSlide->createRichTextShape()->setWidth(400)->setHeight(400)->setOffsetX(100)->setOffsetY(100);
  32. $oShape->createTextRun('this text should be vertically aligned');
  33. $oShape->getActiveParagraph()->getAlignment()->setVertical(Alignment::VERTICAL_AUTO);
  34. $element = '/p:sld/p:cSld/p:spTree/p:sp/p:txBody/a:bodyPr';
  35. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  36. $this->assertZipXmlAttributeNotExists('ppt/slides/slide1.xml', $element, 'anchor');
  37. }
  38. /**
  39. * @link https://github.com/PHPOffice/PHPPresentation/issues/42
  40. */
  41. public function testAlignmentShapeBase()
  42. {
  43. $oSlide = $this->oPresentation->getActiveSlide();
  44. $oShape = $oSlide->createRichTextShape()->setWidth(400)->setHeight(400)->setOffsetX(100)->setOffsetY(100);
  45. $oShape->createTextRun('this text should be vertically aligned');
  46. $oShape->getActiveParagraph()->getAlignment()->setVertical(Alignment::VERTICAL_BASE);
  47. $element = '/p:sld/p:cSld/p:spTree/p:sp/p:txBody/a:bodyPr';
  48. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  49. $this->assertZipXmlAttributeNotExists('ppt/slides/slide1.xml', $element, 'anchor');
  50. }
  51. /**
  52. * @link https://github.com/PHPOffice/PHPPresentation/issues/35
  53. */
  54. public function testAlignmentShapeBottom()
  55. {
  56. $oSlide = $this->oPresentation->getActiveSlide();
  57. $oShape = $oSlide->createRichTextShape()->setWidth(400)->setHeight(400)->setOffsetX(100)->setOffsetY(100);
  58. $oShape->createTextRun('this text should be vertically aligned');
  59. $oShape->getActiveParagraph()->getAlignment()->setVertical(Alignment::VERTICAL_BOTTOM);
  60. $element = '/p:sld/p:cSld/p:spTree/p:sp/p:txBody/a:bodyPr';
  61. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  62. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'anchor', Alignment::VERTICAL_BOTTOM);
  63. }
  64. /**
  65. * @link https://github.com/PHPOffice/PHPPresentation/issues/35
  66. */
  67. public function testAlignmentShapeCenter()
  68. {
  69. $oSlide = $this->oPresentation->getActiveSlide();
  70. $oShape = $oSlide->createRichTextShape()->setWidth(400)->setHeight(400)->setOffsetX(100)->setOffsetY(100);
  71. $oShape->createTextRun('this text should be vertically aligned');
  72. $oShape->getActiveParagraph()->getAlignment()->setVertical(Alignment::VERTICAL_CENTER);
  73. $element = '/p:sld/p:cSld/p:spTree/p:sp/p:txBody/a:bodyPr';
  74. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  75. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'anchor', Alignment::VERTICAL_CENTER);
  76. }
  77. /**
  78. * @link https://github.com/PHPOffice/PHPPresentation/issues/35
  79. */
  80. public function testAlignmentShapeTop()
  81. {
  82. $oSlide = $this->oPresentation->getActiveSlide();
  83. $oShape = $oSlide->createRichTextShape()->setWidth(400)->setHeight(400)->setOffsetX(100)->setOffsetY(100);
  84. $oShape->createTextRun('this text should be vertically aligned');
  85. $oShape->getActiveParagraph()->getAlignment()->setVertical(Alignment::VERTICAL_TOP);
  86. $element = '/p:sld/p:cSld/p:spTree/p:sp/p:txBody/a:bodyPr';
  87. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  88. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'anchor', Alignment::VERTICAL_TOP);
  89. }
  90. public function testAnimation()
  91. {
  92. $oSlide = $this->oPresentation->getActiveSlide();
  93. $oShape1 = $oSlide->createRichTextShape();
  94. $oShape2 = $oSlide->createRichTextShape();
  95. $oAnimation = new Animation();
  96. $oAnimation->addShape($oShape1);
  97. $oAnimation->addShape($oShape2);
  98. $oSlide->addAnimation($oAnimation);
  99. $element = '/p:sld/p:timing';
  100. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  101. $element = '/p:sld/p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par';
  102. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  103. $element = '/p:sld/p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par/p:cTn/p:childTnLst/p:par/p:cTn/p:childTnLst/p:par';
  104. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  105. }
  106. public function testCommentRelationship()
  107. {
  108. $oSlide = $this->oPresentation->getActiveSlide();
  109. $oSlide->addShape(new Comment());
  110. $element = '/Relationships/Relationship[@Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments"]';
  111. $this->assertZipXmlElementExists('ppt/slides/_rels/slide1.xml.rels', $element);
  112. }
  113. public function testCommentInGroupRelationship()
  114. {
  115. $oSlide = $this->oPresentation->getActiveSlide();
  116. $oGroup = new Group();
  117. $oGroup->addShape(new Comment());
  118. $oSlide->addShape($oGroup);
  119. $element = '/Relationships/Relationship[@Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments"]';
  120. $this->assertZipXmlElementExists('ppt/slides/_rels/slide1.xml.rels', $element);
  121. }
  122. public function testDrawingWithHyperlink()
  123. {
  124. $oSlide = $this->oPresentation->getActiveSlide();
  125. $oShape = $oSlide->createDrawingShape();
  126. $oShape->setPath(PHPPRESENTATION_TESTS_BASE_DIR . '/resources/images/PhpPresentationLogo.png');
  127. $oShape->getHyperlink()->setUrl('https://github.com/PHPOffice/PHPPresentation/');
  128. $element = '/p:sld/p:cSld/p:spTree/p:pic/p:nvPicPr/p:cNvPr/a:hlinkClick';
  129. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  130. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'r:id', 'rId3');
  131. }
  132. public function testDrawingShapeBorder()
  133. {
  134. $oSlide = $this->oPresentation->getActiveSlide();
  135. $oShape = $oSlide->createDrawingShape();
  136. $oShape->setPath(PHPPRESENTATION_TESTS_BASE_DIR . '/resources/images/PhpPresentationLogo.png');
  137. $oShape->getBorder()->setLineStyle(Border::LINE_DOUBLE);
  138. $element = '/p:sld/p:cSld/p:spTree/p:pic/p:spPr/a:ln';
  139. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  140. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'cmpd', Border::LINE_DOUBLE);
  141. }
  142. public function testDrawingShapeShadow()
  143. {
  144. $oSlide = $this->oPresentation->getActiveSlide();
  145. $oShape = $oSlide->createDrawingShape();
  146. $oShape->setPath(PHPPRESENTATION_TESTS_BASE_DIR . '/resources/images/PhpPresentationLogo.png');
  147. $oShape->getShadow()->setVisible(true)->setDirection(45)->setDistance(10);
  148. $element = '/p:sld/p:cSld/p:spTree/p:pic/p:spPr/a:effectLst/a:outerShdw';
  149. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  150. }
  151. public function testFillGradientLinearTable()
  152. {
  153. $expected1 = 'E06B20';
  154. $expected2 = strrev($expected1);
  155. $oSlide = $this->oPresentation->getActiveSlide();
  156. $oShape = $oSlide->createTableShape(1);
  157. $oShape->setHeight(200)->setWidth(600)->setOffsetX(150)->setOffsetY(300);
  158. $oRow = $oShape->createRow();
  159. $oCell = $oRow->getCell();
  160. $oCell->createTextRun('R1C1');
  161. $oFill = $oCell->getFill();
  162. $oFill->setFillType(Fill::FILL_GRADIENT_LINEAR)->setStartColor(new Color('FF' . $expected1))->setEndColor(new Color('FF' . $expected2));
  163. $element = '/p:sld/p:cSld/p:spTree/p:graphicFrame/a:graphic/a:graphicData/a:tbl/a:tr/a:tc/a:tcPr/a:gradFill/a:gsLst/a:gs[@pos="0%"]/a:srgbClr';
  164. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  165. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'val', $expected1);
  166. $element = '/p:sld/p:cSld/p:spTree/p:graphicFrame/a:graphic/a:graphicData/a:tbl/a:tr/a:tc/a:tcPr/a:gradFill/a:gsLst/a:gs[@pos="100%"]/a:srgbClr';
  167. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  168. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'val', $expected2);
  169. }
  170. /**
  171. * @link : https://github.com/PHPOffice/PHPPresentation/issues/61
  172. */
  173. public function testFillGradientLinearRichText()
  174. {
  175. $expected1 = 'E06B20';
  176. $expected2 = strrev($expected1);
  177. $oSlide = $this->oPresentation->getActiveSlide();
  178. $oShape = $oSlide->createRichTextShape();
  179. $oShape->setHeight(200)->setWidth(600)->setOffsetX(150)->setOffsetY(300);
  180. $oFill = $oShape->getFill();
  181. $oFill->setFillType(Fill::FILL_GRADIENT_LINEAR)->setStartColor(new Color('FF' . $expected1))->setEndColor(new Color('FF' . $expected2));
  182. $element = '/p:sld/p:cSld/p:spTree/p:sp/p:spPr/a:gradFill/a:gsLst/a:gs[@pos="0%"]/a:srgbClr';
  183. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  184. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'val', $expected1);
  185. $element = '/p:sld/p:cSld/p:spTree/p:sp/p:spPr/a:gradFill/a:gsLst/a:gs[@pos="100%"]/a:srgbClr';
  186. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  187. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'val', $expected2);
  188. }
  189. public function testFillGradientPathTable()
  190. {
  191. $expected1 = 'E06B20';
  192. $expected2 = strrev($expected1);
  193. $oSlide = $this->oPresentation->getActiveSlide();
  194. $oShape = $oSlide->createTableShape(1);
  195. $oShape->setHeight(200)->setWidth(600)->setOffsetX(150)->setOffsetY(300);
  196. $oRow = $oShape->createRow();
  197. $oCell = $oRow->getCell();
  198. $oCell->createTextRun('R1C1');
  199. $oFill = $oCell->getFill();
  200. $oFill->setFillType(Fill::FILL_GRADIENT_PATH)->setStartColor(new Color('FF' . $expected1))->setEndColor(new Color('FF' . $expected2));
  201. $element = '/p:sld/p:cSld/p:spTree/p:graphicFrame/a:graphic/a:graphicData/a:tbl/a:tr/a:tc/a:tcPr/a:gradFill/a:gsLst/a:gs[@pos="0%"]/a:srgbClr';
  202. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  203. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'val', $expected1);
  204. $element = '/p:sld/p:cSld/p:spTree/p:graphicFrame/a:graphic/a:graphicData/a:tbl/a:tr/a:tc/a:tcPr/a:gradFill/a:gsLst/a:gs[@pos="100%"]/a:srgbClr';
  205. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  206. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'val', $expected2);
  207. }
  208. /**
  209. * @link : https://github.com/PHPOffice/PHPPresentation/issues/61
  210. */
  211. public function testFillGradientPathText()
  212. {
  213. $expected1 = 'E06B20';
  214. $expected2 = strrev($expected1);
  215. $oSlide = $this->oPresentation->getActiveSlide();
  216. $oShape = $oSlide->createRichTextShape();
  217. $oShape->setHeight(200)->setWidth(600)->setOffsetX(150)->setOffsetY(300);
  218. $oFill = $oShape->getFill();
  219. $oFill->setFillType(Fill::FILL_GRADIENT_PATH)->setStartColor(new Color('FF' . $expected1))->setEndColor(new Color('FF' . $expected2));
  220. $element = '/p:sld/p:cSld/p:spTree/p:sp/p:spPr/a:gradFill/a:gsLst/a:gs[@pos="0%"]/a:srgbClr';
  221. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  222. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'val', $expected1);
  223. $element = '/p:sld/p:cSld/p:spTree/p:sp/p:spPr/a:gradFill/a:gsLst/a:gs[@pos="100%"]/a:srgbClr';
  224. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  225. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'val', $expected2);
  226. }
  227. public function testFillPatternTable()
  228. {
  229. $expected1 = 'E06B20';
  230. $expected2 = strrev($expected1);
  231. $oSlide = $this->oPresentation->getActiveSlide();
  232. $oShape = $oSlide->createTableShape(1);
  233. $oShape->setHeight(200)->setWidth(600)->setOffsetX(150)->setOffsetY(300);
  234. $oRow = $oShape->createRow();
  235. $oCell = $oRow->getCell();
  236. $oCell->createTextRun('R1C1');
  237. $oFill = $oCell->getFill();
  238. $oFill->setFillType(Fill::FILL_PATTERN_LIGHTTRELLIS)->setStartColor(new Color('FF' . $expected1))->setEndColor(new Color('FF' . $expected2));
  239. $element = '/p:sld/p:cSld/p:spTree/p:graphicFrame/a:graphic/a:graphicData/a:tbl/a:tr/a:tc/a:tcPr/a:pattFill/a:fgClr/a:srgbClr';
  240. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  241. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'val', $expected1);
  242. $element = '/p:sld/p:cSld/p:spTree/p:graphicFrame/a:graphic/a:graphicData/a:tbl/a:tr/a:tc/a:tcPr/a:pattFill/a:bgClr/a:srgbClr';
  243. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  244. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'val', $expected2);
  245. }
  246. public function testFillSolidTable()
  247. {
  248. $expected = 'E06B20';
  249. $oSlide = $this->oPresentation->getActiveSlide();
  250. $oShape = $oSlide->createTableShape(1);
  251. $oShape->setHeight(200)->setWidth(600)->setOffsetX(150)->setOffsetY(300);
  252. $oRow = $oShape->createRow();
  253. $oCell = $oRow->getCell();
  254. $oCell->createTextRun('R1C1');
  255. $oFill = $oCell->getFill();
  256. $oFill->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF' . $expected));
  257. $element = '/p:sld/p:cSld/p:spTree/p:graphicFrame/a:graphic/a:graphicData/a:tbl/a:tr/a:tc/a:tcPr/a:solidFill/a:srgbClr';
  258. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  259. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'val', $expected);
  260. }
  261. /**
  262. * @link : https://github.com/PHPOffice/PHPPresentation/issues/61
  263. */
  264. public function testFillSolidText()
  265. {
  266. $expected = 'E06B20';
  267. $oSlide = $this->oPresentation->getActiveSlide();
  268. $oShape = $oSlide->createRichTextShape();
  269. $oShape->setHeight(200)->setWidth(600)->setOffsetX(150)->setOffsetY(300);
  270. $oFill = $oShape->getFill();
  271. $oFill->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF' . $expected));
  272. $element = '/p:sld/p:cSld/p:spTree/p:sp/p:spPr/a:solidFill/a:srgbClr';
  273. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  274. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'val', $expected);
  275. }
  276. public function testHyperlink()
  277. {
  278. $oSlide = $this->oPresentation->getActiveSlide();
  279. $oRichText = $oSlide->createRichTextShape();
  280. $oRun = $oRichText->createTextRun('Delta');
  281. $oRun->getHyperlink()->setUrl('http://www.google.fr');
  282. $element = '/p:sld/p:cSld/p:spTree/p:sp/p:txBody/a:p/a:r/a:rPr/a:hlinkClick';
  283. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  284. }
  285. public function testHyperlinkInternal()
  286. {
  287. $oSlide = $this->oPresentation->getActiveSlide();
  288. $oRichText = $oSlide->createRichTextShape();
  289. $oRun = $oRichText->createTextRun('Delta');
  290. $oRun->getHyperlink()->setSlideNumber(1);
  291. $element = '/p:sld/p:cSld/p:spTree/p:sp/p:txBody/a:p/a:r/a:rPr/a:hlinkClick';
  292. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  293. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'action', 'ppaction://hlinksldjump');
  294. }
  295. public function testListBullet()
  296. {
  297. $oSlide = $this->oPresentation->getActiveSlide();
  298. $oRichText = $oSlide->createRichTextShape();
  299. $oRichText->getActiveParagraph()->getBulletStyle()->setBulletType(Bullet::TYPE_BULLET);
  300. $oRichText->getActiveParagraph()->getBulletStyle()->setBulletColor(new Color('76543210'));
  301. $oExpectedFont = $oRichText->getActiveParagraph()->getBulletStyle()->getBulletFont();
  302. $oExpectedChar = $oRichText->getActiveParagraph()->getBulletStyle()->getBulletChar();
  303. $oExpectedColor = $oRichText->getActiveParagraph()->getBulletStyle()->getBulletColor()->getRGB();
  304. $oExpectedAlpha = $oRichText->getActiveParagraph()->getBulletStyle()->getBulletColor()->getAlpha() . "%";
  305. $oRichText->createTextRun('Alpha');
  306. $oRichText->createParagraph()->createTextRun('Beta');
  307. $oRichText->createParagraph()->createTextRun('Delta');
  308. $oRichText->createParagraph()->createTextRun('Epsilon');
  309. $element = '/p:sld/p:cSld/p:spTree/p:sp/p:txBody/a:p/a:pPr';
  310. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/a:buFont');
  311. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element . '/a:buFont', 'typeface', $oExpectedFont);
  312. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/a:buChar');
  313. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element . '/a:buChar', 'char', $oExpectedChar);
  314. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/a:buClr');
  315. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/a:buClr/a:srgbClr');
  316. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element . '/a:buClr/a:srgbClr', 'val', $oExpectedColor);
  317. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/a:buClr/a:srgbClr/a:alpha');
  318. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element . '/a:buClr/a:srgbClr/a:alpha', 'val', $oExpectedAlpha);
  319. }
  320. public function testListNumeric()
  321. {
  322. $oSlide = $this->oPresentation->getActiveSlide();
  323. $oRichText = $oSlide->createRichTextShape();
  324. $oRichText->getActiveParagraph()->getBulletStyle()->setBulletType(Bullet::TYPE_NUMERIC);
  325. $oRichText->getActiveParagraph()->getBulletStyle()->setBulletNumericStyle(Bullet::NUMERIC_EA1CHSPERIOD);
  326. $oRichText->getActiveParagraph()->getBulletStyle()->setBulletNumericStartAt(5);
  327. $oExpectedFont = $oRichText->getActiveParagraph()->getBulletStyle()->getBulletFont();
  328. $oExpectedChar = $oRichText->getActiveParagraph()->getBulletStyle()->getBulletNumericStyle();
  329. $oExpectedStart = $oRichText->getActiveParagraph()->getBulletStyle()->getBulletNumericStartAt();
  330. $oRichText->createTextRun('Alpha');
  331. $oRichText->createParagraph()->createTextRun('Beta');
  332. $oRichText->createParagraph()->createTextRun('Delta');
  333. $oRichText->createParagraph()->createTextRun('Epsilon');
  334. $element = '/p:sld/p:cSld/p:spTree/p:sp/p:txBody/a:p/a:pPr';
  335. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/a:buFont');
  336. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element . '/a:buFont', 'typeface', $oExpectedFont);
  337. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/a:buAutoNum');
  338. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element . '/a:buAutoNum', 'type', $oExpectedChar);
  339. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element . '/a:buAutoNum', 'startAt', $oExpectedStart);
  340. }
  341. public function testLine()
  342. {
  343. $valEmu10 = Drawing::pixelsToEmu(10);
  344. $valEmu90 = Drawing::pixelsToEmu(90);
  345. $oSlide = $this->oPresentation->getActiveSlide();
  346. $oSlide->createLineShape(10, 10, 100, 100);
  347. $oSlide->createLineShape(100, 10, 10, 100);
  348. $oSlide->createLineShape(10, 100, 100, 10);
  349. $oSlide->createLineShape(100, 100, 10, 10);
  350. $element = '/p:sld/p:cSld/p:spTree/p:cxnSp/p:spPr/a:prstGeom';
  351. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  352. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'prst', 'line');
  353. $element = '/p:sld/p:cSld/p:spTree/p:cxnSp/p:spPr/a:xfrm/a:ext[@cx="' . $valEmu90 . '"][@cy="' . $valEmu90 . '"]';
  354. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  355. $element = '/p:sld/p:cSld/p:spTree/p:cxnSp/p:spPr/a:xfrm/a:off[@x="' . $valEmu10 . '"][@y="' . $valEmu10 . '"]';
  356. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  357. $element = '/p:sld/p:cSld/p:spTree/p:cxnSp/p:spPr/a:xfrm[@flipV="1"]/a:off[@x="' . $valEmu10 . '"][@y="' . $valEmu10 . '"]';
  358. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  359. }
  360. public function testMedia()
  361. {
  362. $expectedName = 'MyName';
  363. $expectedWidth = rand(1, 100);
  364. $expectedHeight = rand(1, 100);
  365. $expectedX = rand(1, 100);
  366. $expectedY = rand(1, 100);
  367. $oMedia = new Media();
  368. $oMedia->setPath(PHPPRESENTATION_TESTS_BASE_DIR . '/resources/videos/sintel_trailer-480p.ogv')
  369. ->setName($expectedName)
  370. ->setResizeProportional(false)
  371. ->setHeight($expectedHeight)
  372. ->setWidth($expectedWidth)
  373. ->setOffsetX($expectedX)
  374. ->setOffsetY($expectedY);
  375. $oSlide = $this->oPresentation->getActiveSlide();
  376. $oSlide->addShape($oMedia);
  377. $element = '/p:sld/p:cSld/p:spTree/p:pic/p:nvPicPr/p:cNvPr';
  378. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  379. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'name', $expectedName);
  380. $element = '/p:sld/p:cSld/p:spTree/p:pic/p:nvPicPr/p:nvPr/a:videoFile';
  381. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  382. $element = '/p:sld/p:cSld/p:spTree/p:pic/p:nvPicPr/p:nvPr/p:extLst/p:ext';
  383. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  384. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'uri', '{DAA4B4D4-6D71-4841-9C94-3DE7FCFB9230}');
  385. }
  386. public function testNote()
  387. {
  388. $oLayout = $this->oPresentation->getLayout();
  389. $oSlide = $this->oPresentation->getActiveSlide();
  390. $oNote = $oSlide->getNote();
  391. $oRichText = $oNote->createRichTextShape()
  392. ->setHeight($oLayout->getCY($oLayout::UNIT_PIXEL))
  393. ->setWidth($oLayout->getCX($oLayout::UNIT_PIXEL))
  394. ->setOffsetX(170)
  395. ->setOffsetY(180);
  396. $oRichText->createTextRun('testNote');
  397. // Content Types
  398. // $element = '/Types/Override[@PartName="/ppt/notesSlides/notesSlide1.xml"][@ContentType="application/vnd.openxmlformats-officedocument.presentationml.notesSlide+xml"]';
  399. // $this->assertTrue($pres->elementExists($element, '[Content_Types].xml'));
  400. // Rels
  401. // $element = '/Relationships/Relationship[@Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesSlide"][@Target="../notesSlides/notesSlide1.xml"]';
  402. // $this->assertTrue($pres->elementExists($element, 'ppt/slides/_rels/slide1.xml.rels'));
  403. // Slide
  404. $element = '/p:notes';
  405. $this->assertZipXmlElementExists('ppt/notesSlides/notesSlide1.xml', $element);
  406. // Slide Image Placeholder 1
  407. $element = '/p:notes/p:cSld/p:spTree/p:sp/p:nvSpPr/p:cNvPr[@id="2"][@name="Slide Image Placeholder 1"]';
  408. $this->assertZipXmlElementExists('ppt/notesSlides/notesSlide1.xml', $element);
  409. $element = '/p:notes/p:cSld/p:spTree/p:sp[1]/p:spPr/a:xfrm/a:off';
  410. $this->assertZipXmlAttributeEquals('ppt/notesSlides/notesSlide1.xml', $element, 'x', 0);
  411. $this->assertZipXmlAttributeEquals('ppt/notesSlides/notesSlide1.xml', $element, 'y', 0);
  412. $element = '/p:notes/p:cSld/p:spTree/p:sp[1]/p:spPr/a:xfrm/a:ext';
  413. $this->assertZipXmlAttributeEquals('ppt/notesSlides/notesSlide1.xml', $element, 'cx', Drawing::pixelsToEmu(round($oNote->getExtentX() / 2)));
  414. $this->assertZipXmlAttributeEquals('ppt/notesSlides/notesSlide1.xml', $element, 'cy', Drawing::pixelsToEmu(round($oNote->getExtentY() / 2)));
  415. // Notes Placeholder
  416. $element = '/p:notes/p:cSld/p:spTree/p:sp/p:nvSpPr/p:cNvPr[@id="3"][@name="Notes Placeholder"]';
  417. $this->assertZipXmlElementExists('ppt/notesSlides/notesSlide1.xml', $element);
  418. // Notes
  419. $element = '/p:notes/p:cSld/p:spTree/p:sp[2]/p:spPr/a:xfrm/a:off';
  420. $this->assertZipXmlAttributeEquals('ppt/notesSlides/notesSlide1.xml', $element, 'x', Drawing::pixelsToEmu($oNote->getOffsetX()));
  421. $this->assertZipXmlAttributeEquals('ppt/notesSlides/notesSlide1.xml', $element, 'y', Drawing::pixelsToEmu(round($oNote->getExtentY() / 2) + $oNote->getOffsetY()));
  422. $element = '/p:notes/p:cSld/p:spTree/p:sp[2]/p:spPr/a:xfrm/a:ext';
  423. $this->assertZipXmlAttributeEquals('ppt/notesSlides/notesSlide1.xml', $element, 'cx', 5486400);
  424. $this->assertZipXmlAttributeEquals('ppt/notesSlides/notesSlide1.xml', $element, 'cy', 3600450);
  425. $element = '/p:notes/p:cSld/p:spTree/p:sp/p:txBody/a:p/a:r/a:t';
  426. $this->assertZipXmlElementExists('ppt/notesSlides/notesSlide1.xml', $element);
  427. }
  428. public function testRichTextAutoFitNormal()
  429. {
  430. $oSlide = $this->oPresentation->getActiveSlide();
  431. $oRichText = $oSlide->createRichTextShape();
  432. $oRichText->setAutoFit(RichText::AUTOFIT_NORMAL, 47.5, 20);
  433. $oRichText->createTextRun('This is my text for the test.');
  434. $element = '/p:sld/p:cSld/p:spTree/p:sp/p:txBody/a:bodyPr/a:normAutofit';
  435. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  436. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'fontScale', 47500);
  437. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'lnSpcReduction', 20000);
  438. }
  439. public function testRichTextBreak()
  440. {
  441. $oSlide = $this->oPresentation->getActiveSlide();
  442. $oRichText = $oSlide->createRichTextShape();
  443. $oRichText->createBreak();
  444. $element = '/p:sld/p:cSld/p:spTree/p:sp/p:txBody/a:p/a:br';
  445. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  446. }
  447. public function testRichTextHyperlink()
  448. {
  449. $oSlide = $this->oPresentation->getActiveSlide();
  450. $oRichText = $oSlide->createRichTextShape();
  451. $oRichText->getHyperLink()->setUrl('http://www.google.fr');
  452. $element = '/p:sld/p:cSld/p:spTree/p:sp//a:hlinkClick';
  453. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  454. }
  455. public function testRichTextLineSpacing()
  456. {
  457. $expectedLineSpacing = rand(1, 100);
  458. $oSlide = $this->oPresentation->getActiveSlide();
  459. $oRichText = $oSlide->createRichTextShape();
  460. $oRichText->createTextRun('AAA');
  461. $oRichText->getActiveParagraph()->setLineSpacing($expectedLineSpacing);
  462. $element = '/p:sld/p:cSld/p:spTree/p:sp/p:txBody/a:p/a:pPr/a:lnSpc/a:spcPct';
  463. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  464. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'val', $expectedLineSpacing . '%');
  465. }
  466. public function testRichTextRunLanguage()
  467. {
  468. $oSlide = $this->oPresentation->getActiveSlide();
  469. $oRichText = $oSlide->createRichTextShape();
  470. $oRun = $oRichText->createTextRun('MyText');
  471. $expectedElement = '/p:sld/p:cSld/p:spTree/p:sp/p:txBody/a:p/a:r/a:rPr';
  472. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $expectedElement);
  473. $this->assertZipXmlAttributeExists('ppt/slides/slide1.xml', $expectedElement, 'lang');
  474. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $expectedElement, 'lang', 'en-US');
  475. $oRun->setLanguage('de_DE');
  476. $this->resetPresentationFile();
  477. $expectedElement = '/p:sld/p:cSld/p:spTree/p:sp/p:txBody/a:p/a:r/a:rPr';
  478. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $expectedElement);
  479. $this->assertZipXmlAttributeExists('ppt/slides/slide1.xml', $expectedElement, 'lang');
  480. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $expectedElement, 'lang', 'de_DE');
  481. }
  482. public function testRichTextShadow()
  483. {
  484. $oSlide = $this->oPresentation->getActiveSlide();
  485. $oRichText = $oSlide->createRichTextShape();
  486. $oRichText->createTextRun('AAA');
  487. $oRichText->getShadow()->setVisible(true)->setAlpha(75)->setBlurRadius(2)->setDirection(45);
  488. $element = '/p:sld/p:cSld/p:spTree/p:sp/p:spPr/a:effectLst/a:outerShdw';
  489. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  490. }
  491. public function testRichTextUpright()
  492. {
  493. $oSlide = $this->oPresentation->getActiveSlide();
  494. $oRichText = $oSlide->createRichTextShape();
  495. $oRichText->createTextRun('AAA');
  496. $oRichText->setUpright(true);
  497. $element = '/p:sld/p:cSld/p:spTree/p:sp/p:txBody/a:bodyPr';
  498. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  499. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'upright', '1');
  500. }
  501. public function testRichTextVertical()
  502. {
  503. $oSlide = $this->oPresentation->getActiveSlide();
  504. $oRichText = $oSlide->createRichTextShape();
  505. $oRichText->createTextRun('AAA');
  506. $oRichText->setVertical(true);
  507. $element = '/p:sld/p:cSld/p:spTree/p:sp/p:txBody/a:bodyPr';
  508. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  509. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'vert', 'vert');
  510. }
  511. public function testSlideLayoutExists()
  512. {
  513. $this->assertZipFileExists('ppt/slideLayouts/slideLayout1.xml');
  514. }
  515. public function testStyleCharacterSpacing()
  516. {
  517. $element = '/p:sld/p:cSld/p:spTree/p:sp/p:txBody/a:p/a:r/a:rPr';
  518. $oSlide = $this->oPresentation->getActiveSlide();
  519. $oRichText = $oSlide->createRichTextShape();
  520. $oRun = $oRichText->createTextRun('pText');
  521. // Default : $oRun->getFont()->setCharacterSpacing(0);
  522. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  523. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'spc', '0');
  524. $oRun->getFont()->setCharacterSpacing(42);
  525. $this->resetPresentationFile();
  526. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  527. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'spc', '4200');
  528. }
  529. public function testStyleSubScript()
  530. {
  531. $oSlide = $this->oPresentation->getActiveSlide();
  532. $oRichText = $oSlide->createRichTextShape();
  533. $oRun = $oRichText->createTextRun('pText');
  534. $oRun->getFont()->setSubScript(true);
  535. $element = '/p:sld/p:cSld/p:spTree/p:sp/p:txBody/a:p/a:r/a:rPr';
  536. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  537. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'baseline', '-25000');
  538. }
  539. public function testStyleSuperScript()
  540. {
  541. $oSlide = $this->oPresentation->getActiveSlide();
  542. $oRichText = $oSlide->createRichTextShape();
  543. $oRun = $oRichText->createTextRun('pText');
  544. $oRun->getFont()->setSuperScript(true);
  545. $element = '/p:sld/p:cSld/p:spTree/p:sp/p:txBody/a:p/a:r/a:rPr';
  546. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  547. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'baseline', '30000');
  548. }
  549. public function testTableWithAlignment()
  550. {
  551. $oSlide = $this->oPresentation->getActiveSlide();
  552. $oShape = $oSlide->createTableShape(4);
  553. $oShape->setHeight(200)->setWidth(600)->setOffsetX(150)->setOffsetY(300);
  554. $oRow = $oShape->createRow();
  555. $oCell = $oRow->getCell();
  556. $oCell->createTextRun('AAA');
  557. $element = '/p:sld/p:cSld/p:spTree/p:graphicFrame/a:graphic/a:graphicData/a:tbl/a:tr/a:tc/a:tcPr';
  558. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  559. $this->assertZipXmlAttributeNotExists('ppt/slides/slide1.xml', $element, 'anchor');
  560. $this->assertZipXmlAttributeNotExists('ppt/slides/slide1.xml', $element, 'vert');
  561. $oCell->getActiveParagraph()->getAlignment()->setVertical(Alignment::VERTICAL_BOTTOM);
  562. $oCell->getActiveParagraph()->getAlignment()->setTextDirection(Alignment::TEXT_DIRECTION_STACKED);
  563. $this->resetPresentationFile();
  564. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  565. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'anchor', Alignment::VERTICAL_BOTTOM);
  566. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'vert', Alignment::TEXT_DIRECTION_STACKED);
  567. }
  568. public function testTableWithBorder()
  569. {
  570. $oSlide = $this->oPresentation->getActiveSlide();
  571. $oShape = $oSlide->createTableShape(4);
  572. $oShape->setHeight(200)->setWidth(600)->setOffsetX(150)->setOffsetY(300);
  573. $oRow = $oShape->createRow();
  574. $oCell = $oRow->getCell(1);
  575. $oCell->createTextRun('AAA');
  576. $oCell->getBorders()->getBottom()->setDashStyle(Border::DASH_DASH);
  577. $oCell->getBorders()->getBottom()->setLineStyle(Border::LINE_DOUBLE);
  578. $oCell->getBorders()->getTop()->setDashStyle(Border::DASH_DASHDOT);
  579. $oCell->getBorders()->getTop()->setLineStyle(Border::LINE_SINGLE);
  580. $oCell->getBorders()->getRight()->setDashStyle(Border::DASH_DOT);
  581. $oCell->getBorders()->getRight()->setLineStyle(Border::LINE_THICKTHIN);
  582. $oCell->getBorders()->getLeft()->setDashStyle(Border::DASH_LARGEDASH);
  583. $oCell->getBorders()->getLeft()->setLineStyle(Border::LINE_THINTHICK);
  584. $oCell = $oRow->nextCell();
  585. $oCell->createTextRun('BBB');
  586. $oCell->getBorders()->getRight()->setDashStyle(Border::DASH_LARGEDASHDOT);
  587. $oCell->getBorders()->getRight()->setLineStyle(Border::LINE_TRI);
  588. $oRow = $oShape->createRow();
  589. $oCell = $oRow->getCell(1);
  590. $oCell->createTextRun('CCC');
  591. $oCell->getBorders()->getBottom()->setDashStyle(Border::DASH_LARGEDASHDOTDOT);
  592. $oCell->getBorders()->getBottom()->setLineStyle(Border::LINE_NONE);
  593. $element = '/p:sld/p:cSld/p:spTree/p:graphicFrame/a:graphic/a:graphicData/a:tbl/a:tr/a:tc/a:tcPr';
  594. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/a:lnL[@cmpd="' . Border::LINE_THINTHICK . '"]');
  595. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/a:lnL[@cmpd="' . Border::LINE_THINTHICK . '"]/a:prstDash[@val="' . Border::DASH_LARGEDASH . '"]');
  596. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/a:lnR[@cmpd="' . Border::LINE_THICKTHIN . '"]');
  597. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/a:lnR[@cmpd="' . Border::LINE_THICKTHIN . '"]/a:prstDash[@val="' . Border::DASH_DOT . '"]');
  598. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/a:lnT[@cmpd="' . Border::LINE_SINGLE . '"]');
  599. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/a:lnT[@cmpd="' . Border::LINE_SINGLE . '"]/a:prstDash[@val="' . Border::DASH_DASHDOT . '"]');
  600. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/a:lnB[@cmpd="' . Border::LINE_SINGLE . '"]');
  601. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/a:lnB[@cmpd="' . Border::LINE_SINGLE . '"]/a:prstDash[@val="' . Border::DASH_SOLID . '"]');
  602. }
  603. public function testTableWithCellMargin()
  604. {
  605. $oSlide = $this->oPresentation->getActiveSlide();
  606. $oShape = $oSlide->createTableShape(4);
  607. $oShape->setHeight(200)->setWidth(600)->setOffsetX(150)->setOffsetY(300);
  608. $oRow = $oShape->createRow();
  609. $oCell = $oRow->getCell();
  610. $oCell->createTextRun('AAA');
  611. $oCell->getActiveParagraph()->getAlignment()
  612. ->setMarginBottom(10)
  613. ->setMarginLeft(20)
  614. ->setMarginRight(30)
  615. ->setMarginTop(40);
  616. $element = '/p:sld/p:cSld/p:spTree/p:graphicFrame/a:graphic/a:graphicData/a:tbl/a:tr/a:tc/a:tcPr';
  617. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  618. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'marB', Drawing::pixelsToEmu(10));
  619. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'marL', Drawing::pixelsToEmu(20));
  620. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'marR', Drawing::pixelsToEmu(30));
  621. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'marT', Drawing::pixelsToEmu(40));
  622. }
  623. public function testTableWithColspan()
  624. {
  625. $oSlide = $this->oPresentation->getActiveSlide();
  626. $oShape = $oSlide->createTableShape(4);
  627. $oShape->setHeight(200)->setWidth(600)->setOffsetX(150)->setOffsetY(300);
  628. $oRow = $oShape->createRow();
  629. $oCell = $oRow->getCell();
  630. $oCell->createTextRun('AAA');
  631. $oCell->setColSpan(2);
  632. $element = '/p:sld/p:cSld/p:spTree/p:graphicFrame/a:graphic/a:graphicData/a:tbl/a:tr/a:tc';
  633. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  634. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'gridSpan', 2);
  635. }
  636. public function testTableWithRowspan()
  637. {
  638. $oSlide = $this->oPresentation->getActiveSlide();
  639. $oShape = $oSlide->createTableShape(4);
  640. $oShape->setHeight(200)->setWidth(600)->setOffsetX(150)->setOffsetY(300);
  641. $oRow = $oShape->createRow();
  642. $oCell = $oRow->getCell();
  643. $oCell->createTextRun('AAA');
  644. $oCell->setRowSpan(2);
  645. $oShape->createRow();
  646. $oRow = $oShape->createRow();
  647. $oCell = $oRow->getCell();
  648. $oCell->createTextRun('BBB');
  649. $element = '/p:sld/p:cSld/p:spTree/p:graphicFrame/a:graphic/a:graphicData/a:tbl/a:tr/a:tc';
  650. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '[@rowSpan="2"]');
  651. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '[@vMerge="1"]');
  652. }
  653. /**
  654. * @link : https://github.com/PHPOffice/PHPPresentation/issues/70
  655. */
  656. public function testTableWithHyperlink()
  657. {
  658. $oSlide = $this->oPresentation->getActiveSlide();
  659. $oShape = $oSlide->createTableShape(4);
  660. $oShape->setHeight(200)->setWidth(600)->setOffsetX(150)->setOffsetY(300);
  661. $oRow = $oShape->createRow();
  662. $oCell = $oRow->getCell();
  663. $oTextRun = $oCell->createTextRun('AAA');
  664. $oHyperlink = $oTextRun->getHyperlink();
  665. $oHyperlink->setUrl('https://github.com/PHPOffice/PHPPresentation/');
  666. $element = '/p:sld/p:cSld/p:spTree/p:graphicFrame/a:graphic/a:graphicData/a:tbl/a:tr/a:tc/a:txBody/a:p/a:r/a:rPr/a:hlinkClick';
  667. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  668. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'r:id', 'rId2');
  669. }
  670. public function testTransition()
  671. {
  672. $value = rand(1000, 5000);
  673. $element = '/p:sld/p:transition';
  674. $this->assertZipXmlElementNotExists('ppt/slides/slide1.xml', $element);
  675. $oTransition = new Transition();
  676. $oTransition->setTimeTrigger(true, $value);
  677. $this->oPresentation->getActiveSlide()->setTransition($oTransition);
  678. $this->resetPresentationFile();
  679. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element);
  680. $this->assertZipXmlAttributeExists('ppt/slides/slide1.xml', $element, 'advTm');
  681. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'advTm', $value);
  682. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'advClick', '0');
  683. $oTransition->setSpeed(Transition::SPEED_FAST);
  684. $this->resetPresentationFile();
  685. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'spd', 'fast');
  686. $oTransition->setSpeed(Transition::SPEED_MEDIUM);
  687. $this->resetPresentationFile();
  688. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'spd', 'med');
  689. $oTransition->setSpeed(Transition::SPEED_SLOW);
  690. $this->resetPresentationFile();
  691. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'spd', 'slow');
  692. $rcTransition = new \ReflectionClass('PhpOffice\PhpPresentation\Slide\Transition');
  693. $arrayConstants = $rcTransition->getConstants();
  694. foreach ($arrayConstants as $key => $value) {
  695. if (strpos($key, 'TRANSITION_') !== 0) {
  696. continue;
  697. }
  698. $oTransition->setTransitionType($rcTransition->getConstant($key));
  699. $this->oPresentation->getActiveSlide()->setTransition($oTransition);
  700. $this->resetPresentationFile();
  701. switch ($key) {
  702. case 'TRANSITION_BLINDS_HORIZONTAL':
  703. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:blinds[@dir=\'horz\']');
  704. break;
  705. case 'TRANSITION_BLINDS_VERTICAL':
  706. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:blinds[@dir=\'vert\']');
  707. break;
  708. case 'TRANSITION_CHECKER_HORIZONTAL':
  709. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:checker[@dir=\'horz\']');
  710. break;
  711. case 'TRANSITION_CHECKER_VERTICAL':
  712. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:checker[@dir=\'vert\']');
  713. break;
  714. case 'TRANSITION_CIRCLE_HORIZONTAL':
  715. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:circle[@dir=\'horz\']');
  716. break;
  717. case 'TRANSITION_CIRCLE_VERTICAL':
  718. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:circle[@dir=\'vert\']');
  719. break;
  720. case 'TRANSITION_COMB_HORIZONTAL':
  721. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:comb[@dir=\'horz\']');
  722. break;
  723. case 'TRANSITION_COMB_VERTICAL':
  724. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:comb[@dir=\'vert\']');
  725. break;
  726. case 'TRANSITION_COVER_DOWN':
  727. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:cover[@dir=\'d\']');
  728. break;
  729. case 'TRANSITION_COVER_LEFT':
  730. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:cover[@dir=\'l\']');
  731. break;
  732. case 'TRANSITION_COVER_LEFT_DOWN':
  733. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:cover[@dir=\'ld\']');
  734. break;
  735. case 'TRANSITION_COVER_LEFT_UP':
  736. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:cover[@dir=\'lu\']');
  737. break;
  738. case 'TRANSITION_COVER_RIGHT':
  739. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:cover[@dir=\'r\']');
  740. break;
  741. case 'TRANSITION_COVER_RIGHT_DOWN':
  742. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:cover[@dir=\'rd\']');
  743. break;
  744. case 'TRANSITION_COVER_RIGHT_UP':
  745. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:cover[@dir=\'ru\']');
  746. break;
  747. case 'TRANSITION_COVER_UP':
  748. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:cover[@dir=\'u\']');
  749. break;
  750. case 'TRANSITION_CUT':
  751. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:cut');
  752. break;
  753. case 'TRANSITION_DIAMOND':
  754. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:diamond');
  755. break;
  756. case 'TRANSITION_DISSOLVE':
  757. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:dissolve');
  758. break;
  759. case 'TRANSITION_FADE':
  760. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:fade');
  761. break;
  762. case 'TRANSITION_NEWSFLASH':
  763. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:newsflash');
  764. break;
  765. case 'TRANSITION_PLUS':
  766. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:plus');
  767. break;
  768. case 'TRANSITION_PULL_DOWN':
  769. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:pull[@dir=\'d\']');
  770. break;
  771. case 'TRANSITION_PULL_LEFT':
  772. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:pull[@dir=\'l\']');
  773. break;
  774. case 'TRANSITION_PULL_RIGHT':
  775. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:pull[@dir=\'r\']');
  776. break;
  777. case 'TRANSITION_PULL_UP':
  778. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:pull[@dir=\'u\']');
  779. break;
  780. case 'TRANSITION_PUSH_DOWN':
  781. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:push[@dir=\'d\']');
  782. break;
  783. case 'TRANSITION_PUSH_LEFT':
  784. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:push[@dir=\'l\']');
  785. break;
  786. case 'TRANSITION_PUSH_RIGHT':
  787. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:push[@dir=\'r\']');
  788. break;
  789. case 'TRANSITION_PUSH_UP':
  790. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:push[@dir=\'u\']');
  791. break;
  792. case 'TRANSITION_RANDOM':
  793. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:random');
  794. break;
  795. case 'TRANSITION_RANDOMBAR_HORIZONTAL':
  796. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:randomBar[@dir=\'horz\']');
  797. break;
  798. case 'TRANSITION_RANDOMBAR_VERTICAL':
  799. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:randomBar[@dir=\'vert\']');
  800. break;
  801. case 'TRANSITION_SPLIT_IN_HORIZONTAL':
  802. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:split[@dir=\'in\'][@orient=\'horz\']');
  803. break;
  804. case 'TRANSITION_SPLIT_OUT_HORIZONTAL':
  805. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:split[@dir=\'out\'][@orient=\'horz\']');
  806. break;
  807. case 'TRANSITION_SPLIT_IN_VERTICAL':
  808. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:split[@dir=\'in\'][@orient=\'vert\']');
  809. break;
  810. case 'TRANSITION_SPLIT_OUT_VERTICAL':
  811. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:split[@dir=\'out\'][@orient=\'vert\']');
  812. break;
  813. case 'TRANSITION_STRIPS_LEFT_DOWN':
  814. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:strips[@dir=\'ld\']');
  815. break;
  816. case 'TRANSITION_STRIPS_LEFT_UP':
  817. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:strips[@dir=\'lu\']');
  818. break;
  819. case 'TRANSITION_STRIPS_RIGHT_DOWN':
  820. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:strips[@dir=\'rd\']');
  821. break;
  822. case 'TRANSITION_STRIPS_RIGHT_UP':
  823. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:strips[@dir=\'ru\']');
  824. break;
  825. case 'TRANSITION_WEDGE':
  826. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:wedge');
  827. break;
  828. case 'TRANSITION_WIPE_DOWN':
  829. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:wipe[@dir=\'d\']');
  830. break;
  831. case 'TRANSITION_WIPE_LEFT':
  832. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:wipe[@dir=\'l\']');
  833. break;
  834. case 'TRANSITION_WIPE_RIGHT':
  835. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:wipe[@dir=\'r\']');
  836. break;
  837. case 'TRANSITION_WIPE_UP':
  838. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:wipe[@dir=\'u\']');
  839. break;
  840. case 'TRANSITION_ZOOM_IN':
  841. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:zoom[@dir=\'in\']');
  842. break;
  843. case 'TRANSITION_ZOOM_OUT':
  844. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $element . '/p:zoom[@dir=\'out\']');
  845. break;
  846. }
  847. }
  848. $oTransition->setManualTrigger(true);
  849. $this->resetPresentationFile();
  850. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $element, 'advClick', '1');
  851. }
  852. public function testVisibility()
  853. {
  854. $expectedElement = '/p:sld';
  855. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $expectedElement);
  856. $this->assertZipXmlAttributeNotExists('ppt/slides/slide1.xml', $expectedElement, 'show');
  857. $this->oPresentation->getActiveSlide()->setIsVisible(false);
  858. $this->resetPresentationFile();
  859. $this->assertZipXmlElementExists('ppt/slides/slide1.xml', $expectedElement);
  860. $this->assertZipXmlAttributeExists('ppt/slides/slide1.xml', $expectedElement, 'show');
  861. $this->assertZipXmlAttributeEquals('ppt/slides/slide1.xml', $expectedElement, 'show', 0);
  862. }
  863. }