writer = new Writer(); $this->writer->namespaceMap = [ 'http://sabredav.org/ns' => 's', ]; $this->writer->openMemory(); $this->writer->setIndent(true); $this->writer->startDocument(); } function compare($input, $output) { $this->writer->write($input); $this->assertEquals($output, $this->writer->outputMemory()); } function testSimple() { $this->compare([ '{http://sabredav.org/ns}root' => 'text', ], << text HI ); } /** * @depends testSimple */ function testSimpleQuotes() { $this->compare([ '{http://sabredav.org/ns}root' => '"text"', ], << "text" HI ); } function testSimpleAttributes() { $this->compare([ '{http://sabredav.org/ns}root' => [ 'value' => 'text', 'attributes' => [ 'attr1' => 'attribute value', ], ], ], << text HI ); } function testMixedSyntax() { $this->compare([ '{http://sabredav.org/ns}root' => [ 'single' => 'value', 'multiple' => [ [ 'name' => 'foo', 'value' => 'bar', ], [ 'name' => 'foo', 'value' => 'foobar', ], ], 'attributes' => [ 'value' => null, 'attributes' => [ 'foo' => 'bar', ], ], [ 'name' => 'verbose', 'value' => 'syntax', 'attributes' => [ 'foo' => 'bar', ], ], ], ], << value bar foobar syntax HI ); } function testNull() { $this->compare([ '{http://sabredav.org/ns}root' => null, ], << HI ); } function testArrayFormat2() { $this->compare([ '{http://sabredav.org/ns}root' => [ [ 'name' => '{http://sabredav.org/ns}elem1', 'value' => 'text', 'attributes' => [ 'attr1' => 'attribute value', ], ], ], ], << text HI ); } function testCustomNamespace() { $this->compare([ '{http://sabredav.org/ns}root' => [ '{urn:foo}elem1' => 'bar', ], ], << bar HI ); } function testEmptyNamespace() { // Empty namespaces are allowed, so we should support this. $this->compare([ '{http://sabredav.org/ns}root' => [ '{}elem1' => 'bar', ], ], << bar HI ); } function testAttributes() { $this->compare([ '{http://sabredav.org/ns}root' => [ [ 'name' => '{http://sabredav.org/ns}elem1', 'value' => 'text', 'attributes' => [ 'attr1' => 'val1', '{http://sabredav.org/ns}attr2' => 'val2', '{urn:foo}attr3' => 'val3', ], ], ], ], << text HI ); } /** * @expectedException \InvalidArgumentException */ function testInvalidFormat() { $this->compare([ '{http://sabredav.org/ns}root' => [ ['incorrect' => '0', 'keynames' => 1] ], ], ""); } function testBaseElement() { $this->compare([ '{http://sabredav.org/ns}root' => new Element\Base('hello') ], << hello HI ); } function testElementObj() { $this->compare([ '{http://sabredav.org/ns}root' => new Element\Mock() ], << hiiii! HI ); } function testEmptyNamespacePrefix() { $this->writer->namespaceMap['http://sabredav.org/ns'] = null; $this->compare([ '{http://sabredav.org/ns}root' => new Element\Mock() ], << hiiii! HI ); } function testWriteElement() { $this->writer->writeElement("{http://sabredav.org/ns}foo", 'content'); $output = << content HI; $this->assertEquals($output, $this->writer->outputMemory()); } function testWriteElementComplex() { $this->writer->writeElement("{http://sabredav.org/ns}foo", new Element\KeyValue(['{http://sabredav.org/ns}bar' => 'test'])); $output = << test HI; $this->assertEquals($output, $this->writer->outputMemory()); } /** * @expectedException \InvalidArgumentException */ function testWriteBadObject() { $this->writer->write(new \StdClass()); } function testStartElementSimple() { $this->writer->startElement("foo"); $this->writer->endElement(); $output = << HI; $this->assertEquals($output, $this->writer->outputMemory()); } }