From 27b7d67cc9cffaa9864ac77db36707d8a1b7fd3c Mon Sep 17 00:00:00 2001 From: Roman Syroeshko Date: Sun, 2 Mar 2014 19:52:21 +0400 Subject: [PATCH] https://github.com/PHPOffice/PHPWord/issues/46 Tests. --- Tests/PHPWord/TemplateTest.php | 85 ++++++++++++++++++++++++++++++++ Tests/_files/xsl/blank.xsl | 4 ++ Tests/_files/xsl/passthrough.xsl | 11 +++++ 3 files changed, 100 insertions(+) create mode 100644 Tests/PHPWord/TemplateTest.php create mode 100644 Tests/_files/xsl/blank.xsl create mode 100644 Tests/_files/xsl/passthrough.xsl 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