2014-05-13 00:02:25 +02:00
|
|
|
<?php
|
|
|
|
class EditPostSafetyJobTest extends AbstractTest
|
|
|
|
{
|
|
|
|
public function testSaving()
|
|
|
|
{
|
|
|
|
$this->prepare();
|
|
|
|
$this->grantAccess('editPostSafety.own');
|
|
|
|
|
2014-05-13 21:08:07 +02:00
|
|
|
$post = $this->postMocker->mockSingle();
|
2014-05-13 00:02:25 +02:00
|
|
|
$post = $this->assert->doesNotThrow(function() use ($post)
|
|
|
|
{
|
|
|
|
return Api::run(
|
|
|
|
new EditPostSafetyJob(),
|
|
|
|
[
|
|
|
|
JobArgs::ARG_POST_ID => $post->getId(),
|
|
|
|
JobArgs::ARG_NEW_SAFETY => PostSafety::Sketchy,
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
$this->assert->areEqual(PostSafety::Sketchy, $post->getSafety()->toInteger());
|
|
|
|
$this->assert->doesNotThrow(function() use ($post)
|
|
|
|
{
|
|
|
|
PostModel::getById($post->getId());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testWrongPostId()
|
|
|
|
{
|
|
|
|
$this->prepare();
|
|
|
|
|
|
|
|
$this->assert->throws(function()
|
|
|
|
{
|
|
|
|
Api::run(
|
|
|
|
new EditPostSafetyJob(),
|
|
|
|
[
|
|
|
|
JobArgs::ARG_POST_ID => 100,
|
|
|
|
JobArgs::ARG_NEW_SAFETY => PostSafety::Sketchy,
|
|
|
|
]);
|
|
|
|
}, 'Invalid post ID');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testWrongSafety()
|
|
|
|
{
|
|
|
|
$this->prepare();
|
|
|
|
$this->grantAccess('editPostSafety.own');
|
|
|
|
|
2014-05-13 21:08:07 +02:00
|
|
|
$post = $this->postMocker->mockSingle();
|
2014-05-13 00:02:25 +02:00
|
|
|
$this->assert->throws(function() use ($post)
|
|
|
|
{
|
|
|
|
Api::run(
|
|
|
|
new EditPostSafetyJob(),
|
|
|
|
[
|
|
|
|
JobArgs::ARG_POST_ID => $post->getId(),
|
|
|
|
JobArgs::ARG_NEW_SAFETY => '',
|
|
|
|
]);
|
|
|
|
}, 'Invalid safety type');
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function prepare()
|
|
|
|
{
|
2014-05-13 21:08:07 +02:00
|
|
|
$this->login($this->userMocker->mockSingle());
|
2014-05-13 00:02:25 +02:00
|
|
|
}
|
|
|
|
}
|