Made anonymous upload parameter optional
This commit is contained in:
parent
20ee47e596
commit
acf8cf28e8
2 changed files with 43 additions and 11 deletions
|
@ -7,7 +7,8 @@ class AddPostJob extends AbstractJob
|
|||
{
|
||||
$post = PostModel::spawn();
|
||||
|
||||
$anonymous = $this->getArgument(self::ANONYMOUS);
|
||||
$anonymous = $this->hasArgument(self::ANONYMOUS)
|
||||
and $this->getArgument(self::ANONYMOUS);
|
||||
if (Auth::isLoggedIn() and !$anonymous)
|
||||
$post->setUploader(Auth::getCurrentUser());
|
||||
|
||||
|
|
|
@ -11,18 +11,50 @@ class AddPostJobTest extends AbstractTest
|
|||
$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->login($this->mockUser());
|
||||
|
||||
$this->assert->doesNotThrow(function() use ($args)
|
||||
$post = $this->assert->doesNotThrow(function()
|
||||
{
|
||||
Api::run(new AddPostJob(), $args);
|
||||
return Api::run(
|
||||
new AddPostJob(),
|
||||
[
|
||||
EditPostSafetyJob::SAFETY => PostSafety::Safe,
|
||||
EditPostSourceJob::SOURCE => '',
|
||||
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->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()
|
||||
|
@ -36,7 +68,6 @@ class AddPostJobTest extends AbstractTest
|
|||
|
||||
$args =
|
||||
[
|
||||
AddPostJob::ANONYMOUS => false,
|
||||
EditPostSafetyJob::SAFETY => PostSafety::Safe,
|
||||
EditPostSourceJob::SOURCE => '',
|
||||
EditPostContentJob::POST_CONTENT => new ApiFileInput($this->getPath('image.jpg'), 'test.jpg'),
|
||||
|
|
Loading…
Reference in a new issue