diff --git a/Tests/PHPWord/TemplateTest.php b/Tests/PHPWord/TemplateTest.php new file mode 100644 index 00000000..99d977b0 --- /dev/null +++ b/Tests/PHPWord/TemplateTest.php @@ -0,0 +1,85 @@ +load( + \join(\DIRECTORY_SEPARATOR, + array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'xsl', 'passthrough.xsl')) + ); + + $template->applyXslStyleSheet($xslDOMDocument, [1 => 'somevalue']); + } + + /** + * @covers ::applyXslStyleSheet + * @expectedException Exception + * @expectedExceptionMessage Could not load XML from the given template. + * @test + */ + final public function testXslStyleSheetCanNotBeAppliedOnFailureOfLoadingXmlFromTemplate() + { + $template = new PHPWord_Template( + \join(\DIRECTORY_SEPARATOR, + array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'templates', 'corrupted_main_document_part.docx')) + ); + + $xslDOMDocument = new \DOMDocument(); + $xslDOMDocument->load( + \join(\DIRECTORY_SEPARATOR, + array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'xsl', 'passthrough.xsl')) + ); + + $template->applyXslStyleSheet($xslDOMDocument); + } + + /** + * @covers ::applyXslStyleSheet + * @expectedException Exception + * @expectedExceptionMessage Could not transform the given XML document. + * @test + */ + final public function testXslStyleSheetCanNotBeAppliedOnFailureOfTransformation() + { + $template = new PHPWord_Template( + \join(\DIRECTORY_SEPARATOR, + array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'templates', 'blank.docx')) + ); + + $xslDOMDocument = new \DOMDocument(); + $xslDOMDocument->load( + \join(\DIRECTORY_SEPARATOR, + array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'xsl', 'blank.xsl')) + ); + + $template->applyXslStyleSheet($xslDOMDocument); + } +} \ No newline at end of file diff --git a/Tests/_files/xsl/blank.xsl b/Tests/_files/xsl/blank.xsl new file mode 100644 index 00000000..48edfd43 --- /dev/null +++ b/Tests/_files/xsl/blank.xsl @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Tests/_files/xsl/passthrough.xsl b/Tests/_files/xsl/passthrough.xsl new file mode 100644 index 00000000..4ab21dd7 --- /dev/null +++ b/Tests/_files/xsl/passthrough.xsl @@ -0,0 +1,11 @@ + + + + + + + + + + \ No newline at end of file