szurubooru/tests/Dao/PostDaoTest.php

112 lines
3 KiB
PHP
Raw Normal View History

<?php
namespace Szurubooru\Tests\Dao;
2014-09-01 20:51:59 +02:00
final class PostDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
{
2014-09-10 19:16:06 +02:00
public function testCreating()
{
2014-08-30 17:10:45 +02:00
$postDao = new \Szurubooru\Dao\PostDao($this->databaseConnection);
$post = new \Szurubooru\Entities\Post();
$post->setName('test');
2014-09-10 19:16:06 +02:00
$savedPost = $postDao->save($post);
$this->assertEquals('test', $post->getName());
$this->assertNotNull($savedPost->getId());
2014-09-10 19:16:06 +02:00
}
2014-09-10 19:16:06 +02:00
public function testUpdating()
{
$postDao = new \Szurubooru\Dao\PostDao($this->databaseConnection);
$post = new \Szurubooru\Entities\Post();
$post->setName('test');
2014-09-10 19:16:06 +02:00
$post = $postDao->save($post);
$this->assertEquals('test', $post->getName());
$id = $post->getId();
$post->setName($post->getName() . '2');
2014-09-10 19:16:06 +02:00
$post = $postDao->save($post);
$this->assertEquals('test2', $post->getName());
$this->assertEquals($id, $post->getId());
}
public function testGettingAll()
{
2014-08-30 17:10:45 +02:00
$postDao = new \Szurubooru\Dao\PostDao($this->databaseConnection);
$post1 = new \Szurubooru\Entities\Post();
$post1->setName('test2');
$post2 = new \Szurubooru\Entities\Post();
$post2->setName('test2');
$postDao->save($post1);
$postDao->save($post2);
$actual = $postDao->findAll();
$expected = [
$post1->getId() => $post1,
$post2->getId() => $post2,
];
$this->assertEquals($expected, $actual);
}
public function testGettingById()
{
2014-08-30 17:10:45 +02:00
$postDao = new \Szurubooru\Dao\PostDao($this->databaseConnection);
$post1 = new \Szurubooru\Entities\Post();
$post1->setName('test2');
$post2 = new \Szurubooru\Entities\Post();
$post2->setName('test2');
$postDao->save($post1);
$postDao->save($post2);
$actualPost1 = $postDao->findById($post1->getId());
$actualPost2 = $postDao->findById($post2->getId());
$this->assertEquals($post1, $actualPost1);
$this->assertEquals($post2, $actualPost2);
}
public function testDeletingAll()
{
2014-08-30 17:10:45 +02:00
$postDao = new \Szurubooru\Dao\PostDao($this->databaseConnection);
$post1 = new \Szurubooru\Entities\Post();
$post1->setName('test2');
$post2 = new \Szurubooru\Entities\Post();
$post2->setName('test2');
$postDao->save($post1);
$postDao->save($post2);
$postDao->deleteAll();
$actualPost1 = $postDao->findById($post1->getId());
$actualPost2 = $postDao->findById($post2->getId());
$this->assertEquals(null, $actualPost1);
$this->assertEquals(null, $actualPost2);
$this->assertEquals(0, count($postDao->findAll()));
}
public function testDeletingById()
{
2014-08-30 17:10:45 +02:00
$postDao = new \Szurubooru\Dao\PostDao($this->databaseConnection);
$post1 = new \Szurubooru\Entities\Post();
$post1->setName('test2');
$post2 = new \Szurubooru\Entities\Post();
$post2->setName('test2');
$postDao->save($post1);
$postDao->save($post2);
$postDao->deleteById($post1->getId());
$actualPost1 = $postDao->findById($post1->getId());
$actualPost2 = $postDao->findById($post2->getId());
$this->assertEquals(null, $actualPost1);
$this->assertEquals($actualPost2, $actualPost2);
$this->assertEquals(1, count($postDao->findAll()));
}
}