Tests.
This commit is contained in:
Roman Syroeshko 2014-03-02 19:52:21 +04:00
parent a0165701c7
commit 27b7d67cc9
3 changed files with 100 additions and 0 deletions

View File

@ -0,0 +1,85 @@
<?php
namespace PHPWord\Tests;
use PHPWord_Template;
/**
* @coversDefaultClass PHPWord_Template
*/
class PHPWord_TemplateTest extends \PHPUnit_Framework_TestCase
{
/**
* @covers ::applyXslStyleSheet
* @test
*/
final public function testXslStyleSheetCanBeApplied()
{
// TODO: implement after merge of the issue https://github.com/PHPOffice/PHPWord/issues/56
}
/**
* @covers ::applyXslStyleSheet
* @expectedException Exception
* @expectedExceptionMessage Could not set values for the given XSL style sheet parameters.
* @test
*/
final public function testXsLStyleSheetCanNotBeAppliedOnFailureOfSettingParameterValue()
{
$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', '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);
}
}

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
</xsl:stylesheet>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<xsl:template match='@*|node()'>
<xsl:copy>
<xsl:apply-templates select='@*|node()'/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>