25
25
*/
26
26
class SettingsTest extends \PHPUnit \Framework \TestCase
27
27
{
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
+
28
67
/**
29
68
* Test set/get compatibity option
30
69
*/
@@ -35,14 +74,28 @@ public function testSetGetCompatibility()
35
74
$ this ->assertFalse (Settings::hasCompatibility ());
36
75
}
37
76
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
+
38
87
/**
39
88
* Test set/get zip class
40
89
*/
41
90
public function testSetGetZipClass ()
42
91
{
92
+ $ this ->assertEquals (Settings::ZIPARCHIVE , Settings::getZipClass ());
93
+ $ this ->assertFalse (Settings::setZipClass ('foo ' ));
43
94
$ this ->assertEquals (Settings::ZIPARCHIVE , Settings::getZipClass ());
44
95
$ this ->assertTrue (Settings::setZipClass (Settings::PCLZIP ));
96
+ $ this ->assertEquals (Settings::getZipClass (), Settings::PCLZIP );
45
97
$ this ->assertFalse (Settings::setZipClass ('foo ' ));
98
+ $ this ->assertEquals (Settings::getZipClass (), Settings::PCLZIP );
46
99
}
47
100
48
101
/**
@@ -57,16 +110,21 @@ public function testSetGetPdfRenderer()
57
110
$ this ->assertEquals (Settings::PDF_RENDERER_DOMPDF , Settings::getPdfRendererName ());
58
111
$ this ->assertEquals ($ domPdfPath , Settings::getPdfRendererPath ());
59
112
$ this ->assertFalse (Settings::setPdfRendererPath ('dummy/path ' ));
113
+ $ this ->assertEquals ($ domPdfPath , Settings::getPdfRendererPath ());
60
114
}
61
115
62
116
/**
63
117
* Test set/get measurement unit
64
118
*/
65
119
public function testSetGetMeasurementUnit ()
66
120
{
121
+ $ this ->assertEquals (Settings::UNIT_TWIP , Settings::getMeasurementUnit ());
122
+ $ this ->assertFalse (Settings::setMeasurementUnit ('foo ' ));
67
123
$ this ->assertEquals (Settings::UNIT_TWIP , Settings::getMeasurementUnit ());
68
124
$ this ->assertTrue (Settings::setMeasurementUnit (Settings::UNIT_INCH ));
125
+ $ this ->assertEquals (Settings::UNIT_INCH , Settings::getMeasurementUnit ());
69
126
$ this ->assertFalse (Settings::setMeasurementUnit ('foo ' ));
127
+ $ this ->assertEquals (Settings::UNIT_INCH , Settings::getMeasurementUnit ());
70
128
}
71
129
72
130
/**
@@ -98,19 +156,50 @@ public function testTempDirCanBeSet()
98
156
*/
99
157
public function testSetGetDefaultFontName ()
100
158
{
159
+ $ this ->assertEquals (Settings::DEFAULT_FONT_NAME , Settings::getDefaultFontName ());
160
+ $ this ->assertFalse (Settings::setDefaultFontName (' ' ));
101
161
$ this ->assertEquals (Settings::DEFAULT_FONT_NAME , Settings::getDefaultFontName ());
102
162
$ this ->assertTrue (Settings::setDefaultFontName ('Times New Roman ' ));
163
+ $ this ->assertEquals ('Times New Roman ' , Settings::getDefaultFontName ());
103
164
$ this ->assertFalse (Settings::setDefaultFontName (' ' ));
165
+ $ this ->assertEquals ('Times New Roman ' , Settings::getDefaultFontName ());
104
166
}
105
167
106
168
/**
107
169
* Test set/get default font size
108
170
*/
109
171
public function testSetGetDefaultFontSize ()
110
172
{
173
+ $ this ->assertEquals (Settings::DEFAULT_FONT_SIZE , Settings::getDefaultFontSize ());
174
+ $ this ->assertFalse (Settings::setDefaultFontSize (null ));
111
175
$ this ->assertEquals (Settings::DEFAULT_FONT_SIZE , Settings::getDefaultFontSize ());
112
176
$ this ->assertTrue (Settings::setDefaultFontSize (12 ));
177
+ $ this ->assertEquals (12 , Settings::getDefaultFontSize ());
113
178
$ 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 ());
114
203
}
115
204
116
205
/**
@@ -126,13 +215,24 @@ public function testLoadConfig()
126
215
'defaultFontName ' => 'Arial ' ,
127
216
'defaultFontSize ' => 10 ,
128
217
'outputEscapingEnabled ' => false ,
218
+ 'defaultPaper ' => 'A4 ' ,
129
219
);
130
220
131
221
// Test default value
132
222
$ this ->assertEquals ($ expected , Settings::loadConfig ());
133
223
134
224
// Test with valid file
135
225
$ 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
+ }
136
236
137
237
// Test with invalid file
138
238
$ this ->assertEmpty (Settings::loadConfig (__DIR__ . '/../../phpunit.xml.dist ' ));
0 commit comments