ContentT 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  1. <?php
  2. namespace PhpOffice\PhpPresentation\Tests\Writer\ODPresentation;
  3. use PhpOffice\Common\Drawing as CommonDrawing;
  4. use PhpOffice\Common\Text;
  5. use PhpOffice\PhpPresentation\Shape\Comment;
  6. use PhpOffice\PhpPresentation\Shape\Media;
  7. use PhpOffice\PhpPresentation\Shape\RichText\Run;
  8. use PhpOffice\PhpPresentation\Slide\Transition;
  9. use PhpOffice\PhpPresentation\Style\Alignment;
  10. use PhpOffice\PhpPresentation\Style\Border;
  11. use PhpOffice\PhpPresentation\Style\Bullet;
  12. use PhpOffice\PhpPresentation\Style\Color;
  13. use PhpOffice\PhpPresentation\Style\Fill;
  14. use PhpOffice\PhpPresentation\Tests\PhpPresentationTestCase;
  15. use PhpOffice\PhpPresentation\Writer\ODPresentation;
  16. use PhpOffice\Common\Drawing;
  17. /**
  18. * Test class for PhpOffice\PhpPresentation\Writer\ODPresentation\Manifest
  19. *
  20. * @coversDefaultClass PhpOffice\PhpPresentation\Writer\ODPresentation\Manifest
  21. */
  22. class ContentTest extends PhpPresentationTestCase
  23. {
  24. protected $writerName = 'ODPresentation';
  25. public function testDrawingWithHyperlink()
  26. {
  27. $oSlide = $this->oPresentation->getActiveSlide();
  28. $oShape = $oSlide->createDrawingShape();
  29. $oShape->setPath(PHPPRESENTATION_TESTS_BASE_DIR.'/resources/images/PhpPresentationLogo.png');
  30. $oShape->getHyperlink()->setUrl('https://github.com/PHPOffice/PHPPresentation/');
  31. $element = '/office:document-content/office:body/office:presentation/draw:page/draw:frame/office:event-listeners/presentation:event-listener';
  32. $this->assertZipXmlElementExists('content.xml', $element);
  33. $this->assertZipXmlAttributeEquals('content.xml', $element, 'xlink:href', 'https://github.com/PHPOffice/PHPPresentation/');
  34. }
  35. public function testComment()
  36. {
  37. $expectedName = 'Name';
  38. $expectedText = 'Text';
  39. $oAuthor = new Comment\Author();
  40. $oAuthor->setName($expectedName);
  41. $oComment = new Comment();
  42. $oComment->setAuthor($oAuthor);
  43. $oComment->setText($expectedText);
  44. $this->oPresentation->getActiveSlide()->addShape($oComment);
  45. $element = '/office:document-content';
  46. $this->assertZipXmlElementExists('content.xml', $element);
  47. $this->assertZipXmlAttributeExists('content.xml', $element, 'xmlns:officeooo');
  48. $element = '/office:document-content/office:body/office:presentation/draw:page/officeooo:annotation';
  49. $this->assertZipXmlElementExists('content.xml', $element);
  50. $element = '/office:document-content/office:body/office:presentation/draw:page/officeooo:annotation/dc:creator';
  51. $this->assertZipXmlElementExists('content.xml', $element);
  52. $this->assertZipXmlElementEquals('content.xml', $element, $expectedName);
  53. $element = '/office:document-content/office:body/office:presentation/draw:page/officeooo:annotation/text:p';
  54. $this->assertZipXmlElementExists('content.xml', $element);
  55. $this->assertZipXmlElementEquals('content.xml', $element, $expectedText);
  56. }
  57. public function testCommentWithoutAuthor()
  58. {
  59. $oComment = new Comment();
  60. $this->oPresentation->getActiveSlide()->addShape($oComment);
  61. $element = '/office:document-content/office:body/office:presentation/draw:page/officeooo:annotation';
  62. $this->assertZipXmlElementExists('content.xml', $element);
  63. $this->assertZipXmlAttributeNotExists('content.xml', $element, 'dc:creator');
  64. }
  65. public function testFillGradientLinearRichText()
  66. {
  67. $oShape = $this->oPresentation->getActiveSlide()->createRichTextShape();
  68. $oShape->getFill()->setFillType(Fill::FILL_GRADIENT_LINEAR)->setStartColor(new Color('FFFF7700'))->setEndColor(new Color('FFFFFFFF'));
  69. $element = '/office:document-styles/office:styles/draw:gradient';
  70. $this->assertZipXmlAttributeEquals('styles.xml', $element, 'draw:name', 'gradient_' . $oShape->getFill()->getHashCode());
  71. $element = '/office:document-content/office:automatic-styles/style:style[@style:name=\'gr1\']/style:graphic-properties';
  72. $this->assertZipXmlElementExists('content.xml', $element);
  73. $this->assertZipXmlAttributeEquals('content.xml', $element, 'draw:fill', 'gradient');
  74. $this->assertZipXmlAttributeEquals('content.xml', $element, 'draw:fill-gradient-name', 'gradient_' . $oShape->getFill()->getHashCode());
  75. }
  76. public function testFillSolidRichText()
  77. {
  78. $oShape = $this->oPresentation->getActiveSlide()->createRichTextShape();
  79. $oShape->getFill()->setFillType(Fill::FILL_SOLID)->setRotation(90)->setStartColor(new Color('FF4672A8'))->setEndColor(new Color('FF4672A8'));
  80. $element = '/office:document-content/office:automatic-styles/style:style[@style:name=\'gr1\']/style:graphic-properties';
  81. $this->assertZipXmlElementExists('content.xml', $element);
  82. $this->assertZipXmlAttributeEquals('content.xml', $element, 'draw:fill', 'solid');
  83. $this->assertZipXmlAttributeEquals('content.xml', $element, 'draw:fill-color', '#' . $oShape->getFill()->getStartColor()->getRGB());
  84. $this->assertZipXmlAttributeEquals('content.xml', $element, 'draw:fill-color', '#' . $oShape->getFill()->getEndColor()->getRGB());
  85. }
  86. public function testGroup()
  87. {
  88. $oShapeGroup = $this->oPresentation->getActiveSlide()->createGroup();
  89. $oShape = $oShapeGroup->createDrawingShape();
  90. $oShape->setPath(PHPPRESENTATION_TESTS_BASE_DIR.'/resources/images/PhpPresentationLogo.png');
  91. $oShape->getHyperlink()->setUrl('https://github.com/PHPOffice/PHPPresentation/');
  92. $element = '/office:document-content/office:body/office:presentation/draw:page/draw:g';
  93. $this->assertZipXmlElementExists('content.xml', $element);
  94. $element = '/office:document-content/office:body/office:presentation/draw:page/draw:g/draw:frame/office:event-listeners/presentation:event-listener';
  95. $this->assertZipXmlElementExists('content.xml', $element);
  96. }
  97. public function testList()
  98. {
  99. $oRichText = $this->oPresentation->getActiveSlide()->createRichTextShape();
  100. $oRichText->getActiveParagraph()->getBulletStyle()->setBulletType(Bullet::TYPE_BULLET);
  101. $oRichText->createTextRun('Alpha');
  102. $oRichText->createParagraph()->createTextRun('Beta');
  103. $oRichText->createParagraph()->createTextRun('Delta');
  104. $oRichText->createParagraph()->createTextRun('Epsilon');
  105. $element = '/office:document-content/office:automatic-styles/text:list-style/text:list-level-style-bullet';
  106. $this->assertZipXmlElementExists('content.xml', $element);
  107. $element = '/office:document-content/office:body/office:presentation/draw:page/draw:frame/draw:text-box';
  108. $this->assertZipXmlElementExists('content.xml', $element);
  109. $element = '/office:document-content/office:body/office:presentation/draw:page/draw:frame/draw:text-box/text:list/text:list-item/text:p/text:span';
  110. $this->assertZipXmlElementExists('content.xml', $element);
  111. }
  112. public function testInnerList()
  113. {
  114. $oRichText = $this->oPresentation->getActiveSlide()->createRichTextShape();
  115. $oRichText->getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_LEFT)->setMarginLeft(25)->setIndent(-25);
  116. $oRichText->getActiveParagraph()->getBulletStyle()->setBulletType(Bullet::TYPE_BULLET);
  117. $oRichText->createTextRun('Alpha');
  118. $oRichText->createParagraph()->getAlignment()->setLevel(1)->setMarginLeft(75)->setIndent(-25);
  119. $oRichText->createTextRun('Alpha.Alpha');
  120. $oRichText->createParagraph()->createTextRun('Alpha.Beta');
  121. $oRichText->createParagraph()->createTextRun('Alpha.Delta');
  122. $oRichText->createParagraph()->getAlignment()->setLevel(0)->setMarginLeft(25)->setIndent(-25);
  123. $oRichText->createTextRun('Beta');
  124. $oRichText->createParagraph()->getAlignment()->setLevel(1)->setMarginLeft(75)->setIndent(-25);
  125. $oRichText->createTextRun('Beta.Alpha');
  126. $oRichText->createParagraph()->createTextRun('Beta.Beta');
  127. $oRichText->createParagraph()->createTextRun('Beta.Delta');
  128. $element = '/office:document-content/office:automatic-styles/text:list-style/text:list-level-style-bullet';
  129. $this->assertZipXmlElementExists('content.xml', $element);
  130. $element = '/office:document-content/office:body/office:presentation/draw:page/draw:frame/draw:text-box';
  131. $this->assertZipXmlElementExists('content.xml', $element);
  132. $element = '/office:document-content/office:body/office:presentation/draw:page/draw:frame/draw:text-box/text:list/text:list-item/text:list/text:list-item/text:p/text:span';
  133. $this->assertZipXmlElementExists('content.xml', $element);
  134. }
  135. public function testParagraphRichText()
  136. {
  137. $oRichText = $this->oPresentation->getActiveSlide()->createRichTextShape();
  138. $oRichText->createTextRun('Alpha');
  139. $oRichText->createBreak();
  140. $oRichText->createText('Beta');
  141. $oRichText->createBreak();
  142. $oRun = $oRichText->createTextRun('Delta');
  143. $oRun->getHyperlink()->setUrl('http://www.google.fr');
  144. $element = '/office:document-content/office:body/office:presentation/draw:page/draw:frame/draw:text-box/text:p/text:span/text:line-break';
  145. $this->assertZipXmlElementExists('content.xml', $element);
  146. $element = '/office:document-content/office:body/office:presentation/draw:page/draw:frame/draw:text-box/text:p/text:span/text:a';
  147. $this->assertZipXmlElementExists('content.xml', $element);
  148. $this->assertZipXmlAttributeEquals('content.xml', $element, 'xlink:href', 'http://www.google.fr');
  149. }
  150. public function testListWithRichText()
  151. {
  152. $oRichText = $this->oPresentation->getActiveSlide()->createRichTextShape();
  153. $oRichText->getActiveParagraph()->getBulletStyle()->setBulletType(Bullet::TYPE_BULLET);
  154. $oRun = $oRichText->createTextRun('Alpha');
  155. $oRun->getHyperlink()->setUrl('http://www.google.fr');
  156. $oRichText->createBreak();
  157. $oRichText->createTextRun('Beta');
  158. $element = '/office:document-content/office:body/office:presentation/draw:page/draw:frame/draw:text-box/text:list/text:list-item/text:p/text:span/text:a';
  159. $this->assertZipXmlElementExists('content.xml', $element);
  160. $element = '/office:document-content/office:body/office:presentation/draw:page/draw:frame/draw:text-box/text:list/text:list-item/text:p/text:span/text:line-break';
  161. $this->assertZipXmlElementExists('content.xml', $element);
  162. }
  163. public function testMedia()
  164. {
  165. $expectedName = 'MyName';
  166. $expectedWidth = rand(1, 100);
  167. $expectedHeight = rand(1, 100);
  168. $expectedX = rand(1, 100);
  169. $expectedY = rand(1, 100);
  170. $oMedia = new Media();
  171. $oMedia->setPath(PHPPRESENTATION_TESTS_BASE_DIR . '/resources/videos/sintel_trailer-480p.ogv')
  172. ->setName($expectedName)
  173. ->setResizeProportional(false)
  174. ->setHeight($expectedHeight)
  175. ->setWidth($expectedWidth)
  176. ->setOffsetX($expectedX)
  177. ->setOffsetY($expectedY);
  178. $this->oPresentation->getActiveSlide()->addShape($oMedia);
  179. $expectedWidth = Text::numberFormat(CommonDrawing::pixelsToCentimeters($expectedWidth), 3) . 'cm';
  180. $expectedHeight = Text::numberFormat(CommonDrawing::pixelsToCentimeters($expectedHeight), 3) . 'cm';
  181. $expectedX = Text::numberFormat(CommonDrawing::pixelsToCentimeters($expectedX), 3) . 'cm';
  182. $expectedY = Text::numberFormat(CommonDrawing::pixelsToCentimeters($expectedY), 3) . 'cm';
  183. $element = '/office:document-content/office:body/office:presentation/draw:page/draw:frame';
  184. $this->assertZipXmlElementExists('content.xml', $element);
  185. $this->assertZipXmlAttributeEquals('content.xml', $element, 'draw:name', $expectedName);
  186. $this->assertZipXmlAttributeEquals('content.xml', $element, 'svg:width', $expectedWidth);
  187. $this->assertZipXmlAttributeEquals('content.xml', $element, 'svg:height', $expectedHeight);
  188. $this->assertZipXmlAttributeEquals('content.xml', $element, 'svg:x', $expectedX);
  189. $this->assertZipXmlAttributeEquals('content.xml', $element, 'svg:y', $expectedY);
  190. $element = '/office:document-content/office:body/office:presentation/draw:page/draw:frame/draw:plugin';
  191. $this->assertZipXmlElementExists('content.xml', $element);
  192. $this->assertZipXmlAttributeEquals('content.xml', $element, 'draw:mime-type', 'application/vnd.sun.star.media');
  193. $this->assertZipXmlAttributeStartsWith('content.xml', $element, 'draw:mime-type', 'application/vnd.sun.star.media');
  194. $this->assertZipXmlAttributeStartsWith('content.xml', $element, 'xlink:href', 'Pictures/');
  195. $this->assertZipXmlAttributeEndsWith('content.xml', $element, 'xlink:href', 'ogv');
  196. }
  197. public function testNote()
  198. {
  199. $oNote = $this->oPresentation->getActiveSlide()->getNote();
  200. $oRichText = $oNote->createRichTextShape()->setHeight(300)->setWidth(600);
  201. $oRichText->createTextRun('testNote');
  202. $element = '/office:document-content/office:body/office:presentation/draw:page/presentation:notes';
  203. $this->assertZipXmlElementExists('content.xml', $element);
  204. $element = '/office:document-content/office:body/office:presentation/draw:page/presentation:notes/draw:frame/draw:text-box/text:p/text:span';
  205. $this->assertZipXmlElementExists('content.xml', $element);
  206. }
  207. public function testRichTextAutoShrink()
  208. {
  209. $oRichText1 = $this->oPresentation->getActiveSlide()->createRichTextShape();
  210. $element = '/office:document-content/office:automatic-styles/style:style[@style:name=\'gr1\']/style:graphic-properties';
  211. $this->assertZipXmlAttributeNotExists('content.xml', $element, 'draw:auto-grow-height');
  212. $this->assertZipXmlAttributeNotExists('content.xml', $element, 'draw:auto-grow-width');
  213. $oRichText1->setAutoShrinkHorizontal(false);
  214. $oRichText1->setAutoShrinkVertical(true);
  215. $this->resetPresentationFile();
  216. $this->assertZipXmlAttributeExists('content.xml', $element, 'draw:auto-grow-height');
  217. $this->assertZipXmlAttributeExists('content.xml', $element, 'draw:auto-grow-width');
  218. $this->assertZipXmlAttributeEquals('content.xml', $element, 'draw:auto-grow-height', 'true');
  219. $this->assertZipXmlAttributeEquals('content.xml', $element, 'draw:auto-grow-width', 'false');
  220. $oRichText1->setAutoShrinkHorizontal(true);
  221. $oRichText1->setAutoShrinkVertical(false);
  222. $this->resetPresentationFile();
  223. $this->assertZipXmlAttributeExists('content.xml', $element, 'draw:auto-grow-height');
  224. $this->assertZipXmlAttributeExists('content.xml', $element, 'draw:auto-grow-width');
  225. $this->assertZipXmlAttributeEquals('content.xml', $element, 'draw:auto-grow-height', 'false');
  226. $this->assertZipXmlAttributeEquals('content.xml', $element, 'draw:auto-grow-width', 'true');
  227. }
  228. public function testRichTextRunLanguage()
  229. {
  230. $oRichText = $this->oPresentation->getActiveSlide()->createRichTextShape();
  231. $oRun = $oRichText->createTextRun('MyText');
  232. $element = '/office:document-content/office:automatic-styles/style:style[@style:name=\'T_' . $oRun->getHashCode() . '\']/style:text-properties';
  233. $this->assertZipXmlElementExists('content.xml', $element);
  234. $this->assertZipXmlAttributeExists('content.xml', $element, 'fo:language');
  235. $this->assertZipXmlAttributeEquals('content.xml', $element, 'fo:language', 'en-US');
  236. $oRun->setLanguage('de_DE');
  237. $this->resetPresentationFile();
  238. $this->assertZipXmlElementExists('content.xml', $element);
  239. $this->assertZipXmlAttributeExists('content.xml', $element, 'fo:language');
  240. $this->assertZipXmlAttributeEquals('content.xml', $element, 'fo:language', 'de_DE');
  241. }
  242. public function testRichTextBorder()
  243. {
  244. $oRichText1 = $this->oPresentation->getActiveSlide()->createRichTextShape();
  245. $oRichText1->getBorder()->setColor(new Color('FF4672A8'))->setDashStyle(Border::DASH_SOLID)->setLineStyle(Border::LINE_NONE);
  246. $element = '/office:document-content/office:automatic-styles/style:style[@style:name=\'gr1\']/style:graphic-properties';
  247. $this->assertZipXmlElementExists('content.xml', $element);
  248. $this->assertZipXmlAttributeNotExists('content.xml', $element, 'svg:stroke-color');
  249. $this->assertZipXmlAttributeNotExists('content.xml', $element, 'svg:stroke-width');
  250. $this->assertZipXmlAttributeExists('content.xml', $element, 'draw:stroke');
  251. $this->assertZipXmlAttributeEquals('content.xml', $element, 'draw:stroke', 'none');
  252. $oRichText1->getBorder()->setColor(new Color('FF4672A8'))->setDashStyle(Border::DASH_SOLID)->setLineStyle(Border::LINE_SINGLE);
  253. $this->resetPresentationFile();
  254. $this->assertZipXmlElementExists('content.xml', $element);
  255. $this->assertZipXmlAttributeExists('content.xml', $element, 'svg:stroke-color');
  256. $this->assertZipXmlAttributeEquals('content.xml', $element, 'svg:stroke-color', '#' . $oRichText1->getBorder()->getColor()->getRGB());
  257. $this->assertZipXmlAttributeExists('content.xml', $element, 'svg:stroke-width');
  258. $this->assertZipXmlAttributeStartsWith('content.xml', $element, 'svg:stroke-width', (string)number_format(CommonDrawing::pointsToCentimeters($oRichText1->getBorder()->getLineWidth()), 3, '.', ''));
  259. $this->assertZipXmlAttributeEndsWith('content.xml', $element, 'svg:stroke-width', 'cm');
  260. $this->assertZipXmlAttributeExists('content.xml', $element, 'draw:stroke');
  261. $this->assertZipXmlAttributeEquals('content.xml', $element, 'draw:stroke', 'solid');
  262. $this->assertZipXmlAttributeNotExists('content.xml', $element, 'draw:stroke-dash');
  263. $oRichText1->getBorder()->setColor(new Color('FF4672A8'))->setDashStyle(Border::DASH_DASH);
  264. $this->resetPresentationFile();
  265. $this->assertZipXmlAttributeEquals('content.xml', $element, 'draw:stroke', 'dash');
  266. $this->assertZipXmlAttributeExists('content.xml', $element, 'draw:stroke-dash');
  267. $this->assertZipXmlAttributeStartsWith('content.xml', $element, 'draw:stroke-dash', 'strokeDash_');
  268. $this->assertZipXmlAttributeEndsWith('content.xml', $element, 'draw:stroke-dash', $oRichText1->getBorder()->getDashStyle());
  269. }
  270. public function testRichTextShadow()
  271. {
  272. $randAlpha = rand(0, 100);
  273. $oRichText = $this->oPresentation->getActiveSlide()->createRichTextShape();
  274. $oRichText->createTextRun('AAA');
  275. $oRichText->getShadow()->setVisible(true)->setAlpha($randAlpha)->setBlurRadius(2);
  276. $element = '/office:document-content/office:automatic-styles/style:style[@style:name=\'gr1\']/style:graphic-properties';
  277. for ($inc = 0; $inc <= 360; $inc += 45) {
  278. $randDistance = rand(0, 100);
  279. $oRichText->getShadow()->setDirection($inc)->setDistance($randDistance);
  280. $this->assertZipXmlElementExists('content.xml', $element);
  281. $this->assertZipXmlAttributeEquals('content.xml', $element, 'draw:shadow', 'visible');
  282. $this->assertZipXmlAttributeEquals('content.xml', $element, 'style:mirror', 'none');
  283. // Opacity
  284. $this->assertZipXmlAttributeStartsWith('content.xml', $element, 'draw:shadow-opacity', (string)(100 - $randAlpha));
  285. $this->assertZipXmlAttributeEndsWith('content.xml', $element, 'draw:shadow-opacity', '%');
  286. // Color
  287. $this->assertZipXmlAttributeStartsWith('content.xml', $element, 'draw:shadow-color', '#');
  288. // X
  289. if ($inc == 90 || $inc == 270) {
  290. $this->assertZipXmlAttributeEquals('content.xml', $element, 'draw:shadow-offset-x', '0cm');
  291. } else {
  292. if ($inc > 90 && $inc < 270) {
  293. $this->assertZipXmlAttributeEquals('content.xml', $element, 'draw:shadow-offset-x', '-' . Drawing::pixelsToCentimeters($randDistance) . 'cm');
  294. } else {
  295. $this->assertZipXmlAttributeEquals('content.xml', $element, 'draw:shadow-offset-x', Drawing::pixelsToCentimeters($randDistance) . 'cm');
  296. }
  297. }
  298. // Y
  299. if ($inc == 0 || $inc == 180 || $inc == 360) {
  300. $this->assertZipXmlAttributeEquals('content.xml', $element, 'draw:shadow-offset-y', '0cm');
  301. } else {
  302. if (($inc > 0 && $inc < 180) || $inc == 360) {
  303. $this->assertZipXmlAttributeEquals('content.xml', $element, 'draw:shadow-offset-y', Drawing::pixelsToCentimeters($randDistance) . 'cm');
  304. } else {
  305. $this->assertZipXmlAttributeEquals('content.xml', $element, 'draw:shadow-offset-y', '-' . Drawing::pixelsToCentimeters($randDistance) . 'cm');
  306. }
  307. }
  308. $this->resetPresentationFile();
  309. }
  310. }
  311. public function testSlideName()
  312. {
  313. $element = '/office:document-content/office:body/office:presentation/draw:page';
  314. $this->assertZipXmlElementExists('content.xml', $element);
  315. $this->assertZipXmlAttributeNotExists('content.xml', $element, 'draw:name');
  316. $this->oPresentation->getActiveSlide()->setName('AAAA');
  317. $this->resetPresentationFile();
  318. $this->assertZipXmlElementExists('content.xml', $element);
  319. $this->assertZipXmlAttributeExists('content.xml', $element, 'draw:name');
  320. $this->assertZipXmlAttributeEquals('content.xml', $element, 'draw:name', 'AAAA');
  321. $this->oPresentation->getActiveSlide()->setName();
  322. $this->resetPresentationFile();
  323. $this->assertZipXmlElementExists('content.xml', $element);
  324. $this->assertZipXmlAttributeNotExists('content.xml', $element, 'draw:name');
  325. }
  326. public function testStyleAlignment()
  327. {
  328. $oSlide = $this->oPresentation->getActiveSlide();
  329. $oRichText1 = $oSlide->createRichTextShape();
  330. $oRichText1->getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
  331. $oRichText1->createTextRun('Run1');
  332. $oRichText2 = $oSlide->createRichTextShape();
  333. $oRichText2->getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_DISTRIBUTED);
  334. $oRichText2->createTextRun('Run2');
  335. $oRichText3 = $oSlide->createRichTextShape();
  336. $oRichText3->getActiveParagraph()->getAlignment()->setHorizontal('AAAAA');
  337. $oRichText3->createTextRun('Run3');
  338. $oRichText4 = $oSlide->createRichTextShape();
  339. $oRichText4->getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_JUSTIFY);
  340. $oRichText4->createTextRun('Run4');
  341. $oRichText5 = $oSlide->createRichTextShape();
  342. $oRichText5->getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_LEFT);
  343. $oRichText5->createTextRun('Run5');
  344. $oRichText6 = $oSlide->createRichTextShape();
  345. $oRichText6->getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_RIGHT);
  346. $oRichText6->createTextRun('Run6');
  347. $p1HashCode = $oRichText1->getActiveParagraph()->getHashCode();
  348. $p2HashCode = $oRichText2->getActiveParagraph()->getHashCode();
  349. $p3HashCode = $oRichText3->getActiveParagraph()->getHashCode();
  350. $p4HashCode = $oRichText4->getActiveParagraph()->getHashCode();
  351. $p5HashCode = $oRichText5->getActiveParagraph()->getHashCode();
  352. $p6HashCode = $oRichText6->getActiveParagraph()->getHashCode();
  353. $element = '/office:document-content/office:automatic-styles/style:style[@style:name=\'P_'.$p1HashCode.'\']/style:paragraph-properties';
  354. $this->assertZipXmlElementExists('content.xml', $element);
  355. $this->assertZipXmlAttributeEquals('content.xml', $element, 'fo:text-align', 'center');
  356. $element = '/office:document-content/office:automatic-styles/style:style[@style:name=\'P_'.$p2HashCode.'\']/style:paragraph-properties';
  357. $this->assertZipXmlElementExists('content.xml', $element);
  358. $this->assertZipXmlAttributeEquals('content.xml', $element, 'fo:text-align', 'justify');
  359. $element = '/office:document-content/office:automatic-styles/style:style[@style:name=\'P_'.$p3HashCode.'\']/style:paragraph-properties';
  360. $this->assertZipXmlElementExists('content.xml', $element);
  361. $this->assertZipXmlAttributeEquals('content.xml', $element, 'fo:text-align', 'left');
  362. $element = '/office:document-content/office:automatic-styles/style:style[@style:name=\'P_'.$p4HashCode.'\']/style:paragraph-properties';
  363. $this->assertZipXmlElementExists('content.xml', $element);
  364. $this->assertZipXmlAttributeEquals('content.xml', $element, 'fo:text-align', 'justify');
  365. $element = '/office:document-content/office:automatic-styles/style:style[@style:name=\'P_'.$p5HashCode.'\']/style:paragraph-properties';
  366. $this->assertZipXmlElementExists('content.xml', $element);
  367. $this->assertZipXmlAttributeEquals('content.xml', $element, 'fo:text-align', 'left');
  368. $element = '/office:document-content/office:automatic-styles/style:style[@style:name=\'P_'.$p6HashCode.'\']/style:paragraph-properties';
  369. $this->assertZipXmlElementExists('content.xml', $element);
  370. $this->assertZipXmlAttributeEquals('content.xml', $element, 'fo:text-align', 'right');
  371. }
  372. public function testStyleFont()
  373. {
  374. $oRichText = $this->oPresentation->getActiveSlide()->createRichTextShape();
  375. $oRun = $oRichText->createTextRun('Run1');
  376. $oRun->getFont()->setBold(true);
  377. $expectedHashCode = $oRun->getHashCode();
  378. $element = '/office:document-content/office:automatic-styles/style:style[@style:name=\'T_'.$expectedHashCode.'\']/style:text-properties';
  379. $this->assertZipXmlElementExists('content.xml', $element);
  380. $this->assertZipXmlAttributeEquals('content.xml', $element, 'fo:font-weight', 'bold');
  381. }
  382. public function testTable()
  383. {
  384. $this->oPresentation->getActiveSlide()->createTableShape();
  385. $element = '/office:document-content/office:body/office:presentation/draw:page/draw:frame/table:table';
  386. $this->assertZipXmlElementExists('content.xml', $element);
  387. }
  388. public function testTableCellFill()
  389. {
  390. $oColor = new Color();
  391. $oColor->setRGB(Color::COLOR_BLUE);
  392. $oFill = new Fill();
  393. $oFill->setFillType(Fill::FILL_SOLID)->setStartColor($oColor);
  394. $oShape = $this->oPresentation->getActiveSlide()->createTableShape();
  395. $oRow = $oShape->createRow();
  396. $oCell = $oRow->getCell();
  397. $oCell->setFill($oFill);
  398. $element = '/office:document-content/office:automatic-styles/style:style[@style:name=\'gr1r0c0\']';
  399. $this->assertZipXmlElementExists('content.xml', $element);
  400. $this->assertZipXmlAttributeEquals('content.xml', $element, 'style:family', 'table-cell');
  401. $element = '/office:document-content/office:automatic-styles/style:style[@style:name=\'gr1r0c0\']/style:graphic-properties';
  402. $this->assertZipXmlElementExists('content.xml', $element);
  403. $this->assertZipXmlAttributeEquals('content.xml', $element, 'draw:fill', 'solid');
  404. $this->assertZipXmlAttributeStartsWith('content.xml', $element, 'draw:fill-color', '#');
  405. $this->assertZipXmlAttributeEndsWith('content.xml', $element, 'draw:fill-color', $oColor->getRGB());
  406. }
  407. public function testTableWithColspan()
  408. {
  409. $value = rand(2, 100);
  410. $oShape = $this->oPresentation->getActiveSlide()->createTableShape($value);
  411. $oRow = $oShape->createRow();
  412. $oCell = $oRow->getCell();
  413. $oCell->setColSpan($value);
  414. $element = '/office:document-content/office:body/office:presentation/draw:page/draw:frame/table:table/table:table-row/table:table-cell';
  415. $this->assertZipXmlElementExists('content.xml', $element);
  416. $this->assertZipXmlAttributeEquals('content.xml', $element, 'table:number-columns-spanned', $value);
  417. }
  418. /**
  419. * @link : https://github.com/PHPOffice/PHPPresentation/issues/70
  420. */
  421. public function testTableWithHyperlink()
  422. {
  423. $oShape = $this->oPresentation->getActiveSlide()->createTableShape(4);
  424. $oShape->setHeight(200)->setWidth(600)->setOffsetX(150)->setOffsetY(300);
  425. $oRow = $oShape->createRow();
  426. $oCell = $oRow->getCell();
  427. $oTextRun = $oCell->createTextRun('AAA');
  428. $oHyperlink = $oTextRun->getHyperlink();
  429. $oHyperlink->setUrl('https://github.com/PHPOffice/PHPPresentation/');
  430. $element = '/office:document-content/office:body/office:presentation/draw:page/draw:frame/table:table/table:table-row/table:table-cell/text:p/text:span/text:a';
  431. $this->assertZipXmlElementExists('content.xml', $element);
  432. $this->assertZipXmlAttributeEquals('content.xml', $element, 'xlink:href', 'https://github.com/PHPOffice/PHPPresentation/');
  433. }
  434. public function testTableWithText()
  435. {
  436. $oRun = new Run();
  437. $oRun->setText('Test');
  438. $oShape = $this->oPresentation->getActiveSlide()->createTableShape();
  439. $oRow = $oShape->createRow();
  440. $oCell = $oRow->getCell();
  441. $oCell->addText($oRun);
  442. $oCell->createBreak();
  443. $element = '/office:document-content/office:body/office:presentation/draw:page/draw:frame/table:table/table:table-row/table:table-cell/text:p/text:span';
  444. $this->assertZipXmlElementExists('content.xml', $element);
  445. $this->assertZipXmlElementEquals('content.xml', $element, 'Test');
  446. $element = '/office:document-content/office:body/office:presentation/draw:page/draw:frame/table:table/table:table-row/table:table-cell/text:p/text:span/text:line-break';
  447. $this->assertZipXmlElementExists('content.xml', $element);
  448. }
  449. public function testTransition()
  450. {
  451. $value = rand(1000, 5000);
  452. $element = '/office:document-content/office:automatic-styles/style:style[@style:name=\'stylePage0\']/style:drawing-page-properties';
  453. $this->assertZipXmlElementExists('content.xml', $element);
  454. $this->assertZipXmlAttributeNotExists('content.xml', $element, 'presentation:duration');
  455. $oTransition = new Transition();
  456. $oTransition->setTimeTrigger(true, $value);
  457. $this->oPresentation->getActiveSlide()->setTransition($oTransition);
  458. $this->resetPresentationFile();
  459. $this->assertZipXmlElementExists('content.xml', $element);
  460. $this->assertZipXmlAttributeExists('content.xml', $element, 'presentation:duration');
  461. $this->assertZipXmlAttributeStartsWith('content.xml', $element, 'presentation:duration', 'PT');
  462. $this->assertZipXmlAttributeEndsWith('content.xml', $element, 'presentation:duration', 'S');
  463. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:duration', number_format($value / 1000, 6, '.', ''));
  464. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-type', 'automatic');
  465. $oTransition->setSpeed(Transition::SPEED_FAST);
  466. $this->resetPresentationFile();
  467. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-speed', 'fast');
  468. $oTransition->setSpeed(Transition::SPEED_MEDIUM);
  469. $this->resetPresentationFile();
  470. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-speed', 'medium');
  471. $oTransition->setSpeed(Transition::SPEED_SLOW);
  472. $this->resetPresentationFile();
  473. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-speed', 'slow');
  474. $rcTransition = new \ReflectionClass('PhpOffice\PhpPresentation\Slide\Transition');
  475. $arrayConstants = $rcTransition->getConstants();
  476. foreach ($arrayConstants as $key => $value) {
  477. if (strpos($key, 'TRANSITION_') !== 0) {
  478. continue;
  479. }
  480. $this->resetPresentationFile();
  481. $oTransition->setTransitionType($rcTransition->getConstant($key));
  482. $this->oPresentation->getActiveSlide()->setTransition($oTransition);
  483. switch ($key) {
  484. case 'TRANSITION_BLINDS_HORIZONTAL':
  485. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'horizontal-stripes');
  486. break;
  487. case 'TRANSITION_BLINDS_VERTICAL':
  488. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'vertical-stripes');
  489. break;
  490. case 'TRANSITION_CHECKER_HORIZONTAL':
  491. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'horizontal-checkerboard');
  492. break;
  493. case 'TRANSITION_CHECKER_VERTICAL':
  494. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'vertical-checkerboard');
  495. break;
  496. case 'TRANSITION_CIRCLE_HORIZONTAL':
  497. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'none');
  498. break;
  499. case 'TRANSITION_CIRCLE_VERTICAL':
  500. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'none');
  501. break;
  502. case 'TRANSITION_COMB_HORIZONTAL':
  503. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'none');
  504. break;
  505. case 'TRANSITION_COMB_VERTICAL':
  506. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'none');
  507. break;
  508. case 'TRANSITION_COVER_DOWN':
  509. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'uncover-to-bottom');
  510. break;
  511. case 'TRANSITION_COVER_LEFT':
  512. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'uncover-to-left');
  513. break;
  514. case 'TRANSITION_COVER_LEFT_DOWN':
  515. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'uncover-to-lowerleft');
  516. break;
  517. case 'TRANSITION_COVER_LEFT_UP':
  518. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'uncover-to-upperleft');
  519. break;
  520. case 'TRANSITION_COVER_RIGHT':
  521. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'uncover-to-right');
  522. break;
  523. case 'TRANSITION_COVER_RIGHT_DOWN':
  524. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'uncover-to-lowerright');
  525. break;
  526. case 'TRANSITION_COVER_RIGHT_UP':
  527. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'uncover-to-upperright');
  528. break;
  529. case 'TRANSITION_COVER_UP':
  530. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'uncover-to-top');
  531. break;
  532. case 'TRANSITION_CUT':
  533. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'none');
  534. break;
  535. case 'TRANSITION_DIAMOND':
  536. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'none');
  537. break;
  538. case 'TRANSITION_DISSOLVE':
  539. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'dissolve');
  540. break;
  541. case 'TRANSITION_FADE':
  542. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'fade-from-center');
  543. break;
  544. case 'TRANSITION_NEWSFLASH':
  545. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'none');
  546. break;
  547. case 'TRANSITION_PLUS':
  548. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'close');
  549. break;
  550. case 'TRANSITION_PULL_DOWN':
  551. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'stretch-from-bottom');
  552. break;
  553. case 'TRANSITION_PULL_LEFT':
  554. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'stretch-from-left');
  555. break;
  556. case 'TRANSITION_PULL_RIGHT':
  557. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'stretch-from-right');
  558. break;
  559. case 'TRANSITION_PULL_UP':
  560. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'stretch-from-top');
  561. break;
  562. case 'TRANSITION_PUSH_DOWN':
  563. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'roll-from-bottom');
  564. break;
  565. case 'TRANSITION_PUSH_LEFT':
  566. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'roll-from-left');
  567. break;
  568. case 'TRANSITION_PUSH_RIGHT':
  569. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'roll-from-right');
  570. break;
  571. case 'TRANSITION_PUSH_UP':
  572. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'roll-from-top');
  573. break;
  574. case 'TRANSITION_RANDOM':
  575. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'random');
  576. break;
  577. case 'TRANSITION_RANDOMBAR_HORIZONTAL':
  578. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'horizontal-lines');
  579. break;
  580. case 'TRANSITION_RANDOMBAR_VERTICAL':
  581. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'vertical-lines');
  582. break;
  583. case 'TRANSITION_SPLIT_IN_HORIZONTAL':
  584. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'close-horizontal');
  585. break;
  586. case 'TRANSITION_SPLIT_OUT_HORIZONTAL':
  587. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'open-horizontal');
  588. break;
  589. case 'TRANSITION_SPLIT_IN_VERTICAL':
  590. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'close-vertical');
  591. break;
  592. case 'TRANSITION_SPLIT_OUT_VERTICAL':
  593. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'open-vertical');
  594. break;
  595. case 'TRANSITION_STRIPS_LEFT_DOWN':
  596. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'none');
  597. break;
  598. case 'TRANSITION_STRIPS_LEFT_UP':
  599. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'none');
  600. break;
  601. case 'TRANSITION_STRIPS_RIGHT_DOWN':
  602. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'none');
  603. break;
  604. case 'TRANSITION_STRIPS_RIGHT_UP':
  605. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'none');
  606. break;
  607. case 'TRANSITION_WEDGE':
  608. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'none');
  609. break;
  610. case 'TRANSITION_WIPE_DOWN':
  611. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'fade-from-bottom');
  612. break;
  613. case 'TRANSITION_WIPE_LEFT':
  614. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'fade-from-left');
  615. break;
  616. case 'TRANSITION_WIPE_RIGHT':
  617. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'fade-from-right');
  618. break;
  619. case 'TRANSITION_WIPE_UP':
  620. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'fade-from-top');
  621. break;
  622. case 'TRANSITION_ZOOM_IN':
  623. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'none');
  624. break;
  625. case 'TRANSITION_ZOOM_OUT':
  626. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-style', 'none');
  627. break;
  628. }
  629. }
  630. $oTransition->setTimeTrigger(false);
  631. $oTransition->setManualTrigger(true);
  632. $this->resetPresentationFile();
  633. $this->assertZipXmlAttributeContains('content.xml', $element, 'presentation:transition-type', 'manual');
  634. }
  635. public function testVisibility()
  636. {
  637. $element = '/office:document-content/office:automatic-styles/style:style[@style:name=\'stylePage0\']/style:drawing-page-properties';
  638. $this->assertZipXmlElementExists('content.xml', $element);
  639. $this->assertZipXmlAttributeNotExists('content.xml', $element, 'presentation:visibility');
  640. $oSlide = $this->oPresentation->getActiveSlide();
  641. $oSlide->setIsVisible(false);
  642. $this->resetPresentationFile();
  643. $this->assertZipXmlElementExists('content.xml', $element);
  644. $this->assertZipXmlAttributeExists('content.xml', $element, 'presentation:visibility');
  645. $this->assertZipXmlAttributeEquals('content.xml', $element, 'presentation:visibility', 'hidden');
  646. }
  647. }