Made anonymous upload parameter optional

This commit is contained in:
Marcin Kurczewski 2014-05-07 21:04:34 +02:00
parent 20ee47e596
commit acf8cf28e8
2 changed files with 43 additions and 11 deletions

View file

@ -7,7 +7,8 @@ class AddPostJob extends AbstractJob
{ {
$post = PostModel::spawn(); $post = PostModel::spawn();
$anonymous = $this->getArgument(self::ANONYMOUS); $anonymous = $this->hasArgument(self::ANONYMOUS)
and $this->getArgument(self::ANONYMOUS);
if (Auth::isLoggedIn() and !$anonymous) if (Auth::isLoggedIn() and !$anonymous)
$post->setUploader(Auth::getCurrentUser()); $post->setUploader(Auth::getCurrentUser());

View file

@ -11,18 +11,50 @@ class AddPostJobTest extends AbstractTest
$this->grantAccess('addPostSource'); $this->grantAccess('addPostSource');
$this->grantAccess('addPostContent'); $this->grantAccess('addPostContent');
$args = $this->login($this->mockUser());
$post = $this->assert->doesNotThrow(function()
{
return Api::run(
new AddPostJob(),
[ [
AddPostJob::ANONYMOUS => false,
EditPostSafetyJob::SAFETY => PostSafety::Safe, EditPostSafetyJob::SAFETY => PostSafety::Safe,
EditPostSourceJob::SOURCE => '', EditPostSourceJob::SOURCE => '',
EditPostContentJob::POST_CONTENT => new ApiFileInput($this->getPath('image.jpg'), 'test.jpg'), EditPostContentJob::POST_CONTENT => new ApiFileInput($this->getPath('image.jpg'), 'test.jpg'),
]; ]);
$this->assert->doesNotThrow(function() use ($args)
{
Api::run(new AddPostJob(), $args);
}); });
$this->assert->areEqual(
file_get_contents($post->getFullPath()),
file_get_contents($this->getPath('image.jpg')));
$this->assert->areEqual(Auth::getCurrentUser()->getId(), $post->getUploaderId());
}
public function testAnonymousUploads()
{
$this->prepare();
$this->grantAccess('addPost');
$this->grantAccess('addPostTags');
$this->grantAccess('addPostContent');
$this->login($this->mockUser());
$post = $this->assert->doesNotThrow(function()
{
return Api::run(
new AddPostJob(),
[
AddPostJob::ANONYMOUS => true,
EditPostContentJob::POST_CONTENT => new ApiFileInput($this->getPath('image.jpg'), 'test.jpg'),
]);
});
$this->assert->areEqual(
file_get_contents($post->getFullPath()),
file_get_contents($this->getPath('image.jpg')));
$this->assert->areNotEqual(Auth::getCurrentUser()->getId(), $post->getUploaderId());
$this->assert->areEqual(null, $post->getUploaderId());
} }
public function testPrivilegeFail() public function testPrivilegeFail()
@ -36,7 +68,6 @@ class AddPostJobTest extends AbstractTest
$args = $args =
[ [
AddPostJob::ANONYMOUS => false,
EditPostSafetyJob::SAFETY => PostSafety::Safe, EditPostSafetyJob::SAFETY => PostSafety::Safe,
EditPostSourceJob::SOURCE => '', EditPostSourceJob::SOURCE => '',
EditPostContentJob::POST_CONTENT => new ApiFileInput($this->getPath('image.jpg'), 'test.jpg'), EditPostContentJob::POST_CONTENT => new ApiFileInput($this->getPath('image.jpg'), 'test.jpg'),