File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed
tests/PhpWordTests/Writer Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -52,14 +52,15 @@ public function __construct(?PhpWord $phpWord = null)
52
52
$ this ->setPhpWord ($ phpWord );
53
53
54
54
// Create parts
55
+ // The first four files need to be in this order for Mimetype detection to work
55
56
$ this ->parts = [
56
57
'ContentTypes ' => '[Content_Types].xml ' ,
57
58
'Rels ' => '_rels/.rels ' ,
59
+ 'RelsDocument ' => 'word/_rels/document.xml.rels ' ,
60
+ 'Document ' => 'word/document.xml ' ,
58
61
'DocPropsApp ' => 'docProps/app.xml ' ,
59
62
'DocPropsCore ' => 'docProps/core.xml ' ,
60
63
'DocPropsCustom ' => 'docProps/custom.xml ' ,
61
- 'RelsDocument ' => 'word/_rels/document.xml.rels ' ,
62
- 'Document ' => 'word/document.xml ' ,
63
64
'Comments ' => 'word/comments.xml ' ,
64
65
'Styles ' => 'word/styles.xml ' ,
65
66
'Numbering ' => 'word/numbering.xml ' ,
Original file line number Diff line number Diff line change 17
17
18
18
namespace PhpOffice \PhpWordTests \Writer ;
19
19
20
+ use finfo ;
20
21
use PhpOffice \PhpWord \PhpWord ;
21
22
use PhpOffice \PhpWord \SimpleType \Jc ;
22
23
use PhpOffice \PhpWord \Writer \Word2007 ;
@@ -192,4 +193,25 @@ public function testSetUseDiskCachingException(): void
192
193
$ object = new Word2007 ();
193
194
$ object ->setUseDiskCaching (true , $ dir );
194
195
}
196
+
197
+ /**
198
+ * File is detected as Word 2007.
199
+ */
200
+ public function testMime (): void
201
+ {
202
+ $ phpWord = new PhpWord ();
203
+ $ section = $ phpWord ->addSection ();
204
+ $ section ->addText ('Test 1 ' );
205
+
206
+ $ writer = new Word2007 ($ phpWord );
207
+ $ file = __DIR__ . '/../_files/temp.docx ' ;
208
+ $ writer ->save ($ file );
209
+
210
+ $ finfo = new finfo (FILEINFO_MIME_TYPE );
211
+ $ mime = $ finfo ->file ($ file );
212
+
213
+ self ::assertEquals ('application/vnd.openxmlformats-officedocument.wordprocessingml.document ' , $ mime );
214
+
215
+ unlink ($ file );
216
+ }
195
217
}
You can’t perform that action at this time.
0 commit comments