No Description

StyleTest.php 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * This file is part of PHPWord - A pure PHP library for reading and writing
  4. * word processing documents.
  5. *
  6. * PHPWord is free software distributed under the terms of the GNU Lesser
  7. * General Public License version 3 as published by the Free Software Foundation.
  8. *
  9. * For the full copyright and license information, please read the LICENSE
  10. * file that was distributed with this source code. For the full list of
  11. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
  12. *
  13. * @link https://github.com/PHPOffice/PHPWord
  14. * @copyright 2010-2014 PHPWord contributors
  15. * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
  16. */
  17. namespace PhpOffice\PhpWord\Tests;
  18. use PhpOffice\PhpWord\Style;
  19. /**
  20. * Test class for PhpOffice\PhpWord\Style
  21. *
  22. * @coversDefaultClass \PhpOffice\PhpWord\Style
  23. * @runTestsInSeparateProcesses
  24. */
  25. class StyleTest extends \PHPUnit_Framework_TestCase
  26. {
  27. /**
  28. * Add and get paragraph, font, link, title, and table styles
  29. *
  30. * @covers ::addParagraphStyle
  31. * @covers ::addFontStyle
  32. * @covers ::addLinkStyle
  33. * @covers ::addTitleStyle
  34. * @covers ::addTableStyle
  35. * @covers ::setDefaultParagraphStyle
  36. * @covers ::countStyles
  37. * @covers ::getStyle
  38. * @covers ::resetStyles
  39. * @covers ::getStyles
  40. * @test
  41. */
  42. public function testStyles()
  43. {
  44. $paragraph = array('align' => 'center');
  45. $font = array('italic' => true, '_bold' => true);
  46. $table = array('bgColor' => 'CCCCCC');
  47. $styles = array(
  48. 'Paragraph' => 'Paragraph',
  49. 'Font' => 'Font',
  50. 'Link' => 'Font',
  51. 'Table' => 'Table',
  52. 'Heading_1' => 'Font',
  53. 'Normal' => 'Paragraph',
  54. );
  55. Style::addParagraphStyle('Paragraph', $paragraph);
  56. Style::addFontStyle('Font', $font);
  57. Style::addLinkStyle('Link', $font);
  58. // @todo Style::addNumberingStyle
  59. Style::addTitleStyle(1, $font);
  60. Style::addTableStyle('Table', $table);
  61. Style::setDefaultParagraphStyle($paragraph);
  62. $this->assertCount(count($styles), Style::getStyles());
  63. foreach ($styles as $name => $style) {
  64. $this->assertInstanceOf("PhpOffice\\PhpWord\\Style\\{$style}", Style::getStyle($name));
  65. }
  66. $this->assertNull(Style::getStyle('Unknown'));
  67. Style::resetStyles();
  68. $this->assertCount(0, Style::getStyles());
  69. }
  70. /**
  71. * Test default paragraph style
  72. *
  73. * @covers ::setDefaultParagraphStyle
  74. * @test
  75. */
  76. public function testDefaultParagraphStyle()
  77. {
  78. $paragraph = array('align' => 'center');
  79. Style::setDefaultParagraphStyle($paragraph);
  80. $this->assertInstanceOf("PhpOffice\\PhpWord\\Style\\Paragraph", Style::getStyle('Normal'));
  81. }
  82. }