2014-05-06 19:39:41 +02:00
|
|
|
<?php
|
|
|
|
class EditPostJobTest extends AbstractTest
|
|
|
|
{
|
|
|
|
public function testSaving()
|
|
|
|
{
|
|
|
|
$this->grantAccess('editPost');
|
|
|
|
$this->grantAccess('editPostSafety');
|
|
|
|
$this->grantAccess('editPostTags');
|
|
|
|
$this->grantAccess('editPostSource');
|
|
|
|
$this->grantAccess('editPostContent');
|
|
|
|
|
2014-05-13 21:08:07 +02:00
|
|
|
$post = $this->postMocker->mockSingle();
|
2014-06-01 14:07:53 +02:00
|
|
|
$this->assert->areEqual(1, $post->getRevision());
|
2014-05-06 19:39:41 +02:00
|
|
|
|
|
|
|
$args =
|
|
|
|
[
|
2014-05-12 00:13:18 +02:00
|
|
|
JobArgs::ARG_POST_ID => $post->getId(),
|
2014-06-10 10:40:07 +02:00
|
|
|
JobArgs::ARG_POST_REVISION => $post->getRevision(),
|
2014-05-12 00:13:18 +02:00
|
|
|
JobArgs::ARG_NEW_SAFETY => PostSafety::Sketchy,
|
|
|
|
JobArgs::ARG_NEW_SOURCE => 'some source huh',
|
2014-05-13 21:08:07 +02:00
|
|
|
JobArgs::ARG_NEW_POST_CONTENT =>
|
|
|
|
new ApiFileInput($this->testSupport->getPath('image.jpg'), 'test.jpg'),
|
2014-05-06 19:39:41 +02:00
|
|
|
];
|
|
|
|
|
2014-06-01 14:07:53 +02:00
|
|
|
$post = $this->assert->doesNotThrow(function() use ($args)
|
2014-05-06 19:39:41 +02:00
|
|
|
{
|
2014-06-01 14:07:53 +02:00
|
|
|
return Api::run(new EditPostJob(), $args);
|
2014-05-06 19:39:41 +02:00
|
|
|
});
|
2014-06-01 14:07:53 +02:00
|
|
|
|
|
|
|
$this->assert->areEqual(2, $post->getRevision());
|
2014-05-06 19:39:41 +02:00
|
|
|
}
|
|
|
|
|
2014-05-13 00:02:25 +02:00
|
|
|
public function testPartialPrivilegeFail()
|
2014-05-06 19:39:41 +02:00
|
|
|
{
|
|
|
|
$this->grantAccess('editPost');
|
|
|
|
$this->grantAccess('editPostSafety');
|
|
|
|
$this->grantAccess('editPostTags');
|
|
|
|
$this->grantAccess('editPostContent');
|
|
|
|
|
2014-05-13 21:08:07 +02:00
|
|
|
$post = $this->postMocker->mockSingle();
|
2014-05-06 19:39:41 +02:00
|
|
|
|
|
|
|
$args =
|
|
|
|
[
|
2014-05-12 00:13:18 +02:00
|
|
|
JobArgs::ARG_POST_ID => $post->getId(),
|
2014-06-10 10:40:07 +02:00
|
|
|
JobArgs::ARG_POST_REVISION => $post->getRevision(),
|
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-06 19:39:41 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
$this->assert->throws(function() use ($args)
|
|
|
|
{
|
|
|
|
Api::run(new EditPostJob(), $args);
|
|
|
|
}, 'Insufficient privilege');
|
|
|
|
}
|
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(3, count($lines));
|
|
|
|
}
|
2014-05-06 19:39:41 +02:00
|
|
|
}
|