BLA;
$reader = new Reader();
$reader->xml($input);
$reader->next();
$this->assertEquals('{http://sabredav.org/ns}root', $reader->getClark());
}
function testGetClarkNoNS() {
$input = <<
BLA;
$reader = new Reader();
$reader->xml($input);
$reader->next();
$this->assertEquals('{}root', $reader->getClark());
}
function testGetClarkNotOnAnElement() {
$input = <<
BLA;
$reader = new Reader();
$reader->xml($input);
$this->assertNull($reader->getClark());
}
function testSimple() {
$input = <<
Hi!
BLA;
$reader = new Reader();
$reader->xml($input);
$output = $reader->parse();
$expected = [
'name' => '{http://sabredav.org/ns}root',
'value' => [
[
'name' => '{http://sabredav.org/ns}elem1',
'value' => null,
'attributes' => [
'attr' => 'val',
],
],
[
'name' => '{http://sabredav.org/ns}elem2',
'value' => [
[
'name' => '{http://sabredav.org/ns}elem3',
'value' => 'Hi!',
'attributes' => [],
],
],
'attributes' => [],
],
],
'attributes' => [],
];
$this->assertEquals($expected, $output);
}
function testCDATA() {
$input = <<
BLA;
$reader = new Reader();
$reader->xml($input);
$output = $reader->parse();
$expected = [
'name' => '{http://sabredav.org/ns}root',
'value' => [
[
'name' => '{http://sabredav.org/ns}foo',
'value' => 'bar',
'attributes' => [],
],
],
'attributes' => [],
];
$this->assertEquals($expected, $output);
}
function testSimpleNamespacedAttribute() {
$input = <<
BLA;
$reader = new Reader();
$reader->xml($input);
$output = $reader->parse();
$expected = [
'name' => '{http://sabredav.org/ns}root',
'value' => [
[
'name' => '{http://sabredav.org/ns}elem1',
'value' => null,
'attributes' => [
'{urn:foo}attr' => 'val',
],
],
],
'attributes' => [],
];
$this->assertEquals($expected, $output);
}
function testMappedElement() {
$input = <<
BLA;
$reader = new Reader();
$reader->elementMap = [
'{http://sabredav.org/ns}elem1' => 'Sabre\\Xml\\Element\\Mock'
];
$reader->xml($input);
$output = $reader->parse();
$expected = [
'name' => '{http://sabredav.org/ns}root',
'value' => [
[
'name' => '{http://sabredav.org/ns}elem1',
'value' => 'foobar',
'attributes' => [],
],
],
'attributes' => [],
];
$this->assertEquals($expected, $output);
}
/**
* @expectedException \LogicException
*/
function testMappedElementBadClass() {
$input = <<
BLA;
$reader = new Reader();
$reader->elementMap = [
'{http://sabredav.org/ns}elem1' => new \StdClass()
];
$reader->xml($input);
$reader->parse();
}
/**
* @depends testMappedElement
*/
function testMappedElementCallBack() {
$input = <<
BLA;
$reader = new Reader();
$reader->elementMap = [
'{http://sabredav.org/ns}elem1' => function(Reader $reader) {
$reader->next();
return 'foobar';
}
];
$reader->xml($input);
$output = $reader->parse();
$expected = [
'name' => '{http://sabredav.org/ns}root',
'value' => [
[
'name' => '{http://sabredav.org/ns}elem1',
'value' => 'foobar',
'attributes' => [],
],
],
'attributes' => [],
];
$this->assertEquals($expected, $output);
}
/**
* @depends testMappedElementCallBack
*/
function testMappedElementCallBackNoNamespace() {
$input = <<
BLA;
$reader = new Reader();
$reader->elementMap = [
'elem1' => function(Reader $reader) {
$reader->next();
return 'foobar';
}
];
$reader->xml($input);
$output = $reader->parse();
$expected = [
'name' => '{}root',
'value' => [
[
'name' => '{}elem1',
'value' => 'foobar',
'attributes' => [],
],
],
'attributes' => [],
];
$this->assertEquals($expected, $output);
}
/**
* @depends testMappedElementCallBack
*/
function testReadText() {
$input = <<
hello
world
BLA;
$reader = new Reader();
$reader->elementMap = [
'{http://sabredav.org/ns}elem1' => function(Reader $reader) {
return $reader->readText();
}
];
$reader->xml($input);
$output = $reader->parse();
$expected = [
'name' => '{http://sabredav.org/ns}root',
'value' => [
[
'name' => '{http://sabredav.org/ns}elem1',
'value' => 'hello world',
'attributes' => [],
],
],
'attributes' => [],
];
$this->assertEquals($expected, $output);
}
function testParseProblem() {
$input = <<
BLA;
$reader = new Reader();
$reader->elementMap = [
'{http://sabredav.org/ns}elem1' => 'Sabre\\Xml\\Element\\Mock'
];
$reader->xml($input);
try {
$output = $reader->parse();
$this->fail('We expected a ParseException to be thrown');
} catch (LibXMLException $e) {
$this->assertInternalType('array', $e->getErrors());
}
}
/**
* @expectedException \Sabre\Xml\ParseException
*/
function testBrokenParserClass() {
$input = <<
BLA;
$reader = new Reader();
$reader->elementMap = [
'{http://sabredav.org/ns}elem1' => 'Sabre\\Xml\\Element\\Eater'
];
$reader->xml($input);
$reader->parse();
}
/**
* Test was added for Issue #10.
*
* @expectedException Sabre\Xml\LibXMLException
*/
function testBrokenXml() {
$input = <<
BLA;
$reader = new Reader();
$reader->xml($input);
$reader->parse();
}
/**
* Test was added for Issue #45.
*
* @expectedException Sabre\Xml\LibXMLException
*/
function testBrokenXml2() {
$input = <<
""Administrative w">
xml($input);
$reader->parse();
}
/**
* @depends testMappedElement
*/
function testParseInnerTree() {
$input = <<
BLA;
$reader = new Reader();
$reader->elementMap = [
'{http://sabredav.org/ns}elem1' => function(Reader $reader) {
$innerTree = $reader->parseInnerTree(['{http://sabredav.org/ns}elem1' => function(Reader $reader) {
$reader->next();
return "foobar";
}]);
return $innerTree;
}
];
$reader->xml($input);
$output = $reader->parse();
$expected = [
'name' => '{http://sabredav.org/ns}root',
'value' => [
[
'name' => '{http://sabredav.org/ns}elem1',
'value' => [
[
'name' => '{http://sabredav.org/ns}elem1',
'value' => 'foobar',
'attributes' => [],
]
],
'attributes' => [],
],
],
'attributes' => [],
];
$this->assertEquals($expected, $output);
}
/**
* @depends testParseInnerTree
*/
function testParseGetElements() {
$input = <<
BLA;
$reader = new Reader();
$reader->elementMap = [
'{http://sabredav.org/ns}elem1' => function(Reader $reader) {
$innerTree = $reader->parseGetElements(['{http://sabredav.org/ns}elem1' => function(Reader $reader) {
$reader->next();
return "foobar";
}]);
return $innerTree;
}
];
$reader->xml($input);
$output = $reader->parse();
$expected = [
'name' => '{http://sabredav.org/ns}root',
'value' => [
[
'name' => '{http://sabredav.org/ns}elem1',
'value' => [
[
'name' => '{http://sabredav.org/ns}elem1',
'value' => 'foobar',
'attributes' => [],
]
],
'attributes' => [],
],
],
'attributes' => [],
];
$this->assertEquals($expected, $output);
}
/**
* @depends testParseInnerTree
*/
function testParseGetElementsNoElements() {
$input = <<
hi
BLA;
$reader = new Reader();
$reader->elementMap = [
'{http://sabredav.org/ns}elem1' => function(Reader $reader) {
$innerTree = $reader->parseGetElements(['{http://sabredav.org/ns}elem1' => function(Reader $reader) {
$reader->next();
return "foobar";
}]);
return $innerTree;
}
];
$reader->xml($input);
$output = $reader->parse();
$expected = [
'name' => '{http://sabredav.org/ns}root',
'value' => [
[
'name' => '{http://sabredav.org/ns}elem1',
'value' => [],
'attributes' => [],
],
],
'attributes' => [],
];
$this->assertEquals($expected, $output);
}
}