6
6
/**
7
7
* @coversDefaultClass PHPWord_Template
8
8
*/
9
- class TemplateTest extends \PHPUnit_Framework_TestCase
9
+ final class TemplateTest extends \PHPUnit_Framework_TestCase
10
10
{
11
11
/**
12
- * @covers ::applyXslStyleSheet
12
+ * @covers ::save
13
13
* @test
14
14
*/
15
- final public function testXslStyleSheetCanBeApplied ()
15
+ final public function testTemplateCanBeSavedInTemporaryLocation ()
16
16
{
17
- $ template = new PHPWord_Template (
18
- \join (
19
- \DIRECTORY_SEPARATOR ,
20
- array (\PHPWORD_TESTS_DIR_ROOT , '_files ' , 'templates ' , 'with_table_macros.docx ' )
21
- )
17
+ $ templateFqfn = \join (
18
+ \DIRECTORY_SEPARATOR ,
19
+ array (\PHPWORD_TESTS_DIR_ROOT , '_files ' , 'templates ' , 'with_table_macros.docx ' )
22
20
);
23
21
22
+ $ document = new PHPWord_Template ($ templateFqfn );
24
23
$ xslDOMDocument = new \DOMDocument ();
25
24
$ xslDOMDocument ->load (
26
25
\join (
27
26
\DIRECTORY_SEPARATOR ,
28
27
array (\PHPWORD_TESTS_DIR_ROOT , '_files ' , 'xsl ' , 'remove_tables_by_needle.xsl ' )
29
28
)
30
29
);
31
-
32
30
foreach (array ('${employee. ' , '${scoreboard. ' ) as $ needle ) {
33
- $ template ->applyXslStyleSheet ($ xslDOMDocument , array ('needle ' => $ needle ));
31
+ $ document ->applyXslStyleSheet ($ xslDOMDocument , array ('needle ' => $ needle ));
32
+ }
33
+
34
+ $ documentFqfn = $ document ->save ();
35
+
36
+ $ this ->assertNotEmpty ($ documentFqfn , 'FQFN of the saved document is empty. ' );
37
+ $ this ->assertFileExists ($ documentFqfn , "The saved document \"{$ documentFqfn }\" doesn't exist. " );
38
+
39
+ $ templateZip = new \ZipArchive ();
40
+ $ templateZip ->open ($ templateFqfn );
41
+ $ templateXml = $ templateZip ->getFromName ('word/document.xml ' );
42
+ if ($ templateZip ->close () === false ) {
43
+ throw new \Exception ("Could not close zip file \"{$ templateZip }\". " );
34
44
}
35
45
36
- $ actualDocument = $ template ->save ();
46
+ $ documentZip = new \ZipArchive ();
47
+ $ documentZip ->open ($ documentFqfn );
48
+ $ documentXml = $ documentZip ->getFromName ('word/document.xml ' );
49
+ if ($ documentZip ->close () === false ) {
50
+ throw new \Exception ("Could not close zip file \"{$ documentZip }\". " );
51
+ }
52
+
53
+ $ this ->assertNotEquals ($ documentXml , $ templateXml );
54
+
55
+ return $ document ;
56
+ }
57
+
58
+ /**
59
+ * @covers ::applyXslStyleSheet
60
+ * @depends testTemplateCanBeSavedInTemporaryLocation
61
+ * @test
62
+ */
63
+ final public function testXslStyleSheetCanBeApplied (&$ actualDocument )
64
+ {
37
65
$ expectedDocument = \join (
38
66
\DIRECTORY_SEPARATOR ,
39
67
array (\PHPWORD_TESTS_DIR_ROOT , '_files ' , 'documents ' , 'without_table_macros.docx ' )
@@ -43,14 +71,14 @@ final public function testXslStyleSheetCanBeApplied()
43
71
$ actualZip ->open ($ actualDocument );
44
72
$ actualXml = $ actualZip ->getFromName ('word/document.xml ' );
45
73
if ($ actualZip ->close () === false ) {
46
- throw new \Exception (' Could not close zip file " ' . $ actualDocument . ' ". ' );
74
+ throw new \Exception (" Could not close zip file \"{ $ actualDocument}\" . " );
47
75
}
48
76
49
77
$ expectedZip = new \ZipArchive ();
50
78
$ expectedZip ->open ($ expectedDocument );
51
79
$ expectedXml = $ expectedZip ->getFromName ('word/document.xml ' );
52
80
if ($ expectedZip ->close () === false ) {
53
- throw new \Exception (' Could not close zip file " ' . $ expectedDocument . ' ". ' );
81
+ throw new \Exception (" Could not close zip file \"{ $ expectedDocument}\" . " );
54
82
}
55
83
56
84
$ this ->assertXmlStringEqualsXmlString ($ expectedXml , $ actualXml );
0 commit comments