2014-05-04 21:23:12 +02:00
|
|
|
<?php
|
|
|
|
class AbstractTest
|
|
|
|
{
|
|
|
|
public $assert;
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->assert = new Assert();
|
|
|
|
}
|
2014-05-05 11:08:03 +02:00
|
|
|
|
2014-05-06 18:09:23 +02:00
|
|
|
public function setup()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public function teardown()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-05-05 11:08:03 +02:00
|
|
|
protected function mockUser()
|
|
|
|
{
|
|
|
|
$user = UserModel::spawn();
|
|
|
|
$user->setAccessRank(new AccessRank(AccessRank::Registered));
|
2014-05-07 00:34:02 +02:00
|
|
|
$user->setName('dummy'.uniqid());
|
|
|
|
$user->setPassword('sekai');
|
2014-05-05 11:08:03 +02:00
|
|
|
return UserModel::save($user);
|
|
|
|
}
|
|
|
|
|
2014-05-07 21:39:41 +02:00
|
|
|
protected function mockTag()
|
|
|
|
{
|
|
|
|
$tag = TagModel::spawn();
|
|
|
|
$tag->setName(uniqid());
|
|
|
|
return TagModel::save($tag);
|
|
|
|
}
|
|
|
|
|
2014-05-06 11:28:33 +02:00
|
|
|
protected function mockPost($owner)
|
2014-05-05 11:08:03 +02:00
|
|
|
{
|
|
|
|
$post = PostModel::spawn();
|
2014-05-06 11:28:33 +02:00
|
|
|
$post->setUploader($owner);
|
2014-05-05 11:08:03 +02:00
|
|
|
$post->setType(new PostType(PostType::Image));
|
2014-05-07 21:39:41 +02:00
|
|
|
$post->setTags([$this->mockTag(), $this->mockTag()]);
|
2014-05-13 14:08:00 +02:00
|
|
|
copy($this->getPath('image.jpg'), $post->getFullPath());
|
2014-05-05 11:08:03 +02:00
|
|
|
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);
|
2014-05-05 11:08:03 +02:00
|
|
|
$comment = CommentModel::spawn();
|
|
|
|
$comment->setPost($post);
|
|
|
|
$comment->setCommenter($owner);
|
2014-05-06 00:54:15 +02:00
|
|
|
$comment->setText('test test');
|
2014-05-05 11:08:03 +02:00
|
|
|
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-06 19:39:41 +02:00
|
|
|
|
|
|
|
protected function getPath($name)
|
|
|
|
{
|
|
|
|
return getConfig()->rootDir . DS . 'tests' . DS . 'TestFiles' . DS . $name;
|
|
|
|
}
|
2014-05-04 21:23:12 +02:00
|
|
|
}
|