Skip to content

Commit

Permalink
Remove Duplication like an Adult
Browse files Browse the repository at this point in the history
I feel kind of ashamed.
  • Loading branch information
Jim Lind committed Sep 6, 2015
1 parent fb32f23 commit d6c780d
Showing 1 changed file with 21 additions and 25 deletions.
46 changes: 21 additions & 25 deletions tests/JimLind/TiVo/Characteristic/XmlTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use JimLind\TiVo\Characteristic\XmlTrait;

/**
* Test the TiVo\Utilities\Log class.
* Test the TiVo\Utilities\Log class
*/
class XmlNamespaceTest extends \PHPUnit_Framework_TestCase
{
Expand All @@ -20,7 +20,7 @@ protected function setUp()
}

/**
* Test a snippet of XML with a defined namespace.
* Test a snippet of XML with a defined namespace
*/
public function testNamespacedXml()
{
Expand All @@ -38,7 +38,7 @@ public function testNamespacedXml()
}

/**
* Test a snippet of XML without a namespace.
* Test a snippet of XML without a namespace
*/
public function testRawXml()
{
Expand Down Expand Up @@ -68,34 +68,30 @@ public function testEmptyXMLString()
}

/**
* Test XML element output.
* Test XML output
*
* @dataProvider testAfterRegisterProvider
*/
public function testElementXMLString()
public function testAfterRegister($input, $expected)
{
$xmlElement = simplexml_load_string('<a />');
$outputXml = $this->fixture->registerTiVoNamespace($xmlElement);

$actual = $outputXml->asXml();

$expected = '<?xml version="1.0"?>'."\n";
$expected .= '<a xmlns="http://www.w3.org/2001/XMLSchema"/>'."\n";
$inputXml = simplexml_load_string($input);
$outputXml = $this->fixture->registerTiVoNamespace($inputXml);
$actual = $outputXml->asXml();

$this->assertEquals($expected, $actual);
}

/**
* Test full XML structure output.
*/
public function testStructureXMLString()
public function testAfterRegisterProvider()
{
$xmlStructure = simplexml_load_string('<b><c /></b>');
$outputXml = $this->fixture->registerTiVoNamespace($xmlStructure);

$actual = $outputXml->asXml();

$expected = '<?xml version="1.0"?>'."\n";
$expected .= '<b xmlns="http://www.w3.org/2001/XMLSchema"><c/></b>'."\n";

$this->assertEquals($expected, $actual);
return [
[
'<x />',
"<?xml version=\"1.0\"?>\n<x xmlns=\"http://www.w3.org/2001/XMLSchema\"/>\n",
],
[
'<x><y /></x>',
"<?xml version=\"1.0\"?>\n<x xmlns=\"http://www.w3.org/2001/XMLSchema\"/><y/></x>\n",
]
];
}
}

0 comments on commit d6c780d

Please sign in to comment.