2525 */
2626class SettingsTest extends \PHPUnit \Framework \TestCase
2727{
28+ private $ compatibility ;
29+ private $ defaultFontSize ;
30+ private $ defaultFontName ;
31+ private $ defaultPaper ;
32+ private $ measurementUnit ;
33+ private $ outputEscapingEnabled ;
34+ private $ pdfRendererName ;
35+ private $ pdfRendererPath ;
36+ private $ tempDir ;
37+ private $ zipClass ;
38+
39+ public function setUp ()
40+ {
41+ $ this ->compatibility = Settings::hasCompatibility ();
42+ $ this ->defaultFontSize = Settings::getDefaultFontSize ();
43+ $ this ->defaultFontName = Settings::getDefaultFontName ();
44+ $ this ->defaultPaper = Settings::getDefaultPaper ();
45+ $ this ->measurementUnit = Settings::getMeasurementUnit ();
46+ $ this ->outputEscapingEnabled = Settings::isOutputEscapingEnabled ();
47+ $ this ->pdfRendererName = Settings::getPdfRendererName ();
48+ $ this ->pdfRendererPath = Settings::getPdfRendererPath ();
49+ $ this ->tempDir = Settings::getTempDir ();
50+ $ this ->zipClass = Settings::getZipClass ();
51+ }
52+
53+ public function tearDown ()
54+ {
55+ Settings::setCompatibility ($ this ->compatibility );
56+ Settings::setDefaultFontSize ($ this ->defaultFontSize );
57+ Settings::setDefaultFontName ($ this ->defaultFontName );
58+ Settings::setDefaultPaper ($ this ->defaultPaper );
59+ Settings::setMeasurementUnit ($ this ->measurementUnit );
60+ Settings::setOutputEscapingEnabled ($ this ->outputEscapingEnabled );
61+ Settings::setPdfRendererName ($ this ->pdfRendererName );
62+ Settings::setPdfRendererPath ($ this ->pdfRendererPath );
63+ Settings::setTempDir ($ this ->tempDir );
64+ Settings::setZipClass ($ this ->zipClass );
65+ }
66+
2867 /**
2968 * Test set/get compatibity option
3069 */
@@ -35,14 +74,28 @@ public function testSetGetCompatibility()
3574 $ this ->assertFalse (Settings::hasCompatibility ());
3675 }
3776
77+ /**
78+ * Test set/get outputEscapingEnabled option
79+ */
80+ public function testSetGetOutputEscapingEnabled ()
81+ {
82+ $ this ->assertFalse (Settings::isOutputEscapingEnabled ());
83+ Settings::setOutputEscapingEnabled (true );
84+ $ this ->assertTrue (Settings::isOutputEscapingEnabled ());
85+ }
86+
3887 /**
3988 * Test set/get zip class
4089 */
4190 public function testSetGetZipClass ()
4291 {
92+ $ this ->assertEquals (Settings::ZIPARCHIVE , Settings::getZipClass ());
93+ $ this ->assertFalse (Settings::setZipClass ('foo ' ));
4394 $ this ->assertEquals (Settings::ZIPARCHIVE , Settings::getZipClass ());
4495 $ this ->assertTrue (Settings::setZipClass (Settings::PCLZIP ));
96+ $ this ->assertEquals (Settings::getZipClass (), Settings::PCLZIP );
4597 $ this ->assertFalse (Settings::setZipClass ('foo ' ));
98+ $ this ->assertEquals (Settings::getZipClass (), Settings::PCLZIP );
4699 }
47100
48101 /**
@@ -57,16 +110,21 @@ public function testSetGetPdfRenderer()
57110 $ this ->assertEquals (Settings::PDF_RENDERER_DOMPDF , Settings::getPdfRendererName ());
58111 $ this ->assertEquals ($ domPdfPath , Settings::getPdfRendererPath ());
59112 $ this ->assertFalse (Settings::setPdfRendererPath ('dummy/path ' ));
113+ $ this ->assertEquals ($ domPdfPath , Settings::getPdfRendererPath ());
60114 }
61115
62116 /**
63117 * Test set/get measurement unit
64118 */
65119 public function testSetGetMeasurementUnit ()
66120 {
121+ $ this ->assertEquals (Settings::UNIT_TWIP , Settings::getMeasurementUnit ());
122+ $ this ->assertFalse (Settings::setMeasurementUnit ('foo ' ));
67123 $ this ->assertEquals (Settings::UNIT_TWIP , Settings::getMeasurementUnit ());
68124 $ this ->assertTrue (Settings::setMeasurementUnit (Settings::UNIT_INCH ));
125+ $ this ->assertEquals (Settings::UNIT_INCH , Settings::getMeasurementUnit ());
69126 $ this ->assertFalse (Settings::setMeasurementUnit ('foo ' ));
127+ $ this ->assertEquals (Settings::UNIT_INCH , Settings::getMeasurementUnit ());
70128 }
71129
72130 /**
@@ -98,19 +156,50 @@ public function testTempDirCanBeSet()
98156 */
99157 public function testSetGetDefaultFontName ()
100158 {
159+ $ this ->assertEquals (Settings::DEFAULT_FONT_NAME , Settings::getDefaultFontName ());
160+ $ this ->assertFalse (Settings::setDefaultFontName (' ' ));
101161 $ this ->assertEquals (Settings::DEFAULT_FONT_NAME , Settings::getDefaultFontName ());
102162 $ this ->assertTrue (Settings::setDefaultFontName ('Times New Roman ' ));
163+ $ this ->assertEquals ('Times New Roman ' , Settings::getDefaultFontName ());
103164 $ this ->assertFalse (Settings::setDefaultFontName (' ' ));
165+ $ this ->assertEquals ('Times New Roman ' , Settings::getDefaultFontName ());
104166 }
105167
106168 /**
107169 * Test set/get default font size
108170 */
109171 public function testSetGetDefaultFontSize ()
110172 {
173+ $ this ->assertEquals (Settings::DEFAULT_FONT_SIZE , Settings::getDefaultFontSize ());
174+ $ this ->assertFalse (Settings::setDefaultFontSize (null ));
111175 $ this ->assertEquals (Settings::DEFAULT_FONT_SIZE , Settings::getDefaultFontSize ());
112176 $ this ->assertTrue (Settings::setDefaultFontSize (12 ));
177+ $ this ->assertEquals (12 , Settings::getDefaultFontSize ());
113178 $ this ->assertFalse (Settings::setDefaultFontSize (null ));
179+ $ this ->assertEquals (12 , Settings::getDefaultFontSize ());
180+ }
181+
182+ /**
183+ * Test set/get default paper
184+ */
185+ public function testSetGetDefaultPaper ()
186+ {
187+ $ dflt = Settings::DEFAULT_PAPER ;
188+ $ chng = ($ dflt === 'A4 ' ) ? 'Letter ' : 'A4 ' ;
189+ $ doc = new PhpWord ();
190+ $ this ->assertEquals ($ dflt , Settings::getDefaultPaper ());
191+ $ sec1 = $ doc ->addSection ();
192+ $ this ->assertEquals ($ dflt , $ sec1 ->getStyle ()->getPaperSize ());
193+ $ this ->assertFalse (Settings::setDefaultPaper ('' ));
194+ $ this ->assertEquals ($ dflt , Settings::getDefaultPaper ());
195+ $ this ->assertTrue (Settings::setDefaultPaper ($ chng ));
196+ $ this ->assertEquals ($ chng , Settings::getDefaultPaper ());
197+ $ sec2 = $ doc ->addSection ();
198+ $ this ->assertEquals ($ chng , $ sec2 ->getStyle ()->getPaperSize ());
199+ $ sec3 = $ doc ->addSection (array ('paperSize ' => 'Legal ' ));
200+ $ this ->assertEquals ('Legal ' , $ sec3 ->getStyle ()->getPaperSize ());
201+ $ this ->assertFalse (Settings::setDefaultPaper ('' ));
202+ $ this ->assertEquals ($ chng , Settings::getDefaultPaper ());
114203 }
115204
116205 /**
@@ -126,13 +215,24 @@ public function testLoadConfig()
126215 'defaultFontName ' => 'Arial ' ,
127216 'defaultFontSize ' => 10 ,
128217 'outputEscapingEnabled ' => false ,
218+ 'defaultPaper ' => 'A4 ' ,
129219 );
130220
131221 // Test default value
132222 $ this ->assertEquals ($ expected , Settings::loadConfig ());
133223
134224 // Test with valid file
135225 $ this ->assertEquals ($ expected , Settings::loadConfig (__DIR__ . '/../../phpword.ini.dist ' ));
226+ foreach ($ expected as $ key => $ value ) {
227+ if ($ key === 'compatibility ' ) {
228+ $ meth = 'hasCompatibility ' ;
229+ } elseif ($ key === 'outputEscapingEnabled ' ) {
230+ $ meth = 'isOutputEscapingEnabled ' ;
231+ } else {
232+ $ meth = 'get ' . ucfirst ($ key );
233+ }
234+ $ this ->assertEquals (Settings::$ meth (), $ value );
235+ }
136236
137237 // Test with invalid file
138238 $ this ->assertEmpty (Settings::loadConfig (__DIR__ . '/../../phpunit.xml.dist ' ));
0 commit comments