@@ -14,7 +14,46 @@ class PHPWord_TemplateTest extends \PHPUnit_Framework_TestCase
14
14
*/
15
15
final public function testXslStyleSheetCanBeApplied ()
16
16
{
17
- // TODO: implement after merge of the issue https://github.com/PHPOffice/PHPWord/issues/56
17
+ $ template = new PHPWord_Template (
18
+ \join (
19
+ \DIRECTORY_SEPARATOR ,
20
+ array (\PHPWORD_TESTS_DIR_ROOT , '_files ' , 'templates ' , 'with_table_macros.docx ' )
21
+ )
22
+ );
23
+
24
+ $ xslDOMDocument = new \DOMDocument ();
25
+ $ xslDOMDocument ->load (
26
+ \join (
27
+ \DIRECTORY_SEPARATOR ,
28
+ array (\PHPWORD_TESTS_DIR_ROOT , '_files ' , 'xsl ' , 'remove_tables_by_needle.xsl ' )
29
+ )
30
+ );
31
+
32
+ foreach (array ('${employee. ' , '${scoreboard. ' ) as $ needle ) {
33
+ $ template ->applyXslStyleSheet ($ xslDOMDocument , array ('needle ' => $ needle ));
34
+ }
35
+
36
+ $ actualDocument = $ template ->save ();
37
+ $ expectedDocument = \join (
38
+ \DIRECTORY_SEPARATOR ,
39
+ array (\PHPWORD_TESTS_DIR_ROOT , '_files ' , 'documents ' , 'without_table_macros.docx ' )
40
+ );
41
+
42
+ $ actualZip = new ZipArchive ();
43
+ $ actualZip ->open ($ actualDocument );
44
+ $ actualXml = $ zip ->getFromName ('word/document.xml ' );
45
+ if ($ actualZip ->close () === false ) {
46
+ throw new \Exception ('Could not close zip file " ' . $ actualDocument . '". ' );
47
+ }
48
+
49
+ $ expectedZip = new ZipArchive ();
50
+ $ expectedZip ->open ($ expectedDocument );
51
+ $ expectedXml = $ zip ->getFromName ('word/document.xml ' );
52
+ if ($ expectedZip ->close () === false ) {
53
+ throw new \Exception ('Could not close zip file " ' . $ expectedDocument . '". ' );
54
+ }
55
+
56
+ $ this ->assertXmlStringEqualsXmlString (expectedXml, actualXml);
18
57
}
19
58
20
59
/**
@@ -26,14 +65,18 @@ final public function testXslStyleSheetCanBeApplied()
26
65
final public function testXslStyleSheetCanNotBeAppliedOnFailureOfSettingParameterValue ()
27
66
{
28
67
$ template = new PHPWord_Template (
29
- \join (\DIRECTORY_SEPARATOR ,
30
- array (\PHPWORD_TESTS_DIR_ROOT , '_files ' , 'templates ' , 'blank.docx ' ))
68
+ \join (
69
+ \DIRECTORY_SEPARATOR ,
70
+ array (\PHPWORD_TESTS_DIR_ROOT , '_files ' , 'templates ' , 'blank.docx ' )
71
+ )
31
72
);
32
73
33
74
$ xslDOMDocument = new \DOMDocument ();
34
75
$ xslDOMDocument ->load (
35
- \join (\DIRECTORY_SEPARATOR ,
36
- array (\PHPWORD_TESTS_DIR_ROOT , '_files ' , 'xsl ' , 'passthrough.xsl ' ))
76
+ \join (
77
+ \DIRECTORY_SEPARATOR ,
78
+ array (\PHPWORD_TESTS_DIR_ROOT , '_files ' , 'xsl ' , 'passthrough.xsl ' )
79
+ )
37
80
);
38
81
39
82
/*
@@ -52,14 +95,18 @@ final public function testXslStyleSheetCanNotBeAppliedOnFailureOfSettingParamete
52
95
final public function testXslStyleSheetCanNotBeAppliedOnFailureOfLoadingXmlFromTemplate ()
53
96
{
54
97
$ template = new PHPWord_Template (
55
- \join (\DIRECTORY_SEPARATOR ,
56
- array (\PHPWORD_TESTS_DIR_ROOT , '_files ' , 'templates ' , 'corrupted_main_document_part.docx ' ))
98
+ \join (
99
+ \DIRECTORY_SEPARATOR ,
100
+ array (\PHPWORD_TESTS_DIR_ROOT , '_files ' , 'templates ' , 'corrupted_main_document_part.docx ' )
101
+ )
57
102
);
58
103
59
104
$ xslDOMDocument = new \DOMDocument ();
60
105
$ xslDOMDocument ->load (
61
- \join (\DIRECTORY_SEPARATOR ,
62
- array (\PHPWORD_TESTS_DIR_ROOT , '_files ' , 'xsl ' , 'passthrough.xsl ' ))
106
+ \join (
107
+ \DIRECTORY_SEPARATOR ,
108
+ array (\PHPWORD_TESTS_DIR_ROOT , '_files ' , 'xsl ' , 'passthrough.xsl ' )
109
+ )
63
110
);
64
111
65
112
/*
0 commit comments