@@ -218,58 +218,51 @@ public function testSetImageValue()
218
218
219
219
$ docName = 'header-footer-images-test-result.docx ' ;
220
220
$ templateProcessor ->saveAs ($ docName );
221
- $ docFound = file_exists ($ docName );
222
221
223
- if ($ docFound ) {
224
- $ expectedDocumentZip = new \ZipArchive ();
225
- $ expectedDocumentZip ->open ($ docName );
226
- $ expectedContentTypesXml = $ expectedDocumentZip ->getFromName ('[Content_Types].xml ' );
227
- $ expectedDocumentRelationsXml = $ expectedDocumentZip ->getFromName ('word/_rels/document.xml.rels ' );
228
- $ expectedHeaderRelationsXml = $ expectedDocumentZip ->getFromName ('word/_rels/header1.xml.rels ' );
229
- $ expectedFooterRelationsXml = $ expectedDocumentZip ->getFromName ('word/_rels/footer1.xml.rels ' );
230
- $ expectedMainPartXml = $ expectedDocumentZip ->getFromName ('word/document.xml ' );
231
- $ expectedHeaderPartXml = $ expectedDocumentZip ->getFromName ('word/header1.xml ' );
232
- $ expectedFooterPartXml = $ expectedDocumentZip ->getFromName ('word/footer1.xml ' );
233
- $ expectedImage = $ expectedDocumentZip ->getFromName ('word/media/image_rId11_document.jpeg ' );
234
- if (false === $ expectedDocumentZip ->close ()) {
235
- throw new \Exception ("Could not close zip file \"{$ docName }\". " );
236
- }
237
-
238
- $ this ->assertTrue (!empty ($ expectedImage ), 'Embed image doesn \'t found. ' );
239
- $ this ->assertTrue (strpos ($ expectedContentTypesXml , '/word/media/image_rId11_document.jpeg ' ) > 0 , '[Content_Types].xml missed "/word/media/image5_document.jpeg" ' );
240
- $ this ->assertTrue (strpos ($ expectedContentTypesXml , '/word/_rels/header1.xml.rels ' ) > 0 , '[Content_Types].xml missed "/word/_rels/header1.xml.rels" ' );
241
- $ this ->assertTrue (strpos ($ expectedContentTypesXml , '/word/_rels/footer1.xml.rels ' ) > 0 , '[Content_Types].xml missed "/word/_rels/footer1.xml.rels" ' );
242
- $ this ->assertTrue (strpos ($ expectedMainPartXml , '${documentContent} ' ) === false , 'word/document.xml has no image. ' );
243
- $ this ->assertTrue (strpos ($ expectedHeaderPartXml , '${headerValue} ' ) === false , 'word/header1.xml has no image. ' );
244
- $ this ->assertTrue (strpos ($ expectedFooterPartXml , '${footerValue} ' ) === false , 'word/footer1.xml has no image. ' );
245
- $ this ->assertTrue (strpos ($ expectedDocumentRelationsXml , 'media/image_rId11_document.jpeg ' ) > 0 , 'word/_rels/document.xml.rels missed "media/image5_document.jpeg" ' );
246
- $ this ->assertTrue (strpos ($ expectedHeaderRelationsXml , 'media/image_rId11_document.jpeg ' ) > 0 , 'word/_rels/header1.xml.rels missed "media/image5_document.jpeg" ' );
247
- $ this ->assertTrue (strpos ($ expectedFooterRelationsXml , 'media/image_rId11_document.jpeg ' ) > 0 , 'word/_rels/footer1.xml.rels missed "media/image5_document.jpeg" ' );
248
-
249
- unlink ($ docName );
250
- } else {
251
- throw new \Exception ("Generated file ' {$ docName }' not found! " );
222
+ $ this ->assertFileExists ($ docName , "Generated file ' {$ docName }' not found! " );
223
+
224
+ $ expectedDocumentZip = new \ZipArchive ();
225
+ $ expectedDocumentZip ->open ($ docName );
226
+ $ expectedContentTypesXml = $ expectedDocumentZip ->getFromName ('[Content_Types].xml ' );
227
+ $ expectedDocumentRelationsXml = $ expectedDocumentZip ->getFromName ('word/_rels/document.xml.rels ' );
228
+ $ expectedHeaderRelationsXml = $ expectedDocumentZip ->getFromName ('word/_rels/header1.xml.rels ' );
229
+ $ expectedFooterRelationsXml = $ expectedDocumentZip ->getFromName ('word/_rels/footer1.xml.rels ' );
230
+ $ expectedMainPartXml = $ expectedDocumentZip ->getFromName ('word/document.xml ' );
231
+ $ expectedHeaderPartXml = $ expectedDocumentZip ->getFromName ('word/header1.xml ' );
232
+ $ expectedFooterPartXml = $ expectedDocumentZip ->getFromName ('word/footer1.xml ' );
233
+ $ expectedImage = $ expectedDocumentZip ->getFromName ('word/media/image_rId11_document.jpeg ' );
234
+ if (false === $ expectedDocumentZip ->close ()) {
235
+ throw new \Exception ("Could not close zip file \"{$ docName }\". " );
252
236
}
253
237
238
+ $ this ->assertNotEmpty ($ expectedImage , 'Embed image doesn \'t found. ' );
239
+ $ this ->assertStringContainsString ('/word/media/image_rId11_document.jpeg ' , $ expectedContentTypesXml , '[Content_Types].xml missed "/word/media/image5_document.jpeg" ' );
240
+ $ this ->assertStringContainsString ('/word/_rels/header1.xml.rels ' , $ expectedContentTypesXml , '[Content_Types].xml missed "/word/_rels/header1.xml.rels" ' );
241
+ $ this ->assertStringContainsString ('/word/_rels/footer1.xml.rels ' , $ expectedContentTypesXml , '[Content_Types].xml missed "/word/_rels/footer1.xml.rels" ' );
242
+ $ this ->assertStringNotContainsString ('${documentContent} ' , $ expectedMainPartXml , 'word/document.xml has no image. ' );
243
+ $ this ->assertStringNotContainsString ('${headerValue} ' , $ expectedHeaderPartXml , 'word/header1.xml has no image. ' );
244
+ $ this ->assertStringNotContainsString ('${footerValue} ' , $ expectedFooterPartXml , 'word/footer1.xml has no image. ' );
245
+ $ this ->assertStringContainsString ('media/image_rId11_document.jpeg ' , $ expectedDocumentRelationsXml , 'word/_rels/document.xml.rels missed "media/image5_document.jpeg" ' );
246
+ $ this ->assertStringContainsString ('media/image_rId11_document.jpeg ' , $ expectedHeaderRelationsXml , 'word/_rels/header1.xml.rels missed "media/image5_document.jpeg" ' );
247
+ $ this ->assertStringContainsString ('media/image_rId11_document.jpeg ' , $ expectedFooterRelationsXml , 'word/_rels/footer1.xml.rels missed "media/image5_document.jpeg" ' );
248
+
249
+ unlink ($ docName );
250
+
254
251
// dynamic generated doc
255
252
$ testFileName = 'images-test-sample.docx ' ;
256
253
$ phpWord = new \PhpOffice \PhpWord \PhpWord ();
257
254
$ section = $ phpWord ->addSection ();
258
255
$ section ->addText ('${Test} --- ${Test} ' );
259
256
$ objWriter = \PhpOffice \PhpWord \IOFactory::createWriter ($ phpWord , 'Word2007 ' );
260
257
$ objWriter ->save ($ testFileName );
261
- if (!file_exists ($ testFileName )) {
262
- throw new \Exception ("Generated file ' {$ testFileName }' not found! " );
263
- }
258
+ $ this ->assertFileExists ($ testFileName , "Generated file ' {$ testFileName }' not found! " );
264
259
265
260
$ resultFileName = 'images-test-result.docx ' ;
266
261
$ templateProcessor = new \PhpOffice \PhpWord \TemplateProcessor ($ testFileName );
267
262
unlink ($ testFileName );
268
263
$ templateProcessor ->setImageValue ('Test ' , $ imagePath );
269
264
$ templateProcessor ->saveAs ($ resultFileName );
270
- if (!file_exists ($ resultFileName )) {
271
- throw new \Exception ("Generated file ' {$ resultFileName }' not found! " );
272
- }
265
+ $ this ->assertFileExists ($ resultFileName , "Generated file ' {$ resultFileName }' not found! " );
273
266
274
267
$ expectedDocumentZip = new \ZipArchive ();
275
268
$ expectedDocumentZip ->open ($ resultFileName );
@@ -279,7 +272,7 @@ public function testSetImageValue()
279
272
}
280
273
unlink ($ resultFileName );
281
274
282
- $ this ->assertTrue ( strpos ( $ expectedMainPartXml , '${Test} ' ) === false , 'word/document.xml has no image. ' );
275
+ $ this ->assertStringNotContainsString ( '${Test} ' , $ expectedMainPartXml , 'word/document.xml has no image. ' );
283
276
}
284
277
285
278
/**
0 commit comments