Skip to content

Commit

Permalink
WiP
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshyPHP committed Mar 21, 2020
1 parent c93e48f commit 08cd0ac
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
1 change: 1 addition & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
<file>tests/Configurator/TemplateChecks/DisallowNodeByXPathTest.php</file>
<file>tests/Configurator/TemplateChecks/DisallowObjectParamsWithGeneratedNameTest.php</file>
<file>tests/Configurator/TemplateChecks/DisallowPHPTagsTest.php</file>
<file>tests/Configurator/TemplateChecks/DisallowUncompilableXSLTest.php</file>
<file>tests/Configurator/TemplateChecks/DisallowUnsafeCopyOfTest.php</file>
<file>tests/Configurator/TemplateChecks/DisallowUnsafeDynamicCSSTest.php</file>
<file>tests/Configurator/TemplateChecks/DisallowUnsafeDynamicJSTest.php</file>
Expand Down
101 changes: 101 additions & 0 deletions tests/Configurator/TemplateChecks/DisallowUncompilableXSLTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php

namespace s9e\TextFormatter\Tests\Configurator\TemplateChecks;

use s9e\TextFormatter\Configurator\Exceptions\UnsafeTemplateException;
use s9e\TextFormatter\Configurator\Items\Tag;
use s9e\TextFormatter\Configurator\TemplateChecks\DisallowUncompilableXSL;

/**
* @covers s9e\TextFormatter\Configurator\TemplateChecks\AbstractXSLSupportCheck
* @covers s9e\TextFormatter\Configurator\TemplateChecks\DisallowUncompilableXSL
*/
class DisallowUncompilableXSLTest extends AbstractTemplateCheckTest
{
/**
* @testdox Allowed: <b>...</b>
* @doesNotPerformAssertions
*/
public function testAllowed()
{
$node = $this->loadTemplate('<b>...</b>');
$check = new DisallowUncompilableXSL;
$check->check($node, new Tag);
}

/**
* @testdox Disallowed: <xsl:variable name="foo"/>
*/
public function testUnsupportedElement()
{
$this->expectException('RuntimeException');
$this->expectExceptionMessage('xsl:variable elements are not supported');

$node = $this->loadTemplate('<xsl:variable name="foo"/>');

$check = new DisallowUncompilableXSL;
$check->check($node, new Tag);
}

/**
* @testdox Allowed: <xsl:copy-of select="@foo"/>
* @doesNotPerformAssertions
*/
public function testCopyOfAttribute()
{
$node = $this->loadTemplate('<xsl:copy-of select="@foo"/>');
$check = new DisallowUncompilableXSL;
$check->check($node, new Tag);
}

/**
* @testdox Disallowed: <xsl:copy-of select="foo"/>
*/
public function testCopyOf()
{
$this->expectException('RuntimeException');
$this->expectExceptionMessage("Unsupported xsl:copy-of expression 'foo'");

$node = $this->loadTemplate('<xsl:copy-of select="foo"/>');

$check = new DisallowUncompilableXSL;
$check->check($node, new Tag);
}

/**
* @testdox Allowed: <xsl:value-of select="string-length(@foo)"/>
* @doesNotPerformAssertions
*/
public function testSupportedFunction()
{
$node = $this->loadTemplate('<xsl:value-of select="string-length(@foo)"/>');
$check = new DisallowUncompilableXSL;
$check->check($node, new Tag);
}

/**
* @testdox Disallowed: <xsl:value-of select="document()"/>
*/
public function testUnsupportedFunction()
{
$this->expectException('RuntimeException');
$this->expectExceptionMessage('XPath function document() is not supported');

$node = $this->loadTemplate('<xsl:value-of select="document()"/>');
$check = new DisallowUncompilableXSL;
$check->check($node, new Tag);
}

/**
* @testdox Disallowed: <hr title="{foo()}"/>
*/
public function testUnsupportedFunctionAVT()
{
$this->expectException('RuntimeException');
$this->expectExceptionMessage('XPath function foo() is not supported');

$node = $this->loadTemplate('<hr title="{foo()}"/>');
$check = new DisallowUncompilableXSL;
$check->check($node, new Tag);
}
}

0 comments on commit 08cd0ac

Please sign in to comment.