Няма описание

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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\Writer\Word2007\Part;
  18. use PhpOffice\PhpWord\PhpWord;
  19. use PhpOffice\PhpWord\Tests\TestHelperDOCX;
  20. use PhpOffice\PhpWord\Writer\Word2007\Part\Styles;
  21. /**
  22. * Test class for PhpOffice\PhpWord\Writer\Word2007\Part\Styles
  23. *
  24. * @coversDefaultClass \PhpOffice\PhpWord\Writer\Word2007\Part\Styles
  25. * @runTestsInSeparateProcesses
  26. */
  27. class StylesTest extends \PHPUnit_Framework_TestCase
  28. {
  29. /**
  30. * Executed before each method of the class
  31. */
  32. public function tearDown()
  33. {
  34. TestHelperDOCX::clear();
  35. }
  36. /**
  37. * Test write styles
  38. */
  39. public function testWriteStyles()
  40. {
  41. $phpWord = new PhpWord();
  42. $pStyle = array('align' => 'both');
  43. $pBase = array('basedOn' => 'Normal');
  44. $pNew = array('basedOn' => 'Base Style', 'next' => 'Normal');
  45. $rStyle = array('size' => 20);
  46. $tStyle = array(
  47. 'bgColor' => 'FF0000',
  48. 'cellMargin' => 120,
  49. 'borderSize' => 120,
  50. );
  51. $firstRowStyle = array(
  52. 'bgColor' => '0000FF',
  53. 'borderSize' => 120,
  54. 'borderColor' => '00FF00',
  55. );
  56. $phpWord->setDefaultParagraphStyle($pStyle);
  57. $phpWord->addParagraphStyle('Base Style', $pBase);
  58. $phpWord->addParagraphStyle('New Style', $pNew);
  59. $phpWord->addFontStyle('New Style', $rStyle, $pStyle);
  60. $phpWord->addTableStyle('Table Style', $tStyle, $firstRowStyle);
  61. $phpWord->addTitleStyle(1, $rStyle, $pStyle);
  62. $doc = TestHelperDOCX::getDocument($phpWord);
  63. $file = 'word/styles.xml';
  64. // Normal style generated?
  65. $path = '/w:styles/w:style[@w:styleId="Normal"]/w:name';
  66. $element = $doc->getElement($path, $file);
  67. $this->assertEquals('Normal', $element->getAttribute('w:val'));
  68. // Parent style referenced?
  69. $path = '/w:styles/w:style[@w:styleId="New Style"]/w:basedOn';
  70. $element = $doc->getElement($path, $file);
  71. $this->assertEquals('Base Style', $element->getAttribute('w:val'));
  72. // Next paragraph style correct?
  73. $path = '/w:styles/w:style[@w:styleId="New Style"]/w:next';
  74. $element = $doc->getElement($path, $file);
  75. $this->assertEquals('Normal', $element->getAttribute('w:val'));
  76. }
  77. }