|
32 | 32 | */
|
33 | 33 | class ODTextTest extends \PHPUnit\Framework\TestCase
|
34 | 34 | {
|
| 35 | + /** |
| 36 | + * Test default font name. |
| 37 | + */ |
| 38 | + public function testDefaultFontName(): void |
| 39 | + { |
| 40 | + $phpWordWriter = new PhpWord(); |
| 41 | + $testDefaultFontName = 'Times New Roman'; |
| 42 | + $phpWordWriter->setDefaultFontName($testDefaultFontName); |
| 43 | + |
| 44 | + $writer = new ODText($phpWordWriter); |
| 45 | + $file = __DIR__ . '/../_files/temp.odt'; |
| 46 | + $writer->save($file); |
| 47 | + |
| 48 | + self::assertFileExists($file); |
| 49 | + |
| 50 | + $phpWordWriter->setDefaultFontName('This text should not be set after reading back the file'); |
| 51 | + |
| 52 | + $phpWordReader = IOFactory::load($file, 'ODText'); |
| 53 | + |
| 54 | + self::assertEquals($testDefaultFontName, $phpWordReader->getDefaultFontName()); |
| 55 | + |
| 56 | + unlink($file); |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * Test default Asian font name. |
| 61 | + */ |
| 62 | + public function testDefaultAsianFontName(): void |
| 63 | + { |
| 64 | + $phpWordWriter = new PhpWord(); |
| 65 | + $testDefaultFontName = '標楷體'; |
| 66 | + $phpWordWriter->setDefaultAsianFontName($testDefaultFontName); |
| 67 | + |
| 68 | + $writer = new ODText($phpWordWriter); |
| 69 | + $file = __DIR__ . '/../_files/temp.odt'; |
| 70 | + $writer->save($file); |
| 71 | + |
| 72 | + self::assertFileExists($file); |
| 73 | + |
| 74 | + $phpWordWriter->setDefaultAsianFontName('This text should not be set after reading back the file'); |
| 75 | + |
| 76 | + $phpWordReader = IOFactory::load($file, 'ODText'); |
| 77 | + |
| 78 | + self::assertEquals($testDefaultFontName, $phpWordReader->getDefaultAsianFontName()); |
| 79 | + |
| 80 | + unlink($file); |
| 81 | + } |
| 82 | + |
| 83 | + /** |
| 84 | + * Test default font size. |
| 85 | + */ |
| 86 | + public function testDefaulFontSize(): void |
| 87 | + { |
| 88 | + $phpWordWriter = new PhpWord(); |
| 89 | + $testDefaultFontSize = 144; |
| 90 | + $phpWordWriter->setDefaultFontSize($testDefaultFontSize); |
| 91 | + |
| 92 | + $writer = new ODText($phpWordWriter); |
| 93 | + $file = __DIR__ . '/../_files/temp.odt'; |
| 94 | + $writer->save($file); |
| 95 | + |
| 96 | + self::assertFileExists($file); |
| 97 | + |
| 98 | + $phpWordWriter->setDefaultFontSize(987); //This value should not be set after reading back the file |
| 99 | + |
| 100 | + $phpWordReader = IOFactory::load($file, 'ODText'); |
| 101 | + |
| 102 | + self::assertEquals($testDefaultFontSize, $phpWordReader->getDefaultFontSize()); |
| 103 | + |
| 104 | + unlink($file); |
| 105 | + } |
| 106 | + |
| 107 | + /** |
| 108 | + * Test default font color. |
| 109 | + */ |
| 110 | + public function testDefaultFontColor(): void |
| 111 | + { |
| 112 | + $phpWordWriter = new PhpWord(); |
| 113 | + $testDefaultFontColor = '00FF00'; |
| 114 | + $phpWordWriter->setDefaultFontColor($testDefaultFontColor); |
| 115 | + |
| 116 | + $writer = new ODText($phpWordWriter); |
| 117 | + $file = __DIR__ . '/../_files/temp.odt'; |
| 118 | + $writer->save($file); |
| 119 | + |
| 120 | + self::assertFileExists($file); |
| 121 | + |
| 122 | + $phpWordWriter->setDefaultFontColor('C0FFEE'); //This value should not be set after reading back the file |
| 123 | + |
| 124 | + $phpWordReader = IOFactory::load($file, 'ODText'); |
| 125 | + |
| 126 | + self::assertEquals($testDefaultFontColor, $phpWordReader->getDefaultFontColor()); |
| 127 | + |
| 128 | + unlink($file); |
| 129 | + } |
| 130 | + |
35 | 131 | /**
|
36 | 132 | * Test a document with one section and text.
|
37 | 133 | */
|
|
0 commit comments