Fixing user and post data fixtures to fix PostControllerTest::testShortPostPageIsOk() according to previous privacy fix. New post for more advanced privacy test-cases added. Test must be written though.

This commit is contained in:
Alexey Skobkin 2019-04-03 18:38:53 +03:00
parent 0c004085fd
commit d9c0673445
2 changed files with 46 additions and 21 deletions

View file

@ -2,33 +2,58 @@
namespace Skobkin\Bundle\PointToolsBundle\DataFixtures\ORM;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\DataFixtures\{AbstractFixture, OrderedFixtureInterface};
use Doctrine\Common\Persistence\ObjectManager;
use Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Post;
use Skobkin\Bundle\PointToolsBundle\Entity\User;
use Skobkin\Bundle\PointToolsBundle\Entity\{Blogs\Post, User};
class LoadPostData extends AbstractFixture implements OrderedFixtureInterface
{
public function load(ObjectManager $om)
{
/** @var User $testUser */
$testUser = $this->getReference('test_user_99999');
/** @var User $mainUser */
$mainUser = $this->getReference('test_user_'.LoadUserData::USER_MAIN_ID);
/** @var User $privateUser */
$privateUser = $this->getReference('test_user_'.LoadUserData::USER_PRIV_ID);
/** @var User $wlUser */
$wlUser = $this->getReference('test_user_'.LoadUserData::USER_WLON_ID);
/** @var User $prWlUser */
$prWlUser = $this->getReference('test_user_'.LoadUserData::USER_PRWL_ID);
$longPost = (new Post('longpost', $testUser, new \DateTime(), Post::TYPE_POST))
$longPost = (new Post('longpost', $mainUser, new \DateTime(), Post::TYPE_POST))
->setText('Test post with many comments')
->setPrivate(false)
->setDeleted(false)
;
$shortPost = (new Post('shortpost', $testUser, new \DateTime(), Post::TYPE_POST))
$shortPost = (new Post('shortpost', $mainUser, new \DateTime(), Post::TYPE_POST))
->setText('Test short post')
->setPrivate(false)
->setDeleted(false)
;
$privateUserPost = (new Post('prusrpst', $privateUser, new \DateTime(), Post::TYPE_POST))
->setText('Post from private user. Should not be visible in the public feed.')
->setPrivate(false)
->setDeleted(false)
;
$wlUserPost = (new Post('wlusrpst', $wlUser, new \DateTime(), Post::TYPE_POST))
->setText('Post from whitelist-only user. Should only be visible for whitelisted users.')
->setPrivate(false)
->setDeleted(false)
;
$privateWlUserPost = (new Post('prwlusrpst', $prWlUser, new \DateTime(), Post::TYPE_POST))
->setText('Post from private AND whitelist-only user. Should not be visible in the public feed.')
->setPrivate(false)
->setDeleted(false)
;
$om->persist($longPost);
$om->persist($shortPost);
$om->persist($privateUserPost);
$om->persist($wlUserPost);
$om->persist($privateWlUserPost);
$om->flush();
$this->addReference('test_post_longpost', $longPost);

View file

@ -9,25 +9,25 @@ use Skobkin\Bundle\PointToolsBundle\Entity\User;
class LoadUserData extends AbstractFixture implements OrderedFixtureInterface
{
public const USER_MAIN_ID = 99999;
public const USER_PRIV_ID = 99998;
public const USER_WLON_ID = 99997;
public const USER_PRWL_ID = 99996;
public const USER_UNNM_ID = 99995;
private $users = [
// 99999
['login' => 'testuser', 'name' => 'Test User 1'],
// 99998
['login' => 'testuser2', 'name' => 'Test User 2'],
// 99997
['login' => 'testuser3', 'name' => 'Test User 3'],
// 99996
['login' => 'testuser4', 'name' => 'Test User 4'],
//99995
['login' => 'testuser5', 'name' => null],
['id' => self::USER_MAIN_ID, 'login' => 'testuser', 'name' => 'Test User 1', 'private' => false, 'whitelist-only' => false],
['id' => self::USER_PRIV_ID, 'login' => 'private_user', 'name' => 'Test User 3', 'private' => true, 'whitelist-only' => false],
['id' => self::USER_WLON_ID, 'login' => 'whitelist_only_user', 'name' => 'Test User 4', 'private' => false, 'whitelist-only' => true],
['id' => self::USER_PRWL_ID, 'login' => 'private_whitelist_only_user', 'name' => 'Test User 4', 'private' => false, 'whitelist-only' => true],
['id' => self::USER_UNNM_ID, 'login' => 'unnamed_user', 'name' => null, 'private' => false, 'whitelist-only' => false],
];
public function load(ObjectManager $om)
{
$userId = 99999;
foreach ($this->users as $userData) {
$user = new User($userId--, new \DateTime(), $userData['login'], $userData['name']);
$user = new User($userData['id'], new \DateTime(), $userData['login'], $userData['name']);
$user->updatePrivacy(!$userData['private'], $userData['whitelist-only']);
$om->persist($user);