2014-05-06 11:28:33 +02:00
|
|
|
<?php
|
|
|
|
class EditPostSourceJobTest extends AbstractTest
|
|
|
|
{
|
|
|
|
public function testSaving()
|
|
|
|
{
|
|
|
|
$this->prepare();
|
|
|
|
$this->grantAccess('editPostSource.own');
|
|
|
|
$post = $this->assert->doesNotThrow(function()
|
|
|
|
{
|
|
|
|
return $this->runApi('a');
|
|
|
|
});
|
|
|
|
|
2014-05-07 17:52:57 +02:00
|
|
|
$this->assert->areEqual('a', $post->getSource());
|
2014-05-06 11:28:33 +02:00
|
|
|
$this->assert->doesNotThrow(function() use ($post)
|
|
|
|
{
|
2014-05-08 08:54:08 +02:00
|
|
|
PostModel::getById($post->getId());
|
2014-05-06 11:28:33 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAlmostTooLongText()
|
|
|
|
{
|
|
|
|
$this->prepare();
|
|
|
|
$this->grantAccess('editPostSource.own');
|
|
|
|
$this->assert->doesNotThrow(function()
|
|
|
|
{
|
|
|
|
$this->runApi(str_repeat('a', getConfig()->posts->maxSourceLength));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testTooLongText()
|
|
|
|
{
|
|
|
|
$this->prepare();
|
|
|
|
$this->grantAccess('editPostSource.own');
|
|
|
|
$this->assert->throws(function()
|
|
|
|
{
|
|
|
|
$this->runApi(str_repeat('a', getConfig()->posts->maxSourceLength + 1));
|
|
|
|
}, 'Source must have at most');
|
|
|
|
}
|
|
|
|
|
2014-05-13 00:02:25 +02:00
|
|
|
public function testEmptyText()
|
|
|
|
{
|
|
|
|
$this->prepare();
|
|
|
|
$this->grantAccess('editPostSource.own');
|
|
|
|
$post = $this->assert->doesNotThrow(function()
|
|
|
|
{
|
|
|
|
return $this->runApi('');
|
|
|
|
});
|
|
|
|
$this->assert->areEqual('', $post->getSource());
|
|
|
|
}
|
|
|
|
|
2014-05-06 11:28:33 +02:00
|
|
|
public function testWrongPostId()
|
|
|
|
{
|
|
|
|
$this->prepare();
|
|
|
|
$this->assert->throws(function()
|
|
|
|
{
|
|
|
|
Api::run(
|
|
|
|
new EditPostSourceJob(),
|
|
|
|
[
|
2014-05-12 00:13:18 +02:00
|
|
|
JobArgs::ARG_POST_ID => 100,
|
|
|
|
JobArgs::ARG_NEW_SOURCE => 'alohaa',
|
2014-05-06 11:28:33 +02:00
|
|
|
]);
|
|
|
|
}, 'Invalid post ID');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected function runApi($text)
|
|
|
|
{
|
2014-05-13 21:08:07 +02:00
|
|
|
$post = $this->postMocker->mockSingle();
|
2014-05-06 11:28:33 +02:00
|
|
|
return Api::run(
|
|
|
|
new EditPostSourceJob(),
|
|
|
|
[
|
2014-05-12 00:13:18 +02:00
|
|
|
JobArgs::ARG_POST_ID => $post->getId(),
|
|
|
|
JobArgs::ARG_NEW_SOURCE => $text
|
2014-05-06 11:28:33 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function prepare()
|
|
|
|
{
|
2014-05-13 21:08:07 +02:00
|
|
|
$this->login($this->userMocker->mockSingle());
|
2014-05-06 11:28:33 +02:00
|
|
|
}
|
|
|
|
}
|