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');
|
|
|
|
|
|
|
|
$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');
|
|
|
|
}
|
|
|
|
|
2014-05-07 01:14:52 +02:00
|
|
|
public function testLogBuffering()
|
|
|
|
{
|
|
|
|
$this->testSaving();
|
|
|
|
|
|
|
|
$logPath = Logger::getLogPath();
|
|
|
|
$x = file_get_contents($logPath);
|
|
|
|
$lines = array_filter(explode("\n", $x));
|
|
|
|
$this->assert->areEqual(1, count($lines));
|
|
|
|
}
|
|
|
|
|
2014-05-06 19:39:41 +02:00
|
|
|
protected function prepare()
|
|
|
|
{
|
|
|
|
getConfig()->registration->needEmailForUploading = false;
|
|
|
|
}
|
|
|
|
}
|