StylesTe 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. namespace PhpOffice\PhpPresentation\Tests\Writer\ODPresentation;
  3. use PhpOffice\PhpPresentation\DocumentLayout;
  4. use PhpOffice\PhpPresentation\Style\Border;
  5. use PhpOffice\PhpPresentation\Style\Color;
  6. use PhpOffice\PhpPresentation\Style\Fill;
  7. use PhpOffice\PhpPresentation\Tests\PhpPresentationTestCase;
  8. use PhpOffice\PhpPresentation\Writer\ODPresentation;
  9. /**
  10. * Test class for PhpOffice\PhpPresentation\Writer\ODPresentation
  11. *
  12. * @coversDefaultClass PhpOffice\PhpPresentation\Writer\ODPresentation
  13. */
  14. class StylesTest extends PhpPresentationTestCase
  15. {
  16. protected $writerName = 'ODPresentation';
  17. public function testDocumentLayout()
  18. {
  19. $element = "/office:document-styles/office:automatic-styles/style:page-layout/style:page-layout-properties";
  20. $oDocumentLayout = new DocumentLayout();
  21. $oDocumentLayout->setDocumentLayout(DocumentLayout::LAYOUT_A4, true);
  22. $this->oPresentation->setLayout($oDocumentLayout);
  23. $this->assertZipXmlElementExists('styles.xml', $element);
  24. $this->assertZipXmlAttributeEquals('styles.xml', $element, 'style:print-orientation', 'landscape');
  25. $oDocumentLayout->setDocumentLayout(DocumentLayout::LAYOUT_A4, false);
  26. $this->oPresentation->setLayout($oDocumentLayout);
  27. $this->resetPresentationFile();
  28. $this->assertZipXmlElementExists('styles.xml', $element);
  29. $this->assertZipXmlAttributeEquals('styles.xml', $element, 'style:print-orientation', 'portrait');
  30. }
  31. public function testCustomDocumentLayout()
  32. {
  33. $oDocumentLayout = new DocumentLayout();
  34. $oDocumentLayout->setDocumentLayout(array('cx' => rand(1, 100),'cy' => rand(1, 100),));
  35. $this->oPresentation->setLayout($oDocumentLayout);
  36. $element = "/office:document-styles/office:automatic-styles/style:page-layout";
  37. $this->assertZipXmlElementExists('styles.xml', $element);
  38. $this->assertZipXmlAttributeEquals('styles.xml', $element, 'style:name', 'sPL0');
  39. $element = "/office:document-styles/office:master-styles/style:master-page";
  40. $this->assertZipXmlElementExists('styles.xml', $element);
  41. $this->assertZipXmlAttributeEquals('styles.xml', $element, 'style:page-layout-name', 'sPL0');
  42. }
  43. public function testGradientTable()
  44. {
  45. $oSlide = $this->oPresentation->getActiveSlide();
  46. $oShape = $oSlide->createTableShape();
  47. $oRow = $oShape->createRow();
  48. $oCell = $oRow->getCell();
  49. $oCell->getFill()->setFillType(Fill::FILL_GRADIENT_LINEAR)->setStartColor(new Color('FFFF7700'))->setEndColor(new Color('FFFFFFFF'));
  50. $element = "/office:document-styles/office:styles/draw:gradient";
  51. $this->assertZipXmlAttributeEquals('styles.xml', $element, 'draw:name', 'gradient_' . $oCell->getFill()->getHashCode());
  52. }
  53. public function testStrokeDash()
  54. {
  55. $oSlide = $this->oPresentation->getActiveSlide();
  56. $oRichText1 = $oSlide->createRichTextShape();
  57. $oRichText1->getBorder()->setColor(new Color('FF4672A8'))->setLineStyle(Border::LINE_SINGLE);
  58. $arrayDashStyle = array(
  59. Border::DASH_DASH,
  60. Border::DASH_DASHDOT,
  61. Border::DASH_DOT,
  62. Border::DASH_LARGEDASH,
  63. Border::DASH_LARGEDASHDOT,
  64. Border::DASH_LARGEDASHDOTDOT,
  65. Border::DASH_SYSDASH,
  66. Border::DASH_SYSDASHDOT,
  67. Border::DASH_SYSDASHDOTDOT,
  68. Border::DASH_SYSDOT,
  69. );
  70. foreach ($arrayDashStyle as $style) {
  71. $oRichText1->getBorder()->setDashStyle($style);
  72. $element = '/office:document-styles/office:styles/draw:stroke-dash[@draw:name=\'strokeDash_'.$style.'\']';
  73. $this->assertZipXmlElementExists('styles.xml', $element);
  74. $this->assertZipXmlAttributeEquals('styles.xml', $element, 'draw:style', 'rect');
  75. $this->assertZipXmlAttributeExists('styles.xml', $element, 'draw:distance');
  76. switch ($style) {
  77. case Border::DASH_DOT:
  78. case Border::DASH_SYSDOT:
  79. $this->assertZipXmlAttributeExists('styles.xml', $element, 'draw:dots1');
  80. $this->assertZipXmlAttributeExists('styles.xml', $element, 'draw:dots1-length');
  81. break;
  82. case Border::DASH_DASH:
  83. case Border::DASH_LARGEDASH:
  84. case Border::DASH_SYSDASH:
  85. $this->assertZipXmlAttributeExists('styles.xml', $element, 'draw:dots2');
  86. $this->assertZipXmlAttributeExists('styles.xml', $element, 'draw:dots2-length');
  87. break;
  88. case Border::DASH_DASHDOT:
  89. case Border::DASH_LARGEDASHDOT:
  90. case Border::DASH_LARGEDASHDOTDOT:
  91. case Border::DASH_SYSDASHDOT:
  92. case Border::DASH_SYSDASHDOTDOT:
  93. $this->assertZipXmlAttributeExists('styles.xml', $element, 'draw:dots1');
  94. $this->assertZipXmlAttributeExists('styles.xml', $element, 'draw:dots1-length');
  95. $this->assertZipXmlAttributeExists('styles.xml', $element, 'draw:dots2');
  96. $this->assertZipXmlAttributeExists('styles.xml', $element, 'draw:dots2-length');
  97. break;
  98. }
  99. $this->resetPresentationFile();
  100. }
  101. }
  102. }