summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorknut <>2006-05-12 06:11:39 +0000
committerknut <>2006-05-12 06:11:39 +0000
commitd84327e69e858d369ea0c78f6106cfaa54994032 (patch)
treeefbbad450762b8d26bcae2a72b544ac4f6e027ad
parent3257465eec899be0c090cf2ef54fdb3a58ab82f2 (diff)
Added unit tests for TXmlTransform control #99
-rw-r--r--.gitattributes3
-rw-r--r--tests/unit/Web/UI/WebControls/TXmlTransformTest.php129
-rw-r--r--tests/unit/Web/UI/WebControls/data/hello.xml2
-rw-r--r--tests/unit/Web/UI/WebControls/data/hello.xsl5
4 files changed, 139 insertions, 0 deletions
diff --git a/.gitattributes b/.gitattributes
index 3135aca2..7602ad76 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1536,4 +1536,7 @@ tests/unit/TComponentTest.php -text
tests/unit/Web/UI/WebControls/TDropDownListTest.php -text
tests/unit/Web/UI/WebControls/TLabelTest.php -text
tests/unit/Web/UI/WebControls/TRequiredFieldValidatorTest.php -text
+tests/unit/Web/UI/WebControls/TXmlTransformTest.php -text
+tests/unit/Web/UI/WebControls/data/hello.xml -text
+tests/unit/Web/UI/WebControls/data/hello.xsl -text
tests/unit/phpunit2.php -text
diff --git a/tests/unit/Web/UI/WebControls/TXmlTransformTest.php b/tests/unit/Web/UI/WebControls/TXmlTransformTest.php
new file mode 100644
index 00000000..e277edbd
--- /dev/null
+++ b/tests/unit/Web/UI/WebControls/TXmlTransformTest.php
@@ -0,0 +1,129 @@
+<?php
+require_once dirname(__FILE__).'/../../../phpunit2.php';
+
+Prado::using('System.Web.UI.WebControls.TXmlTransform');
+Prado::using('System.Web.UI.THtmlWriter');
+
+/**
+ * @package System.Web.UI.WebControls
+ */
+class TXmlTransformTest extends PHPUnit2_Framework_TestCase {
+
+ private $documentContent;
+ private $transformContent;
+ private $documentPath;
+ private $transformPath;
+
+ public function setUp() {
+ $this->documentPath = dirname(__FILE__).'/data/hello.xml';
+ $this->documentContent = file_get_contents($this->documentPath);
+ $this->transformPath = dirname(__FILE__).'/data/hello.xsl';
+ $this->transformContent = file_get_contents($this->transformPath);
+ }
+
+ public function testSetDocumentContent() {
+ $expected = $this->documentContent;
+ $transform = new TXmlTransform();
+ $transform->setDocumentContent($expected);
+ $this->assertEquals($expected, $transform->getDocumentContent());
+ }
+
+ public function testSetDocumentPathAsFile() {
+ $expected = $this->documentPath;
+ $transform = new TXmlTransform();
+ $transform->setDocumentPath($expected);
+ $this->assertEquals($expected, $transform->getDocumentPath());
+ }
+
+ public function testSetDocumentPathAsNamespace() {
+ if(Prado::getPathOfAlias('UnitTest') === null) {
+ Prado::setPathOfAlias('UnitTest', dirname(__FILE__).'/data');
+ }
+ $expected = $this->documentPath;
+ $transform = new TXmlTransform();
+ $transform->setDocumentPath('UnitTest.hello');
+ $this->assertEquals($expected, $transform->getDocumentPath());
+ }
+
+ public function testSetTransformContent() {
+ $expected = $this->transformContent;
+ $transform = new TXmlTransform();
+ $transform->setTransformContent($expected);
+ $this->assertEquals($expected, $transform->getTransformContent());
+ }
+
+ public function testSetTransformPathAsFile() {
+ $expected = $this->transformPath;
+ $transform = new TXmlTransform();
+ $transform->setTransformPath($expected);
+ $this->assertEquals($expected, $transform->getTransformPath());
+ }
+
+ public function testSetTransformPathAsNamespace() {
+ if(Prado::getPathOfAlias('UnitTest') === null) {
+ Prado::setPathOfAlias('UnitTest', dirname(__FILE__).'/data');
+ }
+ $expected = $this->transformPath;
+ $transform = new TXmlTransform();
+ $transform->setTransformPath('UnitTest.hello');
+ $this->assertEquals($expected, $transform->getTransformPath());
+ }
+
+ public function testAddParameter() {
+ throw new PHPUnit2_Framework_IncompleteTestError();
+ }
+
+ public function testRenderWithDocumentContentAndTransformContent() {
+ $expected = "<b>Hello World!</b>\n";
+ $transform = new TXmlTransform();
+ $transform->setDocumentContent($this->documentContent);
+ $transform->setTransformContent($this->transformContent);
+ $textWriter = new TTextWriter();
+ $htmlWriter = new THtmlWriter($textWriter);
+ $transform->render($htmlWriter);
+ $actual = $textWriter->flush();
+ self::assertEquals($expected, $actual);
+ }
+
+ public function testRenderWithDocumentPathAndTransformContent() {
+ $expected = "<b>Hello World!</b>\n";
+ $transform = new TXmlTransform();
+ $transform->setDocumentPath($this->documentPath);
+ $transform->setTransformContent($this->transformContent);
+ $textWriter = new TTextWriter();
+ $htmlWriter = new THtmlWriter($textWriter);
+ $transform->render($htmlWriter);
+ $actual = $textWriter->flush();
+ self::assertEquals($expected, $actual);
+ }
+
+ public function testRenderWithDocumentContentAndTransformPath() {
+ $expected = "<b>Hello World!</b>\n";
+ $transform = new TXmlTransform();
+ $transform->setDocumentContent($this->documentContent);
+ $transform->setTransformPath($this->transformPath);
+ $textWriter = new TTextWriter();
+ $htmlWriter = new THtmlWriter($textWriter);
+ $transform->render($htmlWriter);
+ $actual = $textWriter->flush();
+ self::assertEquals($expected, $actual);
+ }
+
+ public function testRenderWithDocumentPathAndTransformPath() {
+ $expected = "<b>Hello World!</b>\n";
+ $transform = new TXmlTransform();
+ $transform->setDocumentPath($this->documentPath);
+ $transform->setTransformPath($this->transformPath);
+ $textWriter = new TTextWriter();
+ $htmlWriter = new THtmlWriter($textWriter);
+ $transform->render($htmlWriter);
+ $actual = $textWriter->flush();
+ self::assertEquals($expected, $actual);
+ }
+
+ public function testRenderWithBodyAsDocumentAndTransformPath() {
+ throw new PHPUnit2_Framework_IncompleteTestError();
+ }
+}
+
+?>
diff --git a/tests/unit/Web/UI/WebControls/data/hello.xml b/tests/unit/Web/UI/WebControls/data/hello.xml
new file mode 100644
index 00000000..9f8b12ee
--- /dev/null
+++ b/tests/unit/Web/UI/WebControls/data/hello.xml
@@ -0,0 +1,2 @@
+<?xml version="1.0"?>
+<greeting>Hello World!</greeting>
diff --git a/tests/unit/Web/UI/WebControls/data/hello.xsl b/tests/unit/Web/UI/WebControls/data/hello.xsl
new file mode 100644
index 00000000..f0664464
--- /dev/null
+++ b/tests/unit/Web/UI/WebControls/data/hello.xsl
@@ -0,0 +1,5 @@
+<?xml version="1.0"?>
+<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
+<xsl:output method="xml" omit-xml-declaration="yes"/>
+<xsl:template match="/"><b><xsl:value-of select="greeting"/></b></xsl:template>
+</xsl:transform>