szurubooru/tests/JobTests/EditPostJobTest.php
Marcin Kurczewski 4ba83e6834 Changed job arguments convention back
Restored JobArgs approach. Previous introduction of hierarchic argument
definitions has backfired: it was confusing what class to take arguments
from, the concept of sharing arguments between different jobs was
unintelligible and one never knew where given argument was actually
defined.

This appraoch makes it easier to maintain the arguments list and
simplifies the code a lot.
2014-05-12 00:13:18 +02:00

60 lines
1.5 KiB
PHP

<?php
class EditPostJobTest extends AbstractTest
{
public function testSaving()
{
$this->grantAccess('editPost');
$this->grantAccess('editPostSafety');
$this->grantAccess('editPostTags');
$this->grantAccess('editPostSource');
$this->grantAccess('editPostContent');
$post = $this->mockPost(Auth::getCurrentUser());
$args =
[
JobArgs::ARG_POST_ID => $post->getId(),
JobArgs::ARG_NEW_SAFETY => PostSafety::Sketchy,
JobArgs::ARG_NEW_SOURCE => 'some source huh',
JobArgs::ARG_NEW_POST_CONTENT => new ApiFileInput($this->getPath('image.jpg'), 'test.jpg'),
];
$this->assert->doesNotThrow(function() use ($args)
{
Api::run(new EditPostJob(), $args);
});
}
public function testPrivilegeFail()
{
$this->grantAccess('editPost');
$this->grantAccess('editPostSafety');
$this->grantAccess('editPostTags');
$this->grantAccess('editPostContent');
$post = $this->mockPost(Auth::getCurrentUser());
$args =
[
JobArgs::ARG_POST_ID => $post->getId(),
JobArgs::ARG_NEW_SAFETY => PostSafety::Safe,
JobArgs::ARG_NEW_SOURCE => '',
JobArgs::ARG_NEW_POST_CONTENT => new ApiFileInput($this->getPath('image.jpg'), 'test.jpg'),
];
$this->assert->throws(function() use ($args)
{
Api::run(new EditPostJob(), $args);
}, 'Insufficient privilege');
}
public function testLogBuffering()
{
$this->testSaving();
$logPath = Logger::getLogPath();
$x = file_get_contents($logPath);
$lines = array_filter(explode("\n", $x));
$this->assert->areEqual(3, count($lines));
}
}