Improved compatibility with MySQL

This commit is contained in:
Marcin Kurczewski 2014-09-28 16:26:44 +02:00
parent 6d7566ee2f
commit c0bc4d4f19
31 changed files with 127 additions and 95 deletions

View file

@ -12,6 +12,8 @@ activationBodyPath = mail/activation.txt
[database]
dsn = sqlite:db.sqlite
user =
password =
maxPostSize = 10485760 ;10mb
maxCustomThumbnailSize = 1048576 ;1mb

View file

@ -133,6 +133,8 @@ abstract class AbstractDao implements ICrudDao
protected function findBy($columnName, $value)
{
if (is_array($value) and empty($value))
return [];
$query = $this->fpdo->from($this->tableName)->where($columnName, $value);
$arrayEntities = iterator_to_array($query);
return $this->arrayToEntities($arrayEntities);

View file

@ -19,4 +19,16 @@ abstract class AbstractEntityConverter implements IEntityConverter
}
protected abstract function toBasicEntity(array $array);
protected function dbTimeToEntityTime($time)
{
if ($time === null)
return null;
return date('c', strtotime($time));
}
protected function entityTimeToDbTime($time)
{
return $time;
}
}

View file

@ -10,7 +10,7 @@ class FavoriteEntityConverter extends AbstractEntityConverter implements IEntity
'id' => $entity->getId(),
'userId' => $entity->getUserId(),
'postId' => $entity->getPostId(),
'time' => $entity->getTime(),
'time' => $this->entityTimeToDbTime($entity->getTime()),
];
}
@ -19,7 +19,7 @@ class FavoriteEntityConverter extends AbstractEntityConverter implements IEntity
$entity = new \Szurubooru\Entities\Favorite($array['id']);
$entity->setUserId($array['userId']);
$entity->setPostId($array['postId']);
$entity->setTime($array['time']);
$entity->setTime($this->dbTimeToEntityTime($array['time']));
return $entity;
}
}

View file

@ -8,16 +8,16 @@ class GlobalParamEntityConverter extends AbstractEntityConverter implements IEnt
return
[
'id' => $entity->getId(),
'key' => $entity->getKey(),
'value' => $entity->getValue(),
'dataKey' => $entity->getKey(),
'dataValue' => $entity->getValue(),
];
}
public function toBasicEntity(array $array)
{
$entity = new \Szurubooru\Entities\GlobalParam($array['id']);
$entity->setKey($array['key']);
$entity->setValue($array['value']);
$entity->setKey($array['dataKey']);
$entity->setValue($array['dataValue']);
return $entity;
}
}

View file

@ -10,8 +10,8 @@ class PostEntityConverter extends AbstractEntityConverter implements IEntityConv
'id' => $entity->getId(),
'name' => $entity->getName(),
'userId' => $entity->getUserId(),
'uploadTime' => $entity->getUploadTime(),
'lastEditTime' => $entity->getLastEditTime(),
'uploadTime' => $this->entityTimeToDbTime($entity->getUploadTime()),
'lastEditTime' => $this->entityTimeToDbTime($entity->getLastEditTime()),
'safety' => $entity->getSafety(),
'contentType' => $entity->getContentType(),
'contentChecksum' => $entity->getContentChecksum(),
@ -22,7 +22,7 @@ class PostEntityConverter extends AbstractEntityConverter implements IEntityConv
'originalFileSize' => $entity->getOriginalFileSize(),
'originalFileName' => $entity->getOriginalFileName(),
'featureCount' => $entity->getFeatureCount(),
'lastFeatureTime' => $entity->getLastFeatureTime(),
'lastFeatureTime' => $this->entityTimeToDbTime($entity->getLastFeatureTime()),
];
}
@ -31,8 +31,8 @@ class PostEntityConverter extends AbstractEntityConverter implements IEntityConv
$entity = new \Szurubooru\Entities\Post(intval($array['id']));
$entity->setName($array['name']);
$entity->setUserId($array['userId']);
$entity->setUploadTime($array['uploadTime']);
$entity->setLastEditTime($array['lastEditTime']);
$entity->setUploadTime($this->dbTimeToEntityTime($array['uploadTime']));
$entity->setLastEditTime($this->dbTimeToEntityTime($array['lastEditTime']));
$entity->setSafety(intval($array['safety']));
$entity->setContentType(intval($array['contentType']));
$entity->setContentChecksum($array['contentChecksum']);
@ -43,7 +43,7 @@ class PostEntityConverter extends AbstractEntityConverter implements IEntityConv
$entity->setOriginalFileSize($array['originalFileSize']);
$entity->setOriginalFileName($array['originalFileName']);
$entity->setFeatureCount(intval($array['featureCount']));
$entity->setLastFeatureTime($array['lastFeatureTime']);
$entity->setLastFeatureTime($this->dbTimeToEntityTime($array['lastFeatureTime']));
$entity->setMeta(\Szurubooru\Entities\Post::META_TAG_COUNT, intval($array['tagCount']));
$entity->setMeta(\Szurubooru\Entities\Post::META_FAV_COUNT, intval($array['favCount']));
$entity->setMeta(\Szurubooru\Entities\Post::META_SCORE, intval($array['score']));

View file

@ -10,7 +10,7 @@ class PostScoreEntityConverter extends AbstractEntityConverter implements IEntit
'id' => $entity->getId(),
'userId' => $entity->getUserId(),
'postId' => $entity->getPostId(),
'time' => $entity->getTime(),
'time' => $this->entityTimeToDbTime($entity->getTime()),
'score' => $entity->getScore(),
];
}
@ -20,7 +20,7 @@ class PostScoreEntityConverter extends AbstractEntityConverter implements IEntit
$entity = new \Szurubooru\Entities\PostScore($array['id']);
$entity->setUserId($array['userId']);
$entity->setPostId($array['postId']);
$entity->setTime($array['time']);
$entity->setTime($this->dbTimeToEntityTime($array['time']));
$entity->setScore(intval($array['score']));
return $entity;
}

View file

@ -8,7 +8,7 @@ class SnapshotEntityConverter extends AbstractEntityConverter implements IEntity
return
[
'id' => $entity->getId(),
'time' => $entity->getTime(),
'time' => $this->entityTimeToDbTime($entity->getTime()),
'type' => $entity->getType(),
'primaryKey' => $entity->getPrimaryKey(),
'userId' => $entity->getUserId(),
@ -21,7 +21,7 @@ class SnapshotEntityConverter extends AbstractEntityConverter implements IEntity
public function toBasicEntity(array $array)
{
$entity = new \Szurubooru\Entities\Snapshot(intval($array['id']));
$entity->setTime($array['time']);
$entity->setTime($this->dbTimeToEntityTime($array['time']));
$entity->setType(intval($array['type']));
$entity->setPrimaryKey($array['primaryKey']);
$entity->setUserId($array['userId']);

View file

@ -13,8 +13,8 @@ class UserEntityConverter extends AbstractEntityConverter implements IEntityConv
'emailUnconfirmed' => $entity->getEmailUnconfirmed(),
'passwordHash' => $entity->getPasswordHash(),
'accessRank' => $entity->getAccessRank(),
'registrationTime' => $entity->getRegistrationTime(),
'lastLoginTime' => $entity->getLastLoginTime(),
'registrationTime' => $this->entityTimeToDbTime($entity->getRegistrationTime()),
'lastLoginTime' => $this->entityTimeToDbTime($entity->getLastLoginTime()),
'avatarStyle' => $entity->getAvatarStyle(),
'browsingSettings' => $entity->getBrowsingSettings(),
'accountConfirmed' => $entity->isAccountConfirmed(),
@ -29,8 +29,8 @@ class UserEntityConverter extends AbstractEntityConverter implements IEntityConv
$entity->setEmailUnconfirmed($array['emailUnconfirmed']);
$entity->setPasswordHash($array['passwordHash']);
$entity->setAccessRank(intval($array['accessRank']));
$entity->setRegistrationTime($array['registrationTime']);
$entity->setLastLoginTime($array['lastLoginTime']);
$entity->setRegistrationTime($this->dbTimeToEntityTime($array['registrationTime']));
$entity->setLastLoginTime($this->dbTimeToEntityTime($array['lastLoginTime']));
$entity->setAvatarStyle(intval($array['avatarStyle']));
$entity->setBrowsingSettings($array['browsingSettings']);
$entity->setAccountConfirmed($array['accountConfirmed']);

View file

@ -24,11 +24,11 @@ class GlobalParamDao extends AbstractDao implements ICrudDao
public function findByKey($key)
{
return $this->findOneBy('key', $key);
return $this->findOneBy('dataKey', $key);
}
public function deleteByKey($key)
{
return $this->deleteBy('key', $key);
return $this->deleteBy('dataKey', $key);
}
}

View file

@ -30,7 +30,8 @@ class DatabaseConnection
$cwd = getcwd();
if ($this->config->getDataDirectory())
chdir($this->config->getDataDirectory());
$this->pdo = new \PDO($this->config->database->dsn);
$this->pdo = new \PDO($this->config->database->dsn, $this->config->database->user,
$this->config->database->password);
$this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
chdir($cwd);
}

View file

@ -52,8 +52,8 @@ class UserEditFormData implements \Szurubooru\IValidatable
{
if (!is_string($this->browsingSettings))
throw new \InvalidArgumentException('Browsing settings must be stringified JSON.');
else if (strlen($this->browsingSettings) > 2000)
throw new \InvalidArgumentException('Stringified browsing settings can have at most 2000 characters.');
else if (strlen($this->browsingSettings) > 300)
throw new \InvalidArgumentException('Stringified browsing settings can have at most 300 characters.');
}
}
}

View file

@ -5,36 +5,38 @@ class Upgrade01 implements IUpgrade
{
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
{
$driver = $databaseConnection->getPDO()->getAttribute(\PDO::ATTR_DRIVER_NAME);
$databaseConnection->getPDO()->exec('
CREATE TABLE "users"
CREATE TABLE users
(
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
passwordHash TEXT NOT NULL,
email TEXT,
emailUnconfirmed TEXT,
id INTEGER PRIMARY KEY ' . ($driver === 'mysql' ? 'AUTO_INCREMENT' : 'AUTOINCREMENT') . ',
name VARCHAR(50) NOT NULL,
passwordHash VARCHAR(64) NOT NULL,
email VARCHAR(200),
emailUnconfirmed VARCHAR(200),
accessRank INTEGER NOT NULL,
browsingSettings TEXT,
banned INTEGER,
registrationTime INTEGER DEFAULT NULL,
lastLoginTime INTEGER DEFAULT NULL,
browsingSettings VARCHAR(300),
banned BOOLEAN DEFAULT FALSE,
registrationTime DATETIME DEFAULT NULL,
lastLoginTime DATETIME DEFAULT NULL,
avatarStyle INTEGER DEFAULT 1
);');
$databaseConnection->getPDO()->exec('
CREATE TABLE "tokens"
CREATE TABLE tokens
(
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
id INTEGER PRIMARY KEY ' . ($driver === 'mysql' ? 'AUTO_INCREMENT' : 'AUTOINCREMENT') . ',
name VARCHAR(200) NOT NULL,
purpose INTEGER NOT NULL,
additionalData TEXT
additionalData VARCHAR(200)
);');
$databaseConnection->getPDO()->exec('
CREATE TABLE "posts"
CREATE TABLE posts
(
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL
id INTEGER PRIMARY KEY ' . ($driver === 'mysql' ? 'AUTO_INCREMENT' : 'AUTOINCREMENT') . ',
name VARCHAR(200) NOT NULL
);');
}
}

View file

@ -6,6 +6,6 @@ class Upgrade02 implements IUpgrade
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
{
$databaseConnection->getPDO()->exec('
ALTER TABLE "users" ADD COLUMN accountConfirmed BOOLEAN NOT NULL DEFAULT FALSE');
ALTER TABLE users ADD COLUMN accountConfirmed BOOLEAN NOT NULL DEFAULT FALSE');
}
}

View file

@ -5,37 +5,40 @@ class Upgrade03 implements IUpgrade
{
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
{
$databaseConnection->getPDO()->exec('DROP TABLE "posts"');
$pdo = $databaseConnection->getPDO();
$driver = $pdo->getAttribute(\PDO::ATTR_DRIVER_NAME);
$databaseConnection->getPDO()->exec('
CREATE TABLE "posts"
$pdo->exec('DROP TABLE IF EXISTS posts');
$pdo->exec('
CREATE TABLE posts
(
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
id INTEGER PRIMARY KEY ' . ($driver === 'mysql' ? 'AUTO_INCREMENT' : 'AUTOINCREMENT') . ',
name VARCHAR(40) NOT NULL,
userId INTEGER,
uploadTime TIMESTAMP NOT NULL,
lastEditTime TIMESTAMP,
uploadTime DATETIME NOT NULL,
lastEditTime DATETIME,
safety INTEGER NOT NULL,
contentType INTEGER NOT NULL,
contentChecksum TEXT NOT NULL,
source TEXT,
contentChecksum VARCHAR(64) NOT NULL,
source VARCHAR(200),
imageWidth INTEGER,
imageHeight INTEGER,
originalFileSize INTEGER,
originalFileName TEXT
originalFileName VARCHAR(200)
)');
$databaseConnection->getPDO()->exec('
CREATE TABLE "tags"
$pdo->exec('
CREATE TABLE tags
(
name TEXT PRIMARY KEY NOT NULL
name VARCHAR(64) PRIMARY KEY NOT NULL
)');
$databaseConnection->getPDO()->exec('
CREATE TABLE "postTags"
$pdo->exec('
CREATE TABLE postTags
(
postId INTEGER NOT NULL,
tagName TEXT NOT NULL,
tagName VARCHAR(64) NOT NULL,
PRIMARY KEY (postId, tagName)
)');
}

View file

@ -19,7 +19,7 @@ class Upgrade04 implements IUpgrade
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
{
$databaseConnection->getPDO()->exec('ALTER TABLE "posts" ADD COLUMN contentMimeType TEXT DEFAULT NULL');
$databaseConnection->getPDO()->exec('ALTER TABLE posts ADD COLUMN contentMimeType VARCHAR(64) DEFAULT NULL');
$posts = $this->postDao->findAll();
foreach ($posts as $post)

View file

@ -6,12 +6,13 @@ class Upgrade05 implements IUpgrade
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
{
$pdo = $databaseConnection->getPDO();
$driver = $pdo->getAttribute(\PDO::ATTR_DRIVER_NAME);
$pdo->exec('
CREATE TABLE tags2
(
id INTEGER PRIMARY KEY NOT NULL,
name TEXT UNIQUE NOT NULL,
id INTEGER PRIMARY KEY ' . ($driver === 'mysql' ? 'AUTO_INCREMENT' : 'AUTOINCREMENT') . ',
name VARCHAR(64) UNIQUE NOT NULL,
usages INTEGER NOT NULL DEFAULT 0
)');
$pdo->exec('INSERT INTO tags2(name, usages) SELECT name, (SELECT COUNT(1) FROM postTags WHERE tagName = tags.name) FROM tags');

View file

@ -7,8 +7,6 @@ class Upgrade06 implements IUpgrade
{
$pdo = $databaseConnection->getPDO();
$pdo->exec('ALTER TABLE posts ADD COLUMN tagCount INTEGER NOT NULL DEFAULT 0');
$pdo->exec('
CREATE TRIGGER postTagsDelete BEFORE DELETE ON postTags
FOR EACH ROW
@ -34,5 +32,7 @@ class Upgrade06 implements IUpgrade
UPDATE tags SET usages = usages + 1 WHERE tags.id = NEW.tagId;
UPDATE tags SET usages = usages - 1 WHERE tags.id = OLD.tagId;
END');
$pdo->exec('ALTER TABLE posts ADD COLUMN tagCount INTEGER NOT NULL DEFAULT 0');
}
}

View file

@ -6,15 +6,16 @@ class Upgrade07 implements IUpgrade
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
{
$pdo = $databaseConnection->getPDO();
$pdo->exec('ALTER TABLE posts ADD COLUMN featureCount INTEGER NOT NULL DEFAULT 0');
$pdo->exec('ALTER TABLE posts ADD COLUMN lastFeatureTime TIMESTAMP');
$driver = $pdo->getAttribute(\PDO::ATTR_DRIVER_NAME);
$pdo->exec('CREATE TABLE globals
(
id INTEGER PRIMARY KEY NOT NULL,
key TEXT UNIQUE NOT NULL,
value TEXT
id INTEGER PRIMARY KEY ' . ($driver === 'mysql' ? 'AUTO_INCREMENT' : 'AUTOINCREMENT') . ',
dataKey VARCHAR(32) UNIQUE NOT NULL,
dataValue VARCHAR(64)
)');
$pdo->exec('ALTER TABLE posts ADD COLUMN featureCount INTEGER NOT NULL DEFAULT 0');
$pdo->exec('ALTER TABLE posts ADD COLUMN lastFeatureTime DATETIME');
}
}

View file

@ -6,10 +6,11 @@ class Upgrade08 implements IUpgrade
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
{
$pdo = $databaseConnection->getPDO();
$driver = $pdo->getAttribute(\PDO::ATTR_DRIVER_NAME);
$pdo->exec('CREATE TABLE postRelations
(
id INTEGER PRIMARY KEY NOT NULL,
id INTEGER PRIMARY KEY ' . ($driver === 'mysql' ? 'AUTO_INCREMENT' : 'AUTOINCREMENT') . ',
post1id INTEGER NOT NULL,
post2id INTEGER NOT NULL,
UNIQUE (post1id, post2id)

View file

@ -17,13 +17,14 @@ class Upgrade09 implements IUpgrade
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
{
$pdo = $databaseConnection->getPDO();
$driver = $pdo->getAttribute(\PDO::ATTR_DRIVER_NAME);
$pdo->exec('DROP TABLE IF EXISTS snapshots');
$pdo->exec('CREATE TABLE snapshots
(
id INTEGER PRIMARY KEY NOT NULL,
time TIMESTAMP NOT NULL,
id INTEGER PRIMARY KEY ' . ($driver === 'mysql' ? 'AUTO_INCREMENT' : 'AUTOINCREMENT') . ',
time DATETIME NOT NULL,
type INTEGER NOT NULL,
primaryKey TEXT NOT NULL,
operation INTEGER NOT NULL,

View file

@ -6,16 +6,14 @@ class Upgrade10 implements IUpgrade
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
{
$pdo = $databaseConnection->getPDO();
$pdo->exec('ALTER TABLE posts ADD COLUMN favCount INTEGER NOT NULL DEFAULT 0');
$pdo->exec('ALTER TABLE posts ADD COLUMN lastFavTime TIMESTAMP');
$driver = $pdo->getAttribute(\PDO::ATTR_DRIVER_NAME);
$pdo->exec('CREATE TABLE favorites
(
id INTEGER PRIMARY KEY NOT NULL,
id INTEGER PRIMARY KEY ' . ($driver === 'mysql' ? 'AUTO_INCREMENT' : 'AUTOINCREMENT') . ',
userId INTEGER NOT NULL,
postId INTEGER NOT NULL,
time TIMESTAMP NOT NULL,
time DATETIME NOT NULL,
UNIQUE (userId, postId)
)');
@ -55,5 +53,8 @@ class Upgrade10 implements IUpgrade
WHERE favorites.postId = posts.id)
WHERE posts.id IN (OLD.postId, NEW.postId);
END');
$pdo->exec('ALTER TABLE posts ADD COLUMN favCount INTEGER NOT NULL DEFAULT 0');
$pdo->exec('ALTER TABLE posts ADD COLUMN lastFavTime DATETIME');
}
}

View file

@ -6,15 +6,14 @@ class Upgrade11 implements IUpgrade
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
{
$pdo = $databaseConnection->getPDO();
$pdo->exec('ALTER TABLE posts ADD COLUMN score INTEGER NOT NULL DEFAULT 0');
$driver = $pdo->getAttribute(\PDO::ATTR_DRIVER_NAME);
$pdo->exec('CREATE TABLE postScores
(
id INTEGER PRIMARY KEY NOT NULL,
id INTEGER PRIMARY KEY ' . ($driver === 'mysql' ? 'AUTO_INCREMENT' : 'AUTOINCREMENT') . ',
userId INTEGER NOT NULL,
postId INTEGER NOT NULL,
time TIMESTAMP NOT NULL,
time DATETIME NOT NULL,
score INTEGER NOT NULL,
UNIQUE (userId, postId)
)');
@ -54,5 +53,7 @@ class Upgrade11 implements IUpgrade
WHERE postScores.postId = posts.id)
WHERE posts.id = NEW.postId;
END');
$pdo->exec('ALTER TABLE posts ADD COLUMN score INTEGER NOT NULL DEFAULT 0');
}
}

View file

@ -93,6 +93,8 @@ class Validator
throw new \DomainException('Tags cannot be empty.');
}
$this->validateMaxLength($tag, 64, 'Tag');
foreach ($illegalCharacters as $char)
{
if (strpos($tag, $char) !== false)

View file

@ -10,6 +10,8 @@ abstract class AbstractDatabaseTestCase extends \Szurubooru\Tests\AbstractTestCa
parent::setUp();
$config = $this->mockConfig($this->createTestDirectory());
$config->set('database/dsn', 'sqlite::memory:');
$config->set('database/user', '');
$config->set('database/password', '');
$this->databaseConnection = new \Szurubooru\DatabaseConnection($config);
\Szurubooru\Injector::set(\Szurubooru\DatabaseConnection::class, $this->databaseConnection);

View file

@ -26,7 +26,7 @@ class FavoritesDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
$favorite = new \Szurubooru\Entities\Favorite();
$favorite->setUser($user);
$favorite->setPost($post);
$favorite->setTime('whatever');
$favorite->setTime(date('c'));
$favoritesDao = $this->getFavoritesDao();
$favoritesDao->save($favorite);
@ -36,7 +36,7 @@ class FavoritesDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
$savedFavorite = $favoritesDao->findById($favorite->getId());
$this->assertEquals(1, $savedFavorite->getUserId());
$this->assertEquals(2, $savedFavorite->getPostId());
$this->assertEquals('whatever', $savedFavorite->getTime());
$this->assertEquals($favorite->getTime(), $savedFavorite->getTime());
$this->assertEntitiesEqual($user, $savedFavorite->getUser());
$this->assertEntitiesEqual($post, $savedFavorite->getPost());
}

View file

@ -293,7 +293,7 @@ final class PostDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
{
$post = new \Szurubooru\Entities\Post();
$post->setName('test');
$post->setUploadTime('whatever');
$post->setUploadTime(date('c'));
$post->setSafety(\Szurubooru\Entities\Post::POST_SAFETY_SAFE);
$post->setContentType(\Szurubooru\Entities\Post::POST_TYPE_YOUTUBE);
$post->setContentChecksum('whatever');

View file

@ -26,7 +26,7 @@ class PostScoreDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
$postScore = new \Szurubooru\Entities\PostScore();
$postScore->setUser($user);
$postScore->setPost($post);
$postScore->setTime('whatever');
$postScore->setTime(date('c'));
$postScore->setScore(1);
$postScoreDao = $this->getPostScoreDao();
$postScoreDao->save($postScore);
@ -37,7 +37,7 @@ class PostScoreDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
$savedPostScore = $postScoreDao->findById($postScore->getId());
$this->assertEquals(1, $savedPostScore->getUserId());
$this->assertEquals(2, $savedPostScore->getPostId());
$this->assertEquals('whatever', $savedPostScore->getTime());
$this->assertEquals($postScore->getTime(), $savedPostScore->getTime());
$this->assertEntitiesEqual($user, $savedPostScore->getUser());
$this->assertEntitiesEqual($post, $savedPostScore->getPost());
}
@ -52,19 +52,19 @@ class PostScoreDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
$postScore1 = new \Szurubooru\Entities\PostScore();
$postScore1->setUser($user1);
$postScore1->setPost($post1);
$postScore1->setTime('time1');
$postScore1->setTime(date('c', mktime(1)));
$postScore1->setScore(1);
$postScore2 = new \Szurubooru\Entities\PostScore();
$postScore2->setUser($user2);
$postScore2->setPost($post2);
$postScore2->setTime('time2');
$postScore2->setTime(date('c', mktime(2)));
$postScore2->setScore(0);
$postScore3 = new \Szurubooru\Entities\PostScore();
$postScore3->setUser($user1);
$postScore3->setPost($post2);
$postScore3->setTime('time3');
$postScore3->setTime(date('c', mktime(3)));
$postScore3->setScore(-1);
$postScoreDao = $this->getPostScoreDao();

View file

@ -40,7 +40,7 @@ class SnapshotDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
$snapshot->setType(\Szurubooru\Entities\Snapshot::TYPE_POST);
$snapshot->setData(['wake up', 'neo', ['follow' => 'white rabbit']]);
$snapshot->setPrimaryKey(1);
$snapshot->setTime('whateveer');
$snapshot->setTime(date('c', mktime(1, 2, 3)));
$snapshot->setUserId(null);
$snapshot->setOperation(\Szurubooru\Entities\Snapshot::OPERATION_CHANGE);
return $snapshot;

View file

@ -151,8 +151,8 @@ class UserDaoFilterTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
$user = new \Szurubooru\Entities\User();
$user->setName($userName);
$user->setPasswordHash('whatever');
$user->setLastLoginTime('whatever');
$user->setRegistrationTime('whatever');
$user->setLastLoginTime(date('c', mktime(1, 2, 3)));
$user->setRegistrationTime(date('c', mktime(3, 2, 1)));
$user->setAccessRank(\Szurubooru\Entities\User::ACCESS_RANK_REGULAR_USER);
return $user;
}

View file

@ -114,8 +114,8 @@ final class UserDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
$user = new \Szurubooru\Entities\User();
$user->setName('test');
$user->setPasswordHash('whatever');
$user->setLastLoginTime('whatever');
$user->setRegistrationTime('whatever');
$user->setLastLoginTime(date('c', mktime(1, 2, 3)));
$user->setRegistrationTime(date('c', mktime(3, 2, 1)));
$user->setAccessRank(\Szurubooru\Entities\User::ACCESS_RANK_REGULAR_USER);
return $user;
}