PageRenderTime 53ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/PhpWord/Tests/StyleTest.php

https://github.com/cyrillkalita/PHPWord
PHP | 71 lines | 35 code | 10 blank | 26 comment | 0 complexity | 36bcf53c9d1b411af047af1945271c16 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-3.0
  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. * @runTestsInSeparateProcesses
  23. */
  24. class StyleTest extends \PHPUnit_Framework_TestCase
  25. {
  26. /**
  27. * Add and get paragraph, font, link, title, and table styles
  28. */
  29. public function testStyles()
  30. {
  31. $paragraph = array('align' => 'center');
  32. $font = array('italic' => true, '_bold' => true);
  33. $table = array('bgColor' => 'CCCCCC');
  34. $styles = array('Paragraph' => 'Paragraph', 'Font' => 'Font',
  35. 'Link' => 'Font', 'Table' => 'Table',
  36. 'Heading_1' => 'Font', 'Normal' => 'Paragraph');
  37. $elementCount = 6;
  38. Style::addParagraphStyle('Paragraph', $paragraph);
  39. Style::addFontStyle('Font', $font);
  40. Style::addLinkStyle('Link', $font);
  41. Style::addTableStyle('Table', $table);
  42. Style::addTitleStyle(1, $font);
  43. Style::setDefaultParagraphStyle($paragraph);
  44. $this->assertEquals($elementCount, count(Style::getStyles()));
  45. foreach ($styles as $name => $style) {
  46. $this->assertInstanceOf("PhpOffice\\PhpWord\\Style\\{$style}", Style::getStyle($name));
  47. }
  48. $this->assertNull(Style::getStyle('Unknown'));
  49. Style::resetStyles();
  50. $this->assertEquals(0, count(Style::getStyles()));
  51. }
  52. /**
  53. * Set default paragraph style
  54. */
  55. public function testDefaultParagraphStyle()
  56. {
  57. $paragraph = array('align' => 'center');
  58. Style::setDefaultParagraphStyle($paragraph);
  59. $this->assertInstanceOf("PhpOffice\\PhpWord\\Style\\Paragraph", Style::getStyle('Normal'));
  60. }
  61. }