@@ -277,6 +277,38 @@ public function cloneBlockCanCloneABlockTwice()
277
277
}
278
278
}
279
279
280
+ /**
281
+ * Template macros can be fixed.
282
+ *
283
+ * @covers ::fixBrokenMacros
284
+ * @test
285
+ */
286
+ public function testFixBrokenMacros ()
287
+ {
288
+ $ templateProcessor = new TestableTemplateProcesor ();
289
+
290
+ $ fixed = $ templateProcessor ->fixBrokenMacros ('<w:r><w:t>normal text</w:t></w:r> ' );
291
+ $ this ->assertEquals ('<w:r><w:t>normal text</w:t></w:r> ' , $ fixed );
292
+
293
+ $ fixed = $ templateProcessor ->fixBrokenMacros ('<w:r><w:t>${documentContent}</w:t></w:r> ' );
294
+ $ this ->assertEquals ('<w:r><w:t>${documentContent}</w:t></w:r> ' , $ fixed );
295
+
296
+ $ fixed = $ templateProcessor ->fixBrokenMacros ('<w:r><w:t>$</w:t><w:t>{documentContent}</w:t></w:r> ' );
297
+ $ this ->assertEquals ('<w:r><w:t>${documentContent}</w:t></w:r> ' , $ fixed );
298
+
299
+ $ fixed = $ templateProcessor ->fixBrokenMacros ('<w:r><w:t>$1500</w:t><w:t>${documentContent}</w:t></w:r> ' );
300
+ $ this ->assertEquals ('<w:r><w:t>$1500</w:t><w:t>${documentContent}</w:t></w:r> ' , $ fixed );
301
+
302
+ $ fixed = $ templateProcessor ->fixBrokenMacros ('<w:r><w:t>$1500</w:t><w:t>$</w:t><w:t>{documentContent}</w:t></w:r> ' );
303
+ $ this ->assertEquals ('<w:r><w:t>$1500</w:t><w:t>${documentContent}</w:t></w:r> ' , $ fixed );
304
+
305
+ $ fixed = $ templateProcessor ->fixBrokenMacros ('<w:r><w:t>25$ plus some info {hint}</w:t></w:r> ' );
306
+ $ this ->assertEquals ('<w:r><w:t>25$ plus some info {hint}</w:t></w:r> ' , $ fixed );
307
+
308
+ $ fixed = $ templateProcessor ->fixBrokenMacros ('<w:t>$</w:t></w:r><w:bookmarkStart w:id="0" w:name="_GoBack"/><w:bookmarkEnd w:id="0"/><w:r><w:t xml:space="preserve">15,000.00. </w:t></w:r><w:r w:rsidR="0056499B"><w:t>$</w:t></w:r><w:r w:rsidR="00573DFD" w:rsidRPr="00573DFD"><w:rPr><w:iCs/></w:rPr><w:t>{</w:t></w:r><w:proofErr w:type="spellStart"/><w:r w:rsidR="00573DFD" w:rsidRPr="00573DFD"><w:rPr><w:iCs/></w:rPr><w:t>variable_name</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r w:rsidR="00573DFD" w:rsidRPr="00573DFD"><w:rPr><w:iCs/></w:rPr><w:t>}</w:t></w:r> ' );
309
+ $ this ->assertEquals ('<w:t>$</w:t></w:r><w:bookmarkStart w:id="0" w:name="_GoBack"/><w:bookmarkEnd w:id="0"/><w:r><w:t xml:space="preserve">15,000.00. </w:t></w:r><w:r w:rsidR="0056499B"><w:t>${variable_name}</w:t></w:r> ' , $ fixed );
310
+ }
311
+
280
312
public function testMainPartNameDetection ()
281
313
{
282
314
$ templateProcessor = new TemplateProcessor (__DIR__ . '/_files/templates/document22-xml.docx ' );
0 commit comments