Files
sitemap-plugin/tests/Model/SitemapTest.php
Joachim Løvgaard 673fcd6b5b Refactoring models (#87)
* Refactoring models:
- Renaming (also of associated factories)
- Added constructors
- Added UrlAlternative model together with a factory
-adding upgrade info regarding models
2019-07-01 15:46:13 +02:00

68 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\SitemapPlugin\Model;
use PHPUnit\Framework\TestCase;
use SitemapPlugin\Model\Sitemap;
use SitemapPlugin\Model\Url;
final class SitemapTest extends TestCase
{
public function testInit()
{
$obj = new Sitemap();
$this->assertEmpty($obj->getUrls());
$this->assertNull($obj->getLocalization());
$this->assertNull($obj->getLastModification());
}
public function testUrls()
{
$obj = new Sitemap();
$sitemapUrl = new Url('location');
$sitemapUrl->setLocation('url');
$sitemapUrlTwo = new Url('location');
$sitemapUrlTwo->setLocation('url2');
$obj->addUrl($sitemapUrl);
$this->assertCount(1, $obj->getUrls());
$this->assertTrue(\is_iterable($obj->getUrls()));
$this->assertEquals([$sitemapUrl], $obj->getUrls());
$obj->setUrls([$sitemapUrl, $sitemapUrlTwo]);
$this->assertCount(2, $obj->getUrls());
$this->assertTrue(\is_iterable($obj->getUrls()));
$this->assertEquals([$sitemapUrl, $sitemapUrlTwo], $obj->getUrls());
$obj->removeUrl($sitemapUrlTwo);
$this->assertCount(1, $obj->getUrls());
$this->assertTrue(\is_iterable($obj->getUrls()));
$this->assertEquals([$sitemapUrl], $obj->getUrls());
}
public function testLocalization()
{
$obj = new Sitemap();
$obj->setLocalization('test');
$this->assertEquals('test', $obj->getLocalization());
}
public function testModificationDate()
{
$obj = new Sitemap();
$date = new \DateTimeImmutable();
$obj->setLastModification($date);
$this->assertEquals($date, $obj->getLastModification());
}
}