2014-05-06 19:39:41 +02:00
|
|
|
<?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');
|
|
|
|
|
2014-05-13 21:08:07 +02:00
|
|
|
$this->login($this->userMocker->mockSingle());
|
2014-05-06 19:39:41 +02:00
|
|
|
|
2014-05-07 21:04:34 +02:00
|
|
|
$post = $this->assert->doesNotThrow(function()
|
2014-05-06 19:39:41 +02:00
|
|
|
{
|
2014-05-07 21:04:34 +02:00
|
|
|
return Api::run(
|
|
|
|
new AddPostJob(),
|
|
|
|
[
|
2014-05-15 23:34:22 +02:00
|
|
|
JobArgs::ARG_ANONYMOUS => '0',
|
2014-05-12 00:13:18 +02:00
|
|
|
JobArgs::ARG_NEW_SAFETY => PostSafety::Safe,
|
|
|
|
JobArgs::ARG_NEW_SOURCE => '',
|
|
|
|
JobArgs::ARG_NEW_TAG_NAMES => ['kamen', 'raider'],
|
2014-05-13 21:08:07 +02:00
|
|
|
JobArgs::ARG_NEW_POST_CONTENT =>
|
|
|
|
new ApiFileInput($this->testSupport->getPath('image.jpg'), 'test.jpg'),
|
2014-05-07 21:04:34 +02:00
|
|
|
]);
|
2014-05-06 19:39:41 +02:00
|
|
|
});
|
2014-05-07 21:04:34 +02:00
|
|
|
|
|
|
|
$this->assert->areEqual(
|
|
|
|
file_get_contents($post->getFullPath()),
|
2014-05-13 21:08:07 +02:00
|
|
|
file_get_contents($this->testSupport->getPath('image.jpg')));
|
2014-05-07 21:04:34 +02:00
|
|
|
$this->assert->areEqual(Auth::getCurrentUser()->getId(), $post->getUploaderId());
|
2014-05-15 23:34:22 +02:00
|
|
|
$this->assert->isNotNull($post->getUploaderId());
|
2014-05-07 21:04:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testAnonymousUploads()
|
|
|
|
{
|
|
|
|
$this->prepare();
|
|
|
|
|
|
|
|
$this->grantAccess('addPost');
|
|
|
|
$this->grantAccess('addPostTags');
|
|
|
|
$this->grantAccess('addPostContent');
|
|
|
|
|
2014-05-13 21:08:07 +02:00
|
|
|
$this->login($this->userMocker->mockSingle());
|
2014-05-07 21:04:34 +02:00
|
|
|
|
|
|
|
$post = $this->assert->doesNotThrow(function()
|
|
|
|
{
|
|
|
|
return Api::run(
|
|
|
|
new AddPostJob(),
|
|
|
|
[
|
2014-05-15 23:34:22 +02:00
|
|
|
JobArgs::ARG_ANONYMOUS => '1',
|
2014-05-12 00:13:18 +02:00
|
|
|
JobArgs::ARG_NEW_TAG_NAMES => ['kamen', 'raider'],
|
2014-05-13 21:08:07 +02:00
|
|
|
JobArgs::ARG_NEW_POST_CONTENT =>
|
|
|
|
new ApiFileInput($this->testSupport->getPath('image.jpg'), 'test.jpg'),
|
2014-05-07 21:04:34 +02:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
$this->assert->areEqual(
|
|
|
|
file_get_contents($post->getFullPath()),
|
2014-05-13 21:08:07 +02:00
|
|
|
file_get_contents($this->testSupport->getPath('image.jpg')));
|
2014-05-07 21:04:34 +02:00
|
|
|
$this->assert->areNotEqual(Auth::getCurrentUser()->getId(), $post->getUploaderId());
|
2014-05-14 18:07:31 +02:00
|
|
|
$this->assert->isNull($post->getUploaderId());
|
2014-05-06 19:39:41 +02:00
|
|
|
}
|
|
|
|
|
2014-05-07 21:39:41 +02:00
|
|
|
public function testPartialPrivilegeFail()
|
2014-05-06 19:39:41 +02:00
|
|
|
{
|
|
|
|
$this->prepare();
|
|
|
|
|
|
|
|
$this->grantAccess('addPost');
|
|
|
|
$this->grantAccess('addPostSafety');
|
|
|
|
$this->grantAccess('addPostTags');
|
|
|
|
$this->grantAccess('addPostContent');
|
|
|
|
|
2014-05-07 21:39:41 +02:00
|
|
|
$this->assert->throws(function()
|
2014-05-06 19:39:41 +02:00
|
|
|
{
|
2014-05-07 21:39:41 +02:00
|
|
|
Api::run(
|
|
|
|
new AddPostJob(),
|
|
|
|
[
|
2014-05-12 00:13:18 +02:00
|
|
|
JobArgs::ARG_NEW_SAFETY => PostSafety::Safe,
|
2014-05-13 00:02:25 +02:00
|
|
|
JobArgs::ARG_NEW_SOURCE => 'this should make it fail',
|
2014-05-13 21:08:07 +02:00
|
|
|
JobArgs::ARG_NEW_POST_CONTENT =>
|
|
|
|
new ApiFileInput($this->testSupport->getPath('image.jpg'), 'test.jpg'),
|
2014-05-07 21:39:41 +02:00
|
|
|
]);
|
2014-05-06 19:39:41 +02:00
|
|
|
}, 'Insufficient privilege');
|
|
|
|
}
|
|
|
|
|
2014-05-07 21:39:41 +02:00
|
|
|
public function testInvalidSafety()
|
|
|
|
{
|
|
|
|
$this->prepare();
|
|
|
|
|
|
|
|
$this->grantAccess('addPost');
|
|
|
|
$this->grantAccess('addPostTags');
|
|
|
|
$this->grantAccess('addPostContent');
|
|
|
|
$this->grantAccess('addPostSafety');
|
|
|
|
|
|
|
|
$this->assert->throws(function()
|
|
|
|
{
|
|
|
|
Api::run(
|
|
|
|
new AddPostJob(),
|
|
|
|
[
|
2014-05-12 00:13:18 +02:00
|
|
|
JobArgs::ARG_NEW_SAFETY => 666,
|
|
|
|
JobArgs::ARG_NEW_TAG_NAMES => ['kamen', 'raider'],
|
2014-05-13 21:08:07 +02:00
|
|
|
JobArgs::ARG_NEW_POST_CONTENT =>
|
|
|
|
new ApiFileInput($this->testSupport->getPath('image.jpg'), 'test.jpg'),
|
2014-05-07 21:39:41 +02:00
|
|
|
]);
|
|
|
|
}, 'Invalid safety type');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testNoContentFail()
|
|
|
|
{
|
|
|
|
$this->prepare();
|
|
|
|
|
|
|
|
$this->grantAccess('addPost');
|
|
|
|
$this->grantAccess('addPostTags');
|
|
|
|
$this->grantAccess('addPostContent');
|
|
|
|
|
|
|
|
$this->assert->throws(function()
|
|
|
|
{
|
|
|
|
Api::run(
|
|
|
|
new AddPostJob(),
|
|
|
|
[
|
2014-05-12 00:13:18 +02:00
|
|
|
JobArgs::ARG_TAG_NAMES => ['kamen', 'raider'],
|
2014-05-07 21:39:41 +02:00
|
|
|
]);
|
|
|
|
}, 'No post type detected');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testEmptyTagsFail()
|
|
|
|
{
|
|
|
|
$this->prepare();
|
|
|
|
|
|
|
|
$this->grantAccess('addPost');
|
|
|
|
$this->grantAccess('addPostTags');
|
|
|
|
$this->grantAccess('addPostContent');
|
|
|
|
|
|
|
|
$this->assert->throws(function()
|
|
|
|
{
|
|
|
|
Api::run(
|
|
|
|
new AddPostJob(),
|
|
|
|
[
|
2014-05-13 21:08:07 +02:00
|
|
|
JobArgs::ARG_NEW_POST_CONTENT =>
|
|
|
|
new ApiFileInput($this->testSupport->getPath('image.jpg'), 'test.jpg'),
|
2014-05-07 21:39:41 +02:00
|
|
|
]);
|
|
|
|
}, 'No tags set');
|
|
|
|
}
|
|
|
|
|
2014-05-07 01:14:52 +02:00
|
|
|
public function testLogBuffering()
|
|
|
|
{
|
|
|
|
$this->testSaving();
|
|
|
|
|
|
|
|
$logPath = Logger::getLogPath();
|
|
|
|
$x = file_get_contents($logPath);
|
2014-05-13 14:03:27 +02:00
|
|
|
$lines = explode("\n", $x);
|
2014-05-07 01:14:52 +02:00
|
|
|
$this->assert->areEqual(1, count($lines));
|
|
|
|
}
|
|
|
|
|
2014-05-06 19:39:41 +02:00
|
|
|
protected function prepare()
|
|
|
|
{
|
2014-05-15 10:32:53 +02:00
|
|
|
Core::getConfig()->registration->needEmailForUploading = false;
|
2014-05-06 19:39:41 +02:00
|
|
|
}
|
|
|
|
}
|