|
| 1 | +<?php |
| 2 | +namespace PHPWord\Tests; |
| 3 | + |
| 4 | +use PHPUnit_Framework_TestCase; |
| 5 | +use PHPWord; |
| 6 | +use PHPWord_Writer_Word2007_Styles; |
| 7 | + |
| 8 | +/** |
| 9 | + * Class PHPWord_Writer_Word2007_StylesTest |
| 10 | + * @package PHPWord\Tests |
| 11 | + * @runTestsInSeparateProcesses |
| 12 | + */ |
| 13 | +class PHPWord_Writer_Word2007_StylesTest extends \PHPUnit_Framework_TestCase |
| 14 | +{ |
| 15 | + /** |
| 16 | + * Executed before each method of the class |
| 17 | + */ |
| 18 | + public function tearDown() |
| 19 | + { |
| 20 | + TestHelperDOCX::clear(); |
| 21 | + } |
| 22 | + |
| 23 | + /** |
| 24 | + * Test write styles |
| 25 | + */ |
| 26 | + public function testWriteStyles() |
| 27 | + { |
| 28 | + $PHPWord = new PHPWord(); |
| 29 | + |
| 30 | + $defaultStyle = array('align' => 'both'); |
| 31 | + $baseStyle = array('basedOn' => 'Normal'); |
| 32 | + $newStyle = array('basedOn' => 'Base Style', 'next' => 'Normal'); |
| 33 | + $PHPWord->setDefaultParagraphStyle($defaultStyle); |
| 34 | + $PHPWord->addParagraphStyle('Base Style', $baseStyle); |
| 35 | + $PHPWord->addParagraphStyle('New Style', $newStyle); |
| 36 | + $doc = TestHelperDOCX::getDocument($PHPWord); |
| 37 | + $file = 'word/styles.xml'; |
| 38 | + |
| 39 | + // Normal style generated? |
| 40 | + $path = '/w:styles/w:style[@w:styleId="Normal"]/w:name'; |
| 41 | + $element = $doc->getElement($path, $file); |
| 42 | + $this->assertEquals('Normal', $element->getAttribute('w:val')); |
| 43 | + |
| 44 | + // Parent style referenced? |
| 45 | + $path = '/w:styles/w:style[@w:styleId="New Style"]/w:basedOn'; |
| 46 | + $element = $doc->getElement($path, $file); |
| 47 | + $this->assertEquals('Base Style', $element->getAttribute('w:val')); |
| 48 | + |
| 49 | + // Next paragraph style correct? |
| 50 | + $path = '/w:styles/w:style[@w:styleId="New Style"]/w:next'; |
| 51 | + $element = $doc->getElement($path, $file); |
| 52 | + $this->assertEquals('Normal', $element->getAttribute('w:val')); |
| 53 | + } |
| 54 | + |
| 55 | +} |
0 commit comments