szurubooru/tests/JobTests/AddPostJobTest.php

56 lines
1.3 KiB
PHP
Raw Normal View History

<?php
class AddPostJobTest extends AbstractTest
{
public function testSaving()
{
$this->prepare();
$this->grantAccess('addPost');
$this->grantAccess('addPostSafety');
$this->grantAccess('addPostTags');
$this->grantAccess('addPostSource');
$this->grantAccess('addPostContent');
$args =
[
AddPostJob::ANONYMOUS => false,
EditPostSafetyJob::SAFETY => PostSafety::Safe,
EditPostSourceJob::SOURCE => '',
EditPostContentJob::POST_CONTENT => new ApiFileInput($this->getPath('image.jpg'), 'test.jpg'),
];
$this->assert->doesNotThrow(function() use ($args)
{
Api::run(new AddPostJob(), $args);
});
}
public function testPrivilegeFail()
{
$this->prepare();
$this->grantAccess('addPost');
$this->grantAccess('addPostSafety');
$this->grantAccess('addPostTags');
$this->grantAccess('addPostContent');
$args =
[
AddPostJob::ANONYMOUS => false,
EditPostSafetyJob::SAFETY => PostSafety::Safe,
EditPostSourceJob::SOURCE => '',
EditPostContentJob::POST_CONTENT => new ApiFileInput($this->getPath('image.jpg'), 'test.jpg'),
];
$this->assert->throws(function() use ($args)
{
Api::run(new AddPostJob(), $args);
}, 'Insufficient privilege');
}
protected function prepare()
{
getConfig()->registration->needEmailForUploading = false;
}
}