Skip to content

Commit

Permalink
Tests for actually writing the XML to a file.
Browse files Browse the repository at this point in the history
  • Loading branch information
bertramakers committed May 19, 2015
1 parent 7bbc436 commit 4509e19
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 20 deletions.
33 changes: 23 additions & 10 deletions tests/SiteMapIndexXmlWriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,41 @@ class SiteMapIndexXmlWriterTest extends SiteMapXmlWriterTest
public function setUp()
{
$this->writer = new SiteMapIndexXmlWriter();
}

/**
* @test
*/
public function it_writes_the_expected_xml()
{
$entries = [];
$this->entries = [];

$location = Url::fromNative('http://cultuurnet.be/sitemap-foo.xml');
$entry = new SiteMapXmlEntry($location);
$entries[] = $entry;
$this->entries[] = $entry;

$location = Url::fromNative('http://cultuurnet.be/sitemap-bar.xml');
$lastModified = Date::fromNative('2015', 'May', '7');
$entry = new SiteMapXmlEntry($location);
$entry->setLastModified($lastModified);
$entries[] = $entry;
$this->entries[] = $entry;
}

$this->writeEntries($entries);
/**
* @test
*/
public function it_writes_the_expected_xml()
{
$this->writeEntries($this->entries);

$expected = file_get_contents(__DIR__ . '/xml/sitemap-index.xml');
$this->expectOutputString($expected);
}

/**
* @test
*/
public function it_can_write_the_xml_to_a_file()
{
$uri = tempnam(sys_get_temp_dir(), 'sitemap-index');
$this->writeEntries($this->entries, $uri);

$expected = file_get_contents(__DIR__ . '/xml/sitemap-index.xml');
$actual = file_get_contents($uri);
$this->assertEquals($expected, $actual);
}
}
33 changes: 23 additions & 10 deletions tests/SiteMapUrlSetXmlWriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,41 @@ class SiteMapUrlSetXmlWriterTest extends SiteMapXmlWriterTest
public function setUp()
{
$this->writer = new SiteMapUrlSetXmlWriter();
}

/**
* @test
*/
public function it_writes_the_expected_xml()
{
$entries = [];
$this->entries = [];

$location = Url::fromNative('http://cultuurnet.be/foo.html');
$entry = new SiteMapXmlEntry($location);
$entries[] = $entry;
$this->entries[] = $entry;

$location = Url::fromNative('http://cultuurnet.be/bar.html');
$lastModified = Date::fromNative('2015', 'May', '7');
$entry = new SiteMapXmlEntry($location);
$entry->setLastModified($lastModified);
$entries[] = $entry;
$this->entries[] = $entry;
}

$this->writeEntries($entries);
/**
* @test
*/
public function it_writes_the_expected_xml()
{
$this->writeEntries($this->entries);

$expected = file_get_contents(__DIR__ . '/xml/sitemap.xml');
$this->expectOutputString($expected);
}

/**
* @test
*/
public function it_can_write_the_xml_to_a_file()
{
$uri = tempnam(sys_get_temp_dir(), 'sitemap');
$this->writeEntries($this->entries, $uri);

$expected = file_get_contents(__DIR__ . '/xml/sitemap.xml');
$actual = file_get_contents($uri);
$this->assertEquals($expected, $actual);
}
}
5 changes: 5 additions & 0 deletions tests/SiteMapXmlWriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ abstract class SiteMapXmlWriterTest extends \PHPUnit_Framework_TestCase
*/
protected $writer;

/**
* @var SiteMapXmlEntry[]
*/
protected $entries;

/**
* @param SiteMapXmlEntry[] $entries
* Array of entries to write to XML.
Expand Down

0 comments on commit 4509e19

Please sign in to comment.