szurubooru/tests/Dao/GlobalParamDaoTest.php

68 lines
1.9 KiB
PHP
Raw Normal View History

2014-09-24 23:24:51 +02:00
<?php
namespace Szurubooru\Tests\Dao;
use Szurubooru\Dao\GlobalParamDao;
use Szurubooru\Entities\GlobalParam;
use Szurubooru\Tests\AbstractDatabaseTestCase;
2014-09-24 23:24:51 +02:00
final class GlobalParamDaoTest extends AbstractDatabaseTestCase
2014-09-24 23:24:51 +02:00
{
2015-11-25 09:48:03 +01:00
public function testSettingValues()
{
$expected = new GlobalParam();
$expected->setKey('key');
$expected->setValue('test');
2014-09-24 23:24:51 +02:00
2015-11-25 09:48:03 +01:00
$globalParamDao = $this->getGlobalParamDao();
$globalParamDao->save($expected);
2014-09-24 23:24:51 +02:00
2015-11-25 09:48:03 +01:00
$actual = $globalParamDao->findByKey($expected->getKey());
$this->assertEntitiesEqual($actual, $expected);
}
2014-09-24 23:24:51 +02:00
2015-11-25 09:48:03 +01:00
public function testInsertingSameKeyTwice()
{
$param1 = new GlobalParam();
$param1->setKey('key');
$param1->setValue('value1');
2014-09-24 23:24:51 +02:00
2015-11-25 09:48:03 +01:00
$param2 = new GlobalParam();
$param2->setKey('key');
$param2->setValue('value2');
2014-09-24 23:24:51 +02:00
2015-11-25 09:48:03 +01:00
$globalParamDao = $this->getGlobalParamDao();
$globalParamDao->save($param1);
$globalParamDao->save($param2);
2014-09-24 23:24:51 +02:00
2015-11-25 09:48:03 +01:00
$this->assertEquals([$param2], array_values($globalParamDao->findAll()));
}
2014-09-24 23:24:51 +02:00
2015-11-25 09:48:03 +01:00
public function testUpdatingValues()
{
$expected = new GlobalParam();
$expected->setKey('key');
$expected->setValue('test');
2014-09-24 23:24:51 +02:00
2015-11-25 09:48:03 +01:00
$globalParamDao = $this->getGlobalParamDao();
$globalParamDao->save($expected);
2014-09-24 23:24:51 +02:00
2015-11-25 09:48:03 +01:00
$expected->setKey('key2');
$expected->setValue('test2');
$globalParamDao->save($expected);
2014-09-24 23:24:51 +02:00
2015-11-25 09:48:03 +01:00
$actual = $globalParamDao->findByKey($expected->getKey());
$this->assertEntitiesEqual($actual, $expected);
}
2014-09-24 23:24:51 +02:00
2015-11-25 09:48:03 +01:00
public function testRetrievingUnknownKeys()
{
$globalParamDao = $this->getGlobalParamDao();
$actual = $globalParamDao->findByKey('hey i dont exist');
$this->assertNull($actual);
}
2014-09-24 23:24:51 +02:00
2015-11-25 09:48:03 +01:00
private function getGlobalParamDao()
{
return new GlobalParamDao($this->databaseConnection);
}
2014-09-24 23:24:51 +02:00
}