2014-05-12 22:39:14 +02:00
|
|
|
<?php
|
|
|
|
class EditPostRelationsJobTest extends AbstractTest
|
|
|
|
{
|
|
|
|
public function testEditing()
|
|
|
|
{
|
|
|
|
$this->grantAccess('editPostRelations');
|
|
|
|
|
2014-05-13 21:08:07 +02:00
|
|
|
list ($basePost, $post1, $post2)
|
|
|
|
= $this->postMocker->mockMultiple(3);
|
2014-05-12 22:39:14 +02:00
|
|
|
|
|
|
|
$basePost = $this->assert->doesNotThrow(function() use ($basePost, $post1, $post2)
|
|
|
|
{
|
|
|
|
return Api::run(
|
|
|
|
new EditPostRelationsJob(),
|
|
|
|
[
|
|
|
|
JobArgs::ARG_POST_ID => $basePost->getId(),
|
2014-06-10 10:40:07 +02:00
|
|
|
JobArgs::ARG_POST_REVISION => $basePost->getRevision(),
|
2014-05-12 22:39:14 +02:00
|
|
|
JobArgs::ARG_NEW_RELATED_POST_IDS =>
|
|
|
|
[
|
|
|
|
$post1->getId(),
|
|
|
|
$post2->getId(),
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
$this->assert->areEqual(2, count($basePost->getRelations()));
|
|
|
|
$this->assert->areEqual($post1->getId(), $basePost->getRelations()[0]->getId());
|
|
|
|
$this->assert->areEqual($post2->getId(), $basePost->getRelations()[1]->getId());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testOverwriting()
|
|
|
|
{
|
|
|
|
$this->grantAccess('editPostRelations');
|
|
|
|
|
2014-05-13 21:08:07 +02:00
|
|
|
list ($basePost, $post1, $post2)
|
|
|
|
= $this->postMocker->mockMultiple(3);
|
2014-05-12 22:39:14 +02:00
|
|
|
|
|
|
|
$basePost->setRelations([$post1]);
|
|
|
|
PostModel::save($basePost);
|
|
|
|
|
|
|
|
$this->assert->areEqual(1, count($basePost->getRelations()));
|
|
|
|
$this->assert->areEqual($post1->getId(), $basePost->getRelations()[0]->getId());
|
|
|
|
|
|
|
|
$basePost = $this->assert->doesNotThrow(function() use ($basePost, $post2)
|
|
|
|
{
|
|
|
|
return Api::run(
|
|
|
|
new EditPostRelationsJob(),
|
|
|
|
[
|
|
|
|
JobArgs::ARG_POST_ID => $basePost->getId(),
|
2014-06-10 10:40:07 +02:00
|
|
|
JobArgs::ARG_POST_REVISION => $basePost->getRevision(),
|
2014-05-12 22:39:14 +02:00
|
|
|
JobArgs::ARG_NEW_RELATED_POST_IDS =>
|
|
|
|
[
|
|
|
|
$post2->getId(),
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
$this->assert->areEqual(1, count($basePost->getRelations()));
|
|
|
|
$this->assert->areEqual($post2->getId(), $basePost->getRelations()[0]->getId());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testOverwritingEmpty()
|
|
|
|
{
|
|
|
|
$this->grantAccess('editPostRelations');
|
|
|
|
|
2014-05-13 21:08:07 +02:00
|
|
|
list ($basePost, $post1, $post2)
|
|
|
|
= $this->postMocker->mockMultiple(3);
|
2014-05-12 22:39:14 +02:00
|
|
|
|
|
|
|
$basePost->setRelations([$post1]);
|
|
|
|
PostModel::save($basePost);
|
|
|
|
|
|
|
|
$this->assert->areEqual(1, count($basePost->getRelations()));
|
|
|
|
$this->assert->areEqual($post1->getId(), $basePost->getRelations()[0]->getId());
|
|
|
|
|
|
|
|
$basePost = $this->assert->doesNotThrow(function() use ($basePost)
|
|
|
|
{
|
|
|
|
return Api::run(
|
|
|
|
new EditPostRelationsJob(),
|
|
|
|
[
|
|
|
|
JobArgs::ARG_POST_ID => $basePost->getId(),
|
2014-06-10 10:40:07 +02:00
|
|
|
JobArgs::ARG_POST_REVISION => $basePost->getRevision(),
|
2014-05-12 22:39:14 +02:00
|
|
|
JobArgs::ARG_NEW_RELATED_POST_IDS =>
|
|
|
|
[
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
$basePost = PostModel::getById($basePost->getId());
|
|
|
|
$this->assert->areEqual(0, count($basePost->getRelations()));
|
|
|
|
}
|
|
|
|
}
|