From d9c0673445b75f67b72f840102b242d85f5bd9f0 Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Wed, 3 Apr 2019 18:38:53 +0300 Subject: [PATCH] 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. --- .../DataFixtures/ORM/LoadPostData.php | 41 +++++++++++++++---- .../DataFixtures/ORM/LoadUserData.php | 26 ++++++------ 2 files changed, 46 insertions(+), 21 deletions(-) diff --git a/src/Skobkin/Bundle/PointToolsBundle/DataFixtures/ORM/LoadPostData.php b/src/Skobkin/Bundle/PointToolsBundle/DataFixtures/ORM/LoadPostData.php index 4313e9b..55b624c 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/DataFixtures/ORM/LoadPostData.php +++ b/src/Skobkin/Bundle/PointToolsBundle/DataFixtures/ORM/LoadPostData.php @@ -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); diff --git a/src/Skobkin/Bundle/PointToolsBundle/DataFixtures/ORM/LoadUserData.php b/src/Skobkin/Bundle/PointToolsBundle/DataFixtures/ORM/LoadUserData.php index db6a431..3be48e4 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/DataFixtures/ORM/LoadUserData.php +++ b/src/Skobkin/Bundle/PointToolsBundle/DataFixtures/ORM/LoadUserData.php @@ -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);