Permalink
Browse files

Merge r3526

  • Loading branch information...
1 parent 3fcbb86 commit 9dd885099c8e9ca5323d4ec58b75fa4fa6e95e8d @mlively mlively committed Aug 7, 2008
@@ -146,7 +146,7 @@ protected function row(Array $row, PHPUnit_Extensions_Database_DataSet_ITable $t
foreach ($table->getTableMetaData()->getColumns() as $columnName) {
if (isset($row[$columnName])) {
- fwrite($this->fh, "\t\t{$columnName}=\"{$row[$columnName]}\"\n");
+ fwrite($this->fh, "\t\t{$columnName}=\"". htmlspecialchars($row[$columnName]) . "\"\n");
}
}
@@ -148,7 +148,7 @@ protected function row(Array $row, PHPUnit_Extensions_Database_DataSet_ITable $t
foreach ($table->getTableMetaData()->getColumns() as $columnName) {
if (isset($row[$columnName])) {
- fwrite($this->fh, "\t\t\t<value>{$row[$columnName]}</value>\n");
+ fwrite($this->fh, "\t\t\t<value>" . htmlspecialchars($row[$columnName]) . "</value>\n");
} else {
fwrite($this->fh, "\t\t\t<null />\n");
}
@@ -47,6 +47,9 @@
require_once 'PHPUnit/Framework/TestCase.php';
require_once 'PHPUnit/Extensions/Database/DataSet/FlatXmlDataSet.php';
require_once 'PHPUnit/Extensions/Database/DataSet/XmlDataSet.php';
+require_once 'PHPUnit/Extensions/Database/DataSet/DefaultDataSet.php';
+require_once 'PHPUnit/Extensions/Database/DataSet/DefaultTable.php';
+require_once 'PHPUnit/Extensions/Database/DataSet/DefaultTableMetaData.php';
/**
* @category Testing
@@ -83,5 +86,35 @@ public function testXml()
$this->assertXmlFileEqualsXmlFile($dataSetFile, $filename);
unlink($filename);
}
+
+ public function testEntitiesFlatXml()
+ {
+ $metaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData('table1', array('col1', 'col2'), array('col1'));
+ $table = new PHPUnit_Extensions_Database_DataSet_DefaultTable($metaData);
+ $table->addRow(array('col1' => 1, 'col2' => '<?xml version="1.0"?><myxml>test</myxml>'));
+ $dataSet = new PHPUnit_Extensions_Database_DataSet_DefaultDataSet(array($table));
+
+ $expectedFile = dirname(__FILE__).'/../_files/XmlDataSets/FlatXmlWriterEntities.xml';
+ $filename = dirname(__FILE__).'/'.uniqid().'.xml';
+ PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet::write($dataSet, $filename);
+
+ $this->assertXmlFileEqualsXmlFile($expectedFile, $filename);
+ unlink($filename);
+ }
+
+ public function testEntitiesXml()
+ {
+ $metaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData('table1', array('col1', 'col2'), array('col1'));
+ $table = new PHPUnit_Extensions_Database_DataSet_DefaultTable($metaData);
+ $table->addRow(array('col1' => 1, 'col2' => '<?xml version="1.0"?><myxml>test</myxml>'));
+ $dataSet = new PHPUnit_Extensions_Database_DataSet_DefaultDataSet(array($table));
+
+ $expectedFile = dirname(__FILE__).'/../_files/XmlDataSets/XmlWriterEntities.xml';
+ $filename = dirname(__FILE__).'/'.uniqid().'.xml';
+ PHPUnit_Extensions_Database_DataSet_XmlDataSet::write($dataSet, $filename);
+
+ $this->assertXmlFileEqualsXmlFile($expectedFile, $filename);
+ unlink($filename);
+ }
}
?>
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table1
+ col1="1"
+ col2="&lt;?xml version=&quot;1.0&quot;?&gt;&lt;myxml&gt;test&lt;/myxml&gt;"
+ />
+</dataset>
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="table1">
+ <column>col1</column>
+ <column>col2</column>
+ <row>
+ <value>1</value>
+ <value>&lt;?xml version=&quot;1.0&quot;?&gt;&lt;myxml&gt;test&lt;/myxml&gt;</value>
+ </row>
+ </table>
+</dataset>

0 comments on commit 9dd8850

Please sign in to comment.