szurubooru/tests/JobTests/FlagPostJobTest.php

49 lines
1.1 KiB
PHP
Raw Normal View History

2014-05-13 00:02:25 +02:00
<?php
class FlagPostJobTest extends AbstractTest
{
public function testFlagging()
{
$this->grantAccess('flagPost');
$post = $this->mockPost($this->mockUser());
$post = $this->assert->doesNotThrow(function() use ($post)
{
return Api::run(
new FlagPostJob(),
[
JobArgs::ARG_POST_NAME => $post->getName(),
]);
});
$logPath = Logger::getLogPath();
$logs = file_get_contents($logPath);
$logs = explode("\n", $logs);
2014-05-13 00:02:25 +02:00
$this->assert->areEqual(1, count($logs));
$this->assert->isTrue(strpos($logs[0], 'flagged @' . $post->getId() . ' for moderator attention') !== false);
}
public function testDoubleFlagging()
{
$this->grantAccess('flagPost');
$post = $this->mockPost($this->mockUser());
$this->assert->doesNotThrow(function() use ($post)
{
Api::run(
new FlagPostJob(),
[
JobArgs::ARG_POST_NAME => $post->getName(),
]);
});
$this->assert->throws(function() use ($post)
{
return Api::run(
new FlagPostJob(),
[
JobArgs::ARG_POST_NAME => $post->getName(),
]);
}, 'You already flagged this post');
}
}