1717
1818namespace PhpOffice \PhpWordTests \Reader ;
1919
20+ use PhpOffice \PhpWord \Element \Image ;
21+ use PhpOffice \PhpWord \Element \TextRun ;
2022use PhpOffice \PhpWord \IOFactory ;
23+ use PhpOffice \PhpWord \PhpWord ;
2124use PhpOffice \PhpWord \Reader \Word2007 ;
2225use PhpOffice \PhpWordTests \TestHelperDOCX ;
2326
@@ -36,8 +39,7 @@ class Word2007Test extends \PHPUnit\Framework\TestCase
3639 public function testCanRead (): void
3740 {
3841 $ object = new Word2007 ();
39- $ filename = __DIR__ . '/../_files/documents/reader.docx ' ;
40- self ::assertTrue ($ object ->canRead ($ filename ));
42+ self ::assertTrue ($ object ->canRead (dirname (__DIR__ , 1 ) . '/_files/documents/reader.docx ' ));
4143 }
4244
4345 /**
@@ -46,19 +48,17 @@ public function testCanRead(): void
4648 public function testCanReadFailed (): void
4749 {
4850 $ object = new Word2007 ();
49- $ filename = __DIR__ . '/../_files/documents/foo.docx ' ;
50- self ::assertFalse ($ object ->canRead ($ filename ));
51+ self ::assertFalse ($ object ->canRead (dirname (__DIR__ , 1 ) . '/_files/documents/foo.docx ' ));
5152 }
5253
5354 /**
5455 * Load.
5556 */
5657 public function testLoad (): void
5758 {
58- $ filename = __DIR__ . '/../_files/documents/reader.docx ' ;
59- $ phpWord = IOFactory::load ($ filename );
59+ $ phpWord = IOFactory::load (dirname (__DIR__ , 1 ) . '/_files/documents/reader.docx ' , 'Word2007 ' );
6060
61- self ::assertInstanceOf (' PhpOffice \\ PhpWord \\ PhpWord ' , $ phpWord );
61+ self ::assertInstanceOf (PhpWord::class , $ phpWord );
6262 self ::assertTrue ($ phpWord ->getSettings ()->hasDoNotTrackMoves ());
6363 self ::assertFalse ($ phpWord ->getSettings ()->hasDoNotTrackFormatting ());
6464 self ::assertEquals (100 , $ phpWord ->getSettings ()->getZoom ());
@@ -72,12 +72,50 @@ public function testLoad(): void
7272 */
7373 public function testLoadWord2011 (): void
7474 {
75- $ filename = __DIR__ . ' /../_files/documents/reader-2011.docx ' ;
76- $ phpWord = IOFactory:: load ($ filename );
75+ $ reader = new Word2007 () ;
76+ $ phpWord = $ reader -> load (dirname ( __DIR__ , 1 ) . ' /_files/documents/reader-2011.docx ' );
7777
78- self ::assertInstanceOf (' PhpOffice \\ PhpWord \\ PhpWord ' , $ phpWord );
78+ self ::assertInstanceOf (PhpWord::class , $ phpWord );
7979
8080 $ doc = TestHelperDOCX::getDocument ($ phpWord );
8181 self ::assertTrue ($ doc ->elementExists ('/w:document/w:body/w:p[3]/w:r/w:pict/v:shape/v:imagedata ' ));
8282 }
83+
84+ /**
85+ * Load a Word without/withoutImages.
86+ *
87+ * @dataProvider providerSettingsImageLoading
88+ */
89+ public function testLoadWord2011SettingsImageLoading (bool $ hasImageLoading ): void
90+ {
91+ $ reader = new Word2007 ();
92+ $ reader ->setImageLoading ($ hasImageLoading );
93+ $ phpWord = $ reader ->load (dirname (__DIR__ , 1 ) . '/_files/documents/reader-2011.docx ' );
94+
95+ self ::assertInstanceOf (PhpWord::class, $ phpWord );
96+
97+ $ sections = $ phpWord ->getSections ();
98+ self ::assertCount (1 , $ sections );
99+ $ section = $ sections [0 ];
100+ $ elements = $ section ->getElements ();
101+ self ::assertCount (3 , $ elements );
102+ $ element = $ elements [2 ];
103+ self ::assertInstanceOf (TextRun::class, $ element );
104+ $ subElements = $ element ->getElements ();
105+ if ($ hasImageLoading ) {
106+ self ::assertCount (1 , $ subElements );
107+ $ subElement = $ subElements [0 ];
108+ self ::assertInstanceOf (Image::class, $ subElement );
109+ } else {
110+ self ::assertCount (0 , $ subElements );
111+ }
112+ }
113+
114+ public function providerSettingsImageLoading (): iterable
115+ {
116+ return [
117+ [true ],
118+ [false ],
119+ ];
120+ }
83121}
0 commit comments