@@ -14,7 +14,46 @@ class PHPWord_TemplateTest extends \PHPUnit_Framework_TestCase
1414 */
1515 final public function testXslStyleSheetCanBeApplied ()
1616 {
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);
1857 }
1958
2059 /**
@@ -26,14 +65,18 @@ final public function testXslStyleSheetCanBeApplied()
2665 final public function testXslStyleSheetCanNotBeAppliedOnFailureOfSettingParameterValue ()
2766 {
2867 $ 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+ )
3172 );
3273
3374 $ xslDOMDocument = new \DOMDocument ();
3475 $ 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+ )
3780 );
3881
3982 /*
@@ -52,14 +95,18 @@ final public function testXslStyleSheetCanNotBeAppliedOnFailureOfSettingParamete
5295 final public function testXslStyleSheetCanNotBeAppliedOnFailureOfLoadingXmlFromTemplate ()
5396 {
5497 $ 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+ )
57102 );
58103
59104 $ xslDOMDocument = new \DOMDocument ();
60105 $ 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+ )
63110 );
64111
65112 /*
0 commit comments