Sonata\Exporter\Test\Writer\GsaFeedWriterTest::testSimpleWrite PHP Method

testSimpleWrite() public method

Tests a simple write case.
public testSimpleWrite ( )
    public function testSimpleWrite()
    {
        $writer = new GsaFeedWriter($this->folder, $this->dtd, $this->datasource, $this->feedtype);
        $writer->open();
        $writer->write(array('url' => 'https://sonata-project.org/about', 'mime_type' => 'text/html', 'action' => 'add'));
        $writer->write(array('url' => 'https://sonata-project.org/bundles/', 'mime_type' => 'text/html', 'action' => 'delete'));
        $writer->close();
        $generatedFiles = $this->getFiles();
        $this->assertCount(1, $generatedFiles);
        $this->assertEquals($this->folder . '/feed_00001.xml', $generatedFiles[0]);
        // this will throw an exception if the xml is invalid
        new \SimpleXMLElement(file_get_contents($generatedFiles[0]), LIBXML_PARSEHUGE);
        $expected = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE gsafeed PUBLIC "-//Google//DTD GSA Feeds//EN" "{$this->dtd}">
<gsafeed>
    <header>
        <datasource>{$this->datasource}</datasource>
        <feedtype>{$this->feedtype}</feedtype>
    </header>

    <group>
        <record url="https://sonata-project.org/about" mimetype="text/html" action="add"/>
        <record url="https://sonata-project.org/bundles/" mimetype="text/html" action="delete"/>
    </group>
</gsafeed>
XML;
        $this->assertEquals(trim($expected), file_get_contents($generatedFiles[0]));
    }