24
24
*/
25
25
final class TemplateProcessorTest extends \PHPUnit \Framework \TestCase
26
26
{
27
+ /**
28
+ * Construct test
29
+ *
30
+ * @covers ::__construct
31
+ * @test
32
+ */
33
+ public function testTheConstruct ()
34
+ {
35
+ $ object = new TemplateProcessor (__DIR__ . '/_files/templates/blank.docx ' );
36
+ $ this ->assertInstanceOf ('PhpOffice \\PhpWord \\TemplateProcessor ' , $ object );
37
+ $ this ->assertEquals (array (), $ object ->getVariables ());
38
+ }
39
+
27
40
/**
28
41
* Template can be saved in temporary location.
29
42
*
30
43
* @covers ::save
44
+ * @covers ::zip
31
45
* @test
32
46
*/
33
47
final public function testTemplateCanBeSavedInTemporaryLocation ()
@@ -41,6 +55,8 @@ final public function testTemplateCanBeSavedInTemporaryLocation()
41
55
$ templateProcessor ->applyXslStyleSheet ($ xslDomDocument , array ('needle ' => $ needle ));
42
56
}
43
57
58
+ $ embeddingText = 'The quick Brown Fox jumped over the lazy^H^H^H^Htired unitTester ' ;
59
+ $ templateProcessor ->zip ()->AddFromString ('word/embeddings/fox.bin ' , $ embeddingText );
44
60
$ documentFqfn = $ templateProcessor ->save ();
45
61
46
62
$ this ->assertNotEmpty ($ documentFqfn , 'FQFN of the saved document is empty. ' );
@@ -60,13 +76,15 @@ final public function testTemplateCanBeSavedInTemporaryLocation()
60
76
$ documentHeaderXml = $ documentZip ->getFromName ('word/header1.xml ' );
61
77
$ documentMainPartXml = $ documentZip ->getFromName ('word/document.xml ' );
62
78
$ documentFooterXml = $ documentZip ->getFromName ('word/footer1.xml ' );
79
+ $ documentEmbedding = $ documentZip ->getFromName ('word/embeddings/fox.bin ' );
63
80
if (false === $ documentZip ->close ()) {
64
81
throw new \Exception ("Could not close zip file \"{$ documentZip }\". " );
65
82
}
66
83
67
84
$ this ->assertNotEquals ($ templateHeaderXml , $ documentHeaderXml );
68
85
$ this ->assertNotEquals ($ templateMainPartXml , $ documentMainPartXml );
69
86
$ this ->assertNotEquals ($ templateFooterXml , $ documentFooterXml );
87
+ $ this ->assertEquals ($ embeddingText , $ documentEmbedding );
70
88
71
89
return $ documentFqfn ;
72
90
}
@@ -178,6 +196,18 @@ public function testCloneRow()
178
196
$ this ->assertTrue ($ docFound );
179
197
}
180
198
199
+ /**
200
+ * @expectedException Exception
201
+ * @test
202
+ */
203
+ public function testCloneNotExistingRowShouldThrowException ()
204
+ {
205
+ $ mainPart = '<?xml version="1.0" encoding="UTF-8"?><w:p><w:r><w:rPr></w:rPr><w:t>text</w:t></w:r></w:p> ' ;
206
+ $ templateProcessor = new TestableTemplateProcesor ($ mainPart );
207
+
208
+ $ templateProcessor ->cloneRow ('fake_search ' , 2 );
209
+ }
210
+
181
211
/**
182
212
* @covers ::setValue
183
213
* @covers ::saveAs
@@ -200,6 +230,22 @@ public function testMacrosCanBeReplacedInHeaderAndFooter()
200
230
$ this ->assertTrue ($ docFound );
201
231
}
202
232
233
+ /**
234
+ * @covers ::setValue
235
+ * @test
236
+ */
237
+ public function testSetValue ()
238
+ {
239
+ $ templateProcessor = new TemplateProcessor (__DIR__ . '/_files/templates/clone-merge.docx ' );
240
+ Settings::setOutputEscapingEnabled (true );
241
+ $ helloworld = "hello \nworld " ;
242
+ $ templateProcessor ->setValue ('userName ' , $ helloworld );
243
+ $ this ->assertEquals (
244
+ array ('tableHeader ' , 'userId ' , 'userLocation ' ),
245
+ $ templateProcessor ->getVariables ()
246
+ );
247
+ }
248
+
203
249
/**
204
250
* @covers ::setImageValue
205
251
* @test
0 commit comments