szurubooru/tests/AbstractTest.php

63 lines
1.2 KiB
PHP
Raw Normal View History

2014-05-04 21:23:12 +02:00
<?php
class AbstractTest
{
public $assert;
public function __construct()
{
$this->assert = new Assert();
}
public function setup()
{
}
public function teardown()
{
}
protected function mockUser()
{
$user = UserModel::spawn();
$user->setAccessRank(new AccessRank(AccessRank::Registered));
$user->setName('dummy');
$user->passHash = UserModel::hashPassword('ble', $user->passSalt);
return UserModel::save($user);
}
2014-05-06 11:28:33 +02:00
protected function mockPost($owner)
{
$post = PostModel::spawn();
2014-05-06 11:28:33 +02:00
$post->setUploader($owner);
$post->setType(new PostType(PostType::Image));
return PostModel::save($post);
}
protected function login($user)
{
Auth::setCurrentUser($user);
}
protected function mockComment($owner)
{
2014-05-06 11:28:33 +02:00
$post = $this->mockPost($owner);
$comment = CommentModel::spawn();
$comment->setPost($post);
$comment->setCommenter($owner);
$comment->setText('test test');
return CommentModel::save($comment);
}
2014-05-06 13:07:24 +02:00
protected function grantAccess($privilege)
{
getConfig()->privileges->$privilege = 'anonymous';
Access::init();
}
protected function revokeAccess($privilege)
{
getConfig()->privileges->$privilege = 'nobody';
Access::init();
}
2014-05-04 21:23:12 +02:00
}