2014-05-09 21:08:13 +02:00
|
|
|
<?php
|
|
|
|
class TogglePostFavoriteJobTest extends AbstractTest
|
|
|
|
{
|
|
|
|
public function testFaving()
|
|
|
|
{
|
|
|
|
$this->grantAccess('favoritePost');
|
2014-05-13 21:08:07 +02:00
|
|
|
$post = $this->postMocker->mockSingle();
|
|
|
|
$user = $this->userMocker->mockSingle();
|
2014-05-09 21:08:13 +02:00
|
|
|
$this->login($user);
|
|
|
|
|
|
|
|
$this->assert->areEqual(0, $post->getScore());
|
|
|
|
$this->assert->areEqual(0, $post->getFavoriteCount());
|
|
|
|
|
|
|
|
$post = $this->assert->doesNotThrow(function() use ($post)
|
|
|
|
{
|
|
|
|
return Api::run(
|
|
|
|
new TogglePostFavoriteJob(),
|
|
|
|
[
|
2014-05-12 00:13:18 +02:00
|
|
|
JobArgs::ARG_POST_ID => $post->getId(),
|
|
|
|
JobArgs::ARG_NEW_STATE => 1,
|
2014-05-09 21:08:13 +02:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
$this->assert->areEqual(1, $post->getScore());
|
|
|
|
$this->assert->areEqual(1, $post->getFavoriteCount());
|
|
|
|
$this->assert->areEqual(1, $user->getFavoriteCount());
|
|
|
|
$this->assert->areEqual(1, $user->getScore($post));
|
|
|
|
$this->assert->areEqual(true, $user->hasFavorited($post));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDefaving()
|
|
|
|
{
|
|
|
|
$this->grantAccess('favoritePost');
|
2014-05-13 21:08:07 +02:00
|
|
|
$post = $this->postMocker->mockSingle();
|
|
|
|
$user = $this->userMocker->mockSingle();
|
2014-05-09 21:08:13 +02:00
|
|
|
$this->login($user);
|
|
|
|
|
|
|
|
$this->assert->areEqual(0, $post->getScore());
|
|
|
|
$this->assert->areEqual(0, $post->getFavoriteCount());
|
|
|
|
|
|
|
|
$post = $this->assert->doesNotThrow(function() use ($post)
|
|
|
|
{
|
|
|
|
return Api::run(
|
|
|
|
new TogglePostFavoriteJob(),
|
|
|
|
[
|
2014-05-12 00:13:18 +02:00
|
|
|
JobArgs::ARG_POST_ID => $post->getId(),
|
|
|
|
JobArgs::ARG_NEW_STATE => 1,
|
2014-05-09 21:08:13 +02:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
$post = $this->assert->doesNotThrow(function() use ($post)
|
|
|
|
{
|
|
|
|
return Api::run(
|
|
|
|
new TogglePostFavoriteJob(),
|
|
|
|
[
|
2014-05-12 00:13:18 +02:00
|
|
|
JobArgs::ARG_POST_ID => $post->getId(),
|
|
|
|
JobArgs::ARG_NEW_STATE => 0,
|
2014-05-09 21:08:13 +02:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
$this->assert->areEqual(1, $post->getScore());
|
|
|
|
$this->assert->areEqual(0, $post->getFavoriteCount());
|
|
|
|
$this->assert->areEqual(0, $user->getFavoriteCount());
|
|
|
|
$this->assert->areEqual(1, $user->getScore($post));
|
|
|
|
$this->assert->areEqual(false, $user->hasFavorited($post));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testFavingTwoPeople()
|
|
|
|
{
|
|
|
|
$this->grantAccess('favoritePost');
|
2014-05-13 21:08:07 +02:00
|
|
|
$users = $this->userMocker->mockMultiple(2);
|
|
|
|
$post = $this->postMocker->mockSingle();
|
2014-05-09 21:08:13 +02:00
|
|
|
|
|
|
|
$this->assert->areEqual(0, $post->getScore());
|
|
|
|
$this->assert->areEqual(0, $post->getFavoriteCount());
|
|
|
|
|
2014-05-13 21:08:07 +02:00
|
|
|
$this->login($users[0]);
|
2014-05-09 21:08:13 +02:00
|
|
|
$post = $this->assert->doesNotThrow(function() use ($post)
|
|
|
|
{
|
|
|
|
return Api::run(
|
|
|
|
new TogglePostFavoriteJob(),
|
|
|
|
[
|
2014-05-12 00:13:18 +02:00
|
|
|
JobArgs::ARG_POST_ID => $post->getId(),
|
|
|
|
JobArgs::ARG_NEW_STATE => 1,
|
2014-05-09 21:08:13 +02:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
2014-05-13 21:08:07 +02:00
|
|
|
$this->login($users[1]);
|
2014-05-09 21:08:13 +02:00
|
|
|
$post = $this->assert->doesNotThrow(function() use ($post)
|
|
|
|
{
|
|
|
|
return Api::run(
|
|
|
|
new TogglePostFavoriteJob(),
|
|
|
|
[
|
2014-05-12 00:13:18 +02:00
|
|
|
JobArgs::ARG_POST_ID => $post->getId(),
|
|
|
|
JobArgs::ARG_NEW_STATE => 1,
|
2014-05-09 21:08:13 +02:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
$this->assert->areEqual(2, $post->getScore());
|
|
|
|
$this->assert->areEqual(2, $post->getFavoriteCount());
|
2014-05-13 21:08:07 +02:00
|
|
|
$this->assert->areEqual(1, $users[0]->getFavoriteCount());
|
|
|
|
$this->assert->areEqual(1, $users[0]->getScore($post));
|
|
|
|
$this->assert->areEqual(1, $users[1]->getFavoriteCount());
|
|
|
|
$this->assert->areEqual(1, $users[1]->getScore($post));
|
|
|
|
$this->assert->areEqual(true, $users[0]->hasFavorited($post));
|
|
|
|
$this->assert->areEqual(true, $users[1]->hasFavorited($post));
|
2014-05-09 21:08:13 +02:00
|
|
|
}
|
|
|
|
}
|