@@ -28,7 +28,7 @@ public function tearDown()
28
28
}
29
29
30
30
/**
31
- * covers ::_writeText
31
+ * Test write text element
32
32
*/
33
33
public function testWriteText ()
34
34
{
@@ -49,7 +49,7 @@ public function testWriteText()
49
49
}
50
50
51
51
/**
52
- * covers ::_writeTextRun
52
+ * Test write textrun element
53
53
*/
54
54
public function testWriteTextRun ()
55
55
{
@@ -74,7 +74,7 @@ public function testWriteTextRun()
74
74
}
75
75
76
76
/**
77
- * covers ::_writeLink
77
+ * Test write link element
78
78
*/
79
79
public function testWriteLink ()
80
80
{
@@ -97,7 +97,7 @@ public function testWriteLink()
97
97
}
98
98
99
99
/**
100
- * covers ::_writePreserveText
100
+ * Test write preserve text element
101
101
*/
102
102
public function testWritePreserveText ()
103
103
{
@@ -121,7 +121,7 @@ public function testWritePreserveText()
121
121
}
122
122
123
123
/**
124
- * covers ::_writeTextBreak
124
+ * Test write text break
125
125
*/
126
126
public function testWriteTextBreak ()
127
127
{
@@ -146,30 +146,93 @@ public function testWriteTextBreak()
146
146
}
147
147
148
148
/**
149
- * covers ::_writeParagraphStyle
149
+ * covers ::_writeImage
150
150
*/
151
- public function testWriteParagraphStyleAlign ()
151
+ public function testWriteImage ()
152
152
{
153
153
$ phpWord = new PhpWord ();
154
+ $ styles = array ('align ' => 'left ' , 'width ' => 40 , 'height ' => 40 , 'marginTop ' => -1 , 'marginLeft ' => -1 );
155
+ $ wraps = array ('inline ' , 'behind ' , 'infront ' , 'square ' , 'tight ' );
154
156
$ section = $ phpWord ->addSection ();
157
+ foreach ($ wraps as $ wrap ) {
158
+ $ styles ['wrappingStyle ' ] = $ wrap ;
159
+ $ section ->addImage (__DIR__ . "/../../_files/images/earth.jpg " , $ styles );
160
+ }
161
+
162
+ $ doc = TestHelperDOCX::getDocument ($ phpWord );
163
+
164
+ // behind
165
+ $ element = $ doc ->getElement ('/w:document/w:body/w:p[2]/w:r/w:pict/v:shape ' );
166
+ $ style = $ element ->getAttribute ('style ' );
167
+ $ this ->assertRegExp ('/z\-index:\-[0-9]*/ ' , $ style );
168
+
169
+ // square
170
+ $ element = $ doc ->getElement ('/w:document/w:body/w:p[4]/w:r/w:pict/v:shape/w10:wrap ' );
171
+ $ this ->assertEquals ('square ' , $ element ->getAttribute ('type ' ));
172
+ }
173
+
174
+ /**
175
+ * covers ::_writeWatermark
176
+ */
177
+ public function testWriteWatermark ()
178
+ {
179
+ $ imageSrc = __DIR__ . "/../../_files/images/earth.jpg " ;
180
+
181
+ $ phpWord = new PhpWord ();
182
+ $ section = $ phpWord ->addSection ();
183
+ $ header = $ section ->addHeader ();
184
+ $ header ->addWatermark ($ imageSrc );
185
+ $ doc = TestHelperDOCX::getDocument ($ phpWord );
186
+
187
+ $ element = $ doc ->getElement ("/w:document/w:body/w:sectPr/w:headerReference " );
188
+ $ this ->assertStringStartsWith ("rId " , $ element ->getAttribute ('r:id ' ));
189
+ }
190
+
191
+ /**
192
+ * covers ::_writeTitle
193
+ */
194
+ public function testWriteTitle ()
195
+ {
196
+ $ phpWord = new PhpWord ();
197
+ $ phpWord ->addTitleStyle (1 , array ('bold ' => true ), array ('spaceAfter ' => 240 ));
198
+ $ phpWord ->addSection ()->addTitle ('Test ' , 1 );
199
+ $ doc = TestHelperDOCX::getDocument ($ phpWord );
155
200
156
- $ section ->addText ('This is my text ' , null , array ('align ' => 'right ' ));
201
+ $ element = "/w:document/w:body/w:p/w:pPr/w:pStyle " ;
202
+ $ this ->assertEquals ('Heading1 ' , $ doc ->getElementAttribute ($ element , 'w:val ' ));
203
+ $ element = "/w:document/w:body/w:p/w:r/w:fldChar " ;
204
+ $ this ->assertEquals ('end ' , $ doc ->getElementAttribute ($ element , 'w:fldCharType ' ));
205
+ }
157
206
207
+ /**
208
+ * covers ::_writeCheckbox
209
+ */
210
+ public function testWriteCheckbox ()
211
+ {
212
+ $ rStyle = 'rStyle ' ;
213
+ $ pStyle = 'pStyle ' ;
214
+
215
+ $ phpWord = new PhpWord ();
216
+ $ phpWord ->addFontStyle ($ rStyle , array ('bold ' => true ));
217
+ $ phpWord ->addParagraphStyle ($ pStyle , array ('hanging ' => 120 , 'indent ' => 120 ));
218
+ $ section = $ phpWord ->addSection ();
219
+ $ section ->addCheckbox ('Check1 ' , 'Test ' , $ rStyle , $ pStyle );
158
220
$ doc = TestHelperDOCX::getDocument ($ phpWord );
159
- $ element = $ doc ->getElement ('/w:document/w:body/w:p/w:pPr/w:jc ' );
160
221
161
- $ this ->assertEquals ('right ' , $ element ->getAttribute ('w:val ' ));
222
+ $ element = '/w:document/w:body/w:p/w:r/w:fldChar/w:ffData/w:name ' ;
223
+ $ this ->assertEquals ('Check1 ' , $ doc ->getElementAttribute ($ element , 'w:val ' ));
162
224
}
163
225
164
226
/**
165
227
* covers ::_writeParagraphStyle
166
228
*/
167
- public function testWriteParagraphStylePagination ()
229
+ public function testWriteParagraphStyle ()
168
230
{
169
231
// Create the doc
170
232
$ phpWord = new PhpWord ();
171
233
$ section = $ phpWord ->addSection ();
172
234
$ attributes = array (
235
+ 'align ' => 'right ' ,
173
236
'widowControl ' => false ,
174
237
'keepNext ' => true ,
175
238
'keepLines ' => true ,
@@ -184,10 +247,13 @@ public function testWriteParagraphStylePagination()
184
247
$ i = 0 ;
185
248
foreach ($ attributes as $ key => $ value ) {
186
249
$ i ++;
187
- $ path = "/w:document/w:body/w:p[ {$ i }]/w:pPr/w: {$ key }" ;
250
+ $ nodeName = ($ key == 'align ' ) ? 'jc ' : $ key ;
251
+ $ path = "/w:document/w:body/w:p[ {$ i }]/w:pPr/w: {$ nodeName }" ;
252
+ if ($ key != 'align ' ) {
253
+ $ value = $ value ? 1 : 0 ;
254
+ }
188
255
$ element = $ doc ->getElement ($ path );
189
- $ expected = $ value ? 1 : 0 ;
190
- $ this ->assertEquals ($ expected , $ element ->getAttribute ('w:val ' ));
256
+ $ this ->assertEquals ($ value , $ element ->getAttribute ('w:val ' ));
191
257
}
192
258
}
193
259
@@ -316,81 +382,4 @@ public function testWriteCellStyleCellGridSpan()
316
382
317
383
$ this ->assertEquals (5 , $ element ->getAttribute ('w:val ' ));
318
384
}
319
-
320
- /**
321
- * covers ::_writeImage
322
- */
323
- public function testWriteImagePosition ()
324
- {
325
- $ phpWord = new PhpWord ();
326
- $ section = $ phpWord ->addSection ();
327
- $ section ->addImage (
328
- __DIR__ . "/../../_files/images/earth.jpg " ,
329
- array (
330
- 'marginTop ' => -1 ,
331
- 'marginLeft ' => -1 ,
332
- 'wrappingStyle ' => 'behind '
333
- )
334
- );
335
-
336
- $ doc = TestHelperDOCX::getDocument ($ phpWord );
337
- $ element = $ doc ->getElement ('/w:document/w:body/w:p/w:r/w:pict/v:shape ' );
338
-
339
- $ style = $ element ->getAttribute ('style ' );
340
-
341
- $ this ->assertRegExp ('/z\-index:\-[0-9]*/ ' , $ style );
342
- $ this ->assertRegExp ('/position:absolute;/ ' , $ style );
343
- }
344
-
345
- /**
346
- * covers ::_writeWatermark
347
- */
348
- public function testWriteWatermark ()
349
- {
350
- $ imageSrc = __DIR__ . "/../../_files/images/earth.jpg " ;
351
-
352
- $ phpWord = new PhpWord ();
353
- $ section = $ phpWord ->addSection ();
354
- $ header = $ section ->addHeader ();
355
- $ header ->addWatermark ($ imageSrc );
356
- $ doc = TestHelperDOCX::getDocument ($ phpWord );
357
-
358
- $ element = $ doc ->getElement ("/w:document/w:body/w:sectPr/w:headerReference " );
359
- $ this ->assertStringStartsWith ("rId " , $ element ->getAttribute ('r:id ' ));
360
- }
361
-
362
- /**
363
- * covers ::_writeTitle
364
- */
365
- public function testWriteTitle ()
366
- {
367
- $ phpWord = new PhpWord ();
368
- $ phpWord ->addTitleStyle (1 , array ('bold ' => true ), array ('spaceAfter ' => 240 ));
369
- $ phpWord ->addSection ()->addTitle ('Test ' , 1 );
370
- $ doc = TestHelperDOCX::getDocument ($ phpWord );
371
-
372
- $ element = "/w:document/w:body/w:p/w:pPr/w:pStyle " ;
373
- $ this ->assertEquals ('Heading1 ' , $ doc ->getElementAttribute ($ element , 'w:val ' ));
374
- $ element = "/w:document/w:body/w:p/w:r/w:fldChar " ;
375
- $ this ->assertEquals ('end ' , $ doc ->getElementAttribute ($ element , 'w:fldCharType ' ));
376
- }
377
-
378
- /**
379
- * covers ::_writeCheckbox
380
- */
381
- public function testWriteCheckbox ()
382
- {
383
- $ rStyle = 'rStyle ' ;
384
- $ pStyle = 'pStyle ' ;
385
-
386
- $ phpWord = new PhpWord ();
387
- $ phpWord ->addFontStyle ($ rStyle , array ('bold ' => true ));
388
- $ phpWord ->addParagraphStyle ($ pStyle , array ('hanging ' => 120 , 'indent ' => 120 ));
389
- $ section = $ phpWord ->addSection ();
390
- $ section ->addCheckbox ('Check1 ' , 'Test ' , $ rStyle , $ pStyle );
391
- $ doc = TestHelperDOCX::getDocument ($ phpWord );
392
-
393
- $ element = '/w:document/w:body/w:p/w:r/w:fldChar/w:ffData/w:name ' ;
394
- $ this ->assertEquals ('Check1 ' , $ doc ->getElementAttribute ($ element , 'w:val ' ));
395
- }
396
385
}
0 commit comments