Skip to content

Commit

Permalink
Convert tests to baseless
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Mar 1, 2024
1 parent cb3db78 commit b827999
Show file tree
Hide file tree
Showing 23 changed files with 421 additions and 486 deletions.
6 changes: 4 additions & 2 deletions src/main/php/xml/io/XmlStreamWriter.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

use io\streams\OutputStream;


/**
* Outputs XML to an output stream.
*
* @test xp://xml.unittest.io.XmlStreamWriterTest
* @test xml.unittest.io.XmlStreamWriterTest
*/
class XmlStreamWriter extends XmlWriter {
protected $stack= [];
Expand All @@ -21,6 +20,9 @@ public function __construct(OutputStream $stream) {
$this->stream= $stream;
}

/** @return io.streams.OutputStream */
public function out() { return $this->stream; }

/**
* Start writing a document
*
Expand Down
68 changes: 32 additions & 36 deletions src/test/php/xml/unittest/AbstractProcessorTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@

use io\FileNotFoundException;
use lang\Runtime;
use unittest\{Expect, PrerequisitesNotMetError, Test, TestCase};
use unittest\{Assert, Expect, PrerequisitesNotMetError, Test, TestCase};
use xml\{TransformerException, Tree};

/**
* Test XSL processor
*
* @see xp://xml.IXSLProcessor
*/
abstract class AbstractProcessorTest extends TestCase {
abstract class AbstractProcessorTest {
public $processor= null;
public $xmlDeclaration= '';

Expand All @@ -24,7 +19,7 @@ abstract class AbstractProcessorTest extends TestCase {
* @throws unittest.AssertionFailedError
*/
public function assertXmlEquals($expect, $actual) {
$this->assertEquals(
Assert::equals(
$this->xmlDeclaration.preg_replace('#>[\s\r\n]+<#', '><', trim($expect)),
preg_replace('#>[\s\r\n]+<#', '><', trim($actual))
);
Expand Down Expand Up @@ -82,6 +77,7 @@ public function processorCharset() { }
*
* @throws unittest.PrerequisitesNotMetError
*/
#[Before]
public function setUp() {
foreach ((array)$this->neededExtension() as $ext) {
if (!extension_loaded($ext)) {
Expand Down Expand Up @@ -167,23 +163,23 @@ public function setMalformedXSLTree() {
#[Test]
public function paramAccessors() {
$this->processor->setParam('a', 'b');
$this->assertEquals('b', $this->processor->getParam('a'));
Assert::equals('b', $this->processor->getParam('a'));
}

#[Test]
public function baseAccessors() {
$file= Runtime::getInstance()->getExecutable()->getFilename();
$path= rtrim(realpath(dirname($file)), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
$this->processor->setBase($path);
$this->assertEquals($path, $this->processor->getBase());
Assert::equals($path, $this->processor->getBase());
}

#[Test]
public function setBaseAddsTrailingDirectorySeparator() {
$file= Runtime::getInstance()->getExecutable()->getFilename();
$path= rtrim(realpath(dirname($file)), DIRECTORY_SEPARATOR);
$this->processor->setBase($path);
$this->assertEquals($path.DIRECTORY_SEPARATOR, $this->processor->getBase());
Assert::equals($path.DIRECTORY_SEPARATOR, $this->processor->getBase());
}

#[Test]
Expand All @@ -193,9 +189,9 @@ public function setParams() {
'left' => 'one',
'right' => 'two'
]);
$this->assertEquals('b', $this->processor->getParam('a')) &&
$this->assertEquals('one', $this->processor->getParam('left')) &&
$this->assertEquals('two', $this->processor->getParam('right'));
Assert::equals('b', $this->processor->getParam('a')) &&
Assert::equals('one', $this->processor->getParam('left')) &&
Assert::equals('two', $this->processor->getParam('right'));
}

#[Test]
Expand All @@ -207,7 +203,7 @@ public function transformationWithEmptyResult() {
</xsl:stylesheet>
');
$this->processor->run();
$this->assertEquals('', $this->processor->output());
Assert::equals('', $this->processor->output());
}

#[Test]
Expand All @@ -222,8 +218,8 @@ public function iso88591XslWithoutOutputEncoding() {
</xsl:stylesheet>
');
$this->processor->run();
$this->assertEquals($this->processorCharset(), $this->processor->outputEncoding());
$this->assertEquals('übercoder', $this->processor->output());
Assert::equals($this->processorCharset(), $this->processor->outputEncoding());
Assert::equals('übercoder', $this->processor->output());
}

#[Test]
Expand All @@ -238,8 +234,8 @@ public function iso88591XslWithUtf8OutputEncoding() {
</xsl:stylesheet>
');
$this->processor->run();
$this->assertEquals('utf-8', $this->processor->outputEncoding());
$this->assertEquals('übercoder', $this->processor->output());
Assert::equals('utf-8', $this->processor->outputEncoding());
Assert::equals('übercoder', $this->processor->output());
}

#[Test]
Expand All @@ -254,8 +250,8 @@ public function utf8XslWithoutOutputEncoding() {
</xsl:stylesheet>
');
$this->processor->run();
$this->assertEquals($this->processorCharset(), $this->processor->outputEncoding());
$this->assertEquals('übercoder', $this->processor->output());
Assert::equals($this->processorCharset(), $this->processor->outputEncoding());
Assert::equals('übercoder', $this->processor->output());
}

#[Test]
Expand All @@ -270,8 +266,8 @@ public function utf8XslWithUtf8OutputEncoding() {
</xsl:stylesheet>
');
$this->processor->run();
$this->assertEquals('utf-8', $this->processor->outputEncoding());
$this->assertEquals('übercoder', $this->processor->output());
Assert::equals('utf-8', $this->processor->outputEncoding());
Assert::equals('übercoder', $this->processor->output());
}

#[Test]
Expand All @@ -286,8 +282,8 @@ public function utf8XslWithIso88591OutputEncoding() {
</xsl:stylesheet>
');
$this->processor->run();
$this->assertEquals('iso-8859-1', $this->processor->outputEncoding());
$this->assertEquals("\xfcbercoder", $this->processor->output());
Assert::equals('iso-8859-1', $this->processor->outputEncoding());
Assert::equals("\xfcbercoder", $this->processor->output());
}

#[Test]
Expand All @@ -302,8 +298,8 @@ public function iso88591XslWithIso88591OutputEncoding() {
</xsl:stylesheet>
');
$this->processor->run();
$this->assertEquals('iso-8859-1', $this->processor->outputEncoding());
$this->assertEquals("\xfcbercoder", $this->processor->output());
Assert::equals('iso-8859-1', $this->processor->outputEncoding());
Assert::equals("\xfcbercoder", $this->processor->output());
}

#[Test]
Expand Down Expand Up @@ -333,7 +329,7 @@ public function transformationToHtml() {
</xsl:stylesheet>
');
$this->processor->run();
$this->assertEquals('<b>Hello</b>', trim($this->processor->output()));
Assert::equals('<b>Hello</b>', trim($this->processor->output()));
}

#[Test]
Expand All @@ -348,7 +344,7 @@ public function javaScriptInCDataSection() {
</xsl:stylesheet>
');
$this->processor->run();
$this->assertEquals(
Assert::equals(
'<script language="JavaScript"> alert(1 && 2); </script>',
trim($this->processor->output())
);
Expand All @@ -366,7 +362,7 @@ public function omitXmlDeclaration() {
</xsl:stylesheet>
');
$this->processor->run();
$this->assertEquals('<tag>No XML declaration</tag>', trim($this->processor->output()));
Assert::equals('<tag>No XML declaration</tag>', trim($this->processor->output()));
}

#[Test]
Expand Down Expand Up @@ -481,7 +477,7 @@ public function includingAFile() {
</xsl:stylesheet>
');
$this->processor->run();
$this->assertEquals('TEST', $this->processor->output());
Assert::equals('TEST', $this->processor->output());
}

#[Test]
Expand All @@ -496,7 +492,7 @@ public function importingAFile() {
</xsl:stylesheet>
');
$this->processor->run();
$this->assertEquals('TEST', $this->processor->output());
Assert::equals('TEST', $this->processor->output());
}

#[Test]
Expand All @@ -508,7 +504,7 @@ public function outputEncodingFromIncludedFile() {
</xsl:stylesheet>
');
$this->processor->run();
$this->assertEquals('iso-8859-1', $this->processor->outputEncoding());
Assert::equals('iso-8859-1', $this->processor->outputEncoding());
}

#[Test]
Expand All @@ -520,7 +516,7 @@ public function outputEncodingFromImportedFile() {
</xsl:stylesheet>
');
$this->processor->run();
$this->assertEquals('iso-8859-1', $this->processor->outputEncoding());
Assert::equals('iso-8859-1', $this->processor->outputEncoding());
}

#[Test]
Expand All @@ -532,7 +528,7 @@ public function outputEncodingFromIncludedInImportedFile() {
</xsl:stylesheet>
');
$this->processor->run();
$this->assertEquals('iso-8859-1', $this->processor->outputEncoding());
Assert::equals('iso-8859-1', $this->processor->outputEncoding());
}

#[Test]
Expand All @@ -544,6 +540,6 @@ public function outputEncodingFromIncludedInIncludedFile() {
</xsl:stylesheet>
');
$this->processor->run();
$this->assertEquals('iso-8859-1', $this->processor->outputEncoding());
Assert::equals('iso-8859-1', $this->processor->outputEncoding());
}
}
Loading

0 comments on commit b827999

Please sign in to comment.