|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * This file is part of PHPWord - A pure PHP library for reading and writing |
| 5 | + * word processing documents. |
| 6 | + * |
| 7 | + * PHPWord is free software distributed under the terms of the GNU Lesser |
| 8 | + * General Public License version 3 as published by the Free Software Foundation. |
| 9 | + * |
| 10 | + * For the full copyright and license information, please read the LICENSE |
| 11 | + * file that was distributed with this source code. For the full list of |
| 12 | + * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. |
| 13 | + * |
| 14 | + * @see https://github.com/PHPOffice/PHPWord |
| 15 | + * |
| 16 | + * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
| 17 | + */ |
| 18 | + |
| 19 | +namespace PhpOffice\PhpWordTests\Writer\RTF\Style; |
| 20 | + |
| 21 | +use PhpOffice\PhpWord\PhpWord; |
| 22 | +use PhpOffice\PhpWord\SimpleType\VerticalJc; |
| 23 | +use PhpOffice\PhpWord\Writer\RTF; |
| 24 | +use PHPUnit\Framework\TestCase; |
| 25 | + |
| 26 | +class SectionTest extends TestCase |
| 27 | +{ |
| 28 | + /** @dataProvider verticalAlignProvider */ |
| 29 | + public function testVerticalAlign(string $vAlign, string $expect): void |
| 30 | + { |
| 31 | + $phpWord = new PhpWord(); |
| 32 | + $section = $phpWord->addSection(); |
| 33 | + $style = $section->getStyle(); |
| 34 | + $style->setVAlign($vAlign); |
| 35 | + $writer = new RTF($phpWord); |
| 36 | + self::assertStringContainsString($expect, $writer->getContent()); |
| 37 | + } |
| 38 | + |
| 39 | + public static function verticalAlignProvider(): array |
| 40 | + { |
| 41 | + return [ |
| 42 | + [VerticalJc::TOP, '\vertalt'], |
| 43 | + [VerticalJc::CENTER, '\vertalc'], |
| 44 | + [VerticalJc::BOTH, '\vertalj'], |
| 45 | + [VerticalJc::BOTTOM, '\vertalb'], |
| 46 | + ]; |
| 47 | + } |
| 48 | + |
| 49 | + public function testNoVerticalAlignNoBreakType(): void |
| 50 | + { |
| 51 | + $phpWord = new PhpWord(); |
| 52 | + $section = $phpWord->addSection(); |
| 53 | + $style = $section->getStyle(); |
| 54 | + $writer = new RTF($phpWord); |
| 55 | + $content = $writer->getContent(); |
| 56 | + self::assertStringNotContainsString('vert', $content); |
| 57 | + self::assertStringNotContainsString('sbk', $content); |
| 58 | + } |
| 59 | + |
| 60 | + /** @dataProvider breakTypeProvider */ |
| 61 | + public function testBreakType(string $breakType, string $expect): void |
| 62 | + { |
| 63 | + $phpWord = new PhpWord(); |
| 64 | + $section = $phpWord->addSection(); |
| 65 | + $style = $section->getStyle(); |
| 66 | + $style->setBreakType($breakType); |
| 67 | + $writer = new RTF($phpWord); |
| 68 | + $content = $writer->getContent(); |
| 69 | + self::assertStringContainsString($expect, $content); |
| 70 | + } |
| 71 | + |
| 72 | + public static function breakTypeProvider(): array |
| 73 | + { |
| 74 | + return [ |
| 75 | + ['nextPage', '\sbkpage'], |
| 76 | + ['nextColumn', '\sbkcol'], |
| 77 | + ['continuous', '\sbknone'], |
| 78 | + ['evenPage', '\sbkeven'], |
| 79 | + ['oddPage', '\sbkodd'], |
| 80 | + ]; |
| 81 | + } |
| 82 | + |
| 83 | + public function testColsNum(): void |
| 84 | + { |
| 85 | + $phpWord = new PhpWord(); |
| 86 | + $section = $phpWord->addSection(); |
| 87 | + $style = $section->getStyle(); |
| 88 | + $style->setColsNum(5); |
| 89 | + $style->setColsSpace(7); |
| 90 | + $writer = new RTF($phpWord); |
| 91 | + $content = $writer->getContent(); |
| 92 | + self::assertStringContainsString('\cols5', $content); |
| 93 | + self::assertStringContainsString('\colsx7', $content); |
| 94 | + } |
| 95 | + |
| 96 | + public function testPageSize(): void |
| 97 | + { |
| 98 | + $phpWord = new PhpWord(); |
| 99 | + $section = $phpWord->addSection(); |
| 100 | + $temp1 = $section->getStyle()->getOrientation(); |
| 101 | + self::assertSame('portrait', $temp1); |
| 102 | + $writer = new RTF($phpWord); |
| 103 | + $content = $writer->getContent(); |
| 104 | + |
| 105 | + self::assertStringContainsString('\sectd \pgwsxn11906\pghsxn16838', $content); |
| 106 | + $temp2 = $section->getStyle()->getOrientation(); |
| 107 | + self::assertSame('portrait', $temp2); |
| 108 | + } |
| 109 | + |
| 110 | + public function testPageSizeBookFold(): void |
| 111 | + { |
| 112 | + $phpWord = new PhpWord(); |
| 113 | + $section = $phpWord->addSection(); |
| 114 | + $phpWord->getSettings()->setBookFoldPrinting(true); |
| 115 | + $temp1 = $section->getStyle()->getOrientation(); |
| 116 | + self::assertSame('portrait', $temp1); |
| 117 | + $writer = new RTF($phpWord); |
| 118 | + $content = $writer->getContent(); |
| 119 | + |
| 120 | + self::assertStringContainsString('\sectd \pgwsxn8419\pghsxn11906', $content); |
| 121 | + $temp2 = $section->getStyle()->getOrientation(); |
| 122 | + self::assertSame('landscape', $temp2); |
| 123 | + } |
| 124 | +} |
0 commit comments