Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.81 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Tests\Functional\Controller\AccessFixtures;
  4.  
  5. use App\ApplicationAccess\UserAccesses;
  6. use App\ApplicationAccess\UserApplicationAccesses;
  7. use App\DataFixtures\OrderentityFixtures;
  8. use App\DataFixtures\PortalprofileFixtures;
  9. use App\DataFixtures\UserFixtures;
  10. use App\Entity\AccessApplicationprofile;
  11. use App\Entity\AccessOrderentity;
  12. use App\Entity\Application;
  13. use App\Entity\Applicationprofile;
  14. use App\Entity\Orderentity;
  15. use App\Entity\OrderentityUser;
  16. use App\Entity\User;
  17. use Doctrine\Bundle\FixturesBundle\Fixture;
  18. use Doctrine\Common\DataFixtures\DependentFixtureInterface;
  19. use Doctrine\Common\DataFixtures\FixtureInterface;
  20. use Doctrine\Persistence\ObjectManager;
  21.  
  22.  
  23. /*
  24.  
  25.  
  26.  */
  27.  
  28. class AccessFixtures extends Fixture implements FixtureInterface, DependentFixtureInterface
  29. {
  30.     /**
  31.      * @var ObjectManager
  32.      */
  33.     private $om;
  34.  
  35.     // CONNECTOR NAME
  36.     CONST BLUEBEAN_CONNECTOR_NAME = 'bluebean';
  37.     CONST APPTEST_CONNECTOR_NAME = 'apptest';
  38.  
  39.     //APPLICATION NAME
  40.  
  41.     CONST APP_TEST_WITH_ACCESS = 'app1';
  42.     CONST APP_TEST_WITH_ACCESS_OVERRIDEN = 'app2';
  43.     CONST APP_TEST_WITH_NO_ACCESS = 'app3';
  44.     CONST APP_TEST_WITH_NO_ACCESS_OVERRIDEN = 'app4';
  45.     CONST APP_BLUEBEAN_WITH_ACCESS = 'app5';
  46.     CONST APP_BLUEBEAN_WITH_ACCESS_OVERRIDEN = 'app6';
  47.     CONST APP_BLUEBEAN_WITH_NO_ACCESS = 'app7';
  48.     CONST APP_BLUEBEAN_WITH_NO_ACCESS_OVERRIDEN = 'app8';
  49.  
  50.  
  51.     /**
  52.      * @inheritDoc
  53.      */
  54.     public function load(ObjectManager $om)
  55.     {
  56.         $this->om = $om;
  57.         $franchisee = $this->getReference('franchisee-1');
  58.         $oe1 = $this->getReference('entiteCmd1');
  59.         $oe2 = $this->getReference('entiteCmd2');
  60.  
  61.         $oeUser1 = new OrderentityUser();
  62.         $oeUser1->setOrderentity($oe1);
  63.         $oeUser1->setUser($franchisee);
  64.         $oeUser1->setTag(OrderentityUser::MANAGER);
  65.  
  66.         $oeUser2 = new OrderentityUser();
  67.         $oeUser2->setOrderentity($oe2);
  68.         $oeUser2->setUser($franchisee);
  69.         $oeUser2->setTag(OrderentityUser::MANAGER);
  70.  
  71.         $om->persist($oeUser1);
  72.         $om->persist($oeUser2);
  73.  
  74.         //CASE 1 : une app sans connecteur bluebean où le mec a l'accès par défaut
  75.  
  76.         $app1 = $this->createApp(self::APP_TEST_WITH_ACCESS, self::APPTEST_CONNECTOR_NAME);
  77.  
  78.         $applicationProfile = new Applicationprofile();
  79.         $applicationProfile->setName('appprofileapp1');
  80.         $applicationProfile->setApplication($app1);
  81.         $applicationProfile->addPortalprofile($franchisee->getProfile());
  82.         $applicationProfile->addRole('ROLE_ACCESS');
  83.         $om->persist($applicationProfile);
  84.  
  85.         //CASE 2 : une app sans connecteur bluebean où le mec a pas l'accès par défaut
  86.  
  87.         //Create app without application profile
  88.         $app2 = $this->createApp(self::APP_TEST_WITH_NO_ACCESS, self::APPTEST_CONNECTOR_NAME);
  89.  
  90.         //CASE 3 : une app sans connecteur bluebean où le mec a l'accès par défaut mais ca a été surchargé par un accessapplicationprofile et il a pas accès (on l'a bien traité, ce cas là ?)
  91.  
  92.         $app3 = $this->createApp(self::APP_TEST_WITH_NO_ACCESS_OVERRIDEN, self::APPTEST_CONNECTOR_NAME);
  93.  
  94.         $applicationProfile = new Applicationprofile();
  95.         $applicationProfile->setName('appprofileapp3');
  96.         $applicationProfile->setApplication($app3);
  97.         $applicationProfile->addPortalprofile($franchisee->getProfile());
  98.         $applicationProfile->addRole('ROLE_ACCESS');
  99.         $om->persist($applicationProfile);
  100.  
  101.         $accessApplicationProfile = new AccessApplicationprofile();
  102.         $accessApplicationProfile->setApplicationprofile(null);
  103.         $accessApplicationProfile->setUser($franchisee);
  104.         $accessApplicationProfile->setApplication($app3);
  105.         $om->persist($accessApplicationProfile);
  106.  
  107.         //CASE 4 : une app sans connecteur bluebean où le mec a l'accès par défaut
  108.         /** @var User $franchisee */
  109.         $app4 = $this->createApp(self::APP_TEST_WITH_ACCESS_OVERRIDEN, self::APPTEST_CONNECTOR_NAME);
  110.         $applicationProfile = new Applicationprofile();
  111.         $applicationProfile->setName('appprofiletest');
  112.         $applicationProfile->setApplication($app4);
  113.         $applicationProfile->addPortalprofile($franchisee->getProfile());
  114.         $applicationProfile->addRole('ROLE_ACCESS');
  115.         $om->persist($applicationProfile);
  116.  
  117.         $accessApplicationProfile = new AccessApplicationprofile();
  118.         $accessApplicationProfile->setApplicationprofile($applicationProfile);
  119.         $accessApplicationProfile->setUser($franchisee);
  120.         $accessApplicationProfile->setApplication($app4);
  121.         $om->persist($accessApplicationProfile);
  122.  
  123.  
  124.         // CASE 5 : une app avec connecteur bluebean où le mec a pas accès
  125.         $app5 = $this->createApp(self::APP_BLUEBEAN_WITH_NO_ACCESS, self::BLUEBEAN_CONNECTOR_NAME);
  126.  
  127.  
  128.         //CASE 6 :  une app avec connecteur bluebean où le mec a accès à ses fixed-orderentities et c'est tout
  129.         $app6 = $this->createApp(self::APP_BLUEBEAN_WITH_ACCESS, self::BLUEBEAN_CONNECTOR_NAME);
  130.  
  131.         $applicationProfile = new Applicationprofile();
  132.         $applicationProfile->setName('appprofileapp6');
  133.         $applicationProfile->setApplication($app6);
  134.         $applicationProfile->addPortalprofile($franchisee->getProfile());
  135.         $applicationProfile->addRole('ROLE_EMETTEUR');
  136.         $om->persist($applicationProfile);
  137.  
  138.  
  139.         //CASE 7: une app avec connecteur bluebean où le mec a accès à ses fixed-orderentities, mais au moins une est désactivée, et on en rajoute au moins 1
  140.  
  141.         $app7 = $this->createApp(self::APP_BLUEBEAN_WITH_NO_ACCESS_OVERRIDEN, self::BLUEBEAN_CONNECTOR_NAME);
  142.  
  143.         $oe1 = $this->getReference('entiteCmd1');
  144.         $oe2 = $this->getReference('entiteCmd2');
  145.  
  146.  
  147.         $om->persist($oeUser1);
  148.         $om->persist($oeUser2);
  149.  
  150.         $applicationProfile = new Applicationprofile();
  151.         $applicationProfile->setName('appprofileapp6');
  152.         $applicationProfile->setApplication($app7);
  153.         $applicationProfile->addPortalprofile($franchisee->getProfile());
  154.         $applicationProfile->addRole('ROLE_EMETTEUR');
  155.         $om->persist($applicationProfile);
  156.  
  157.         $oeAccess = new AccessOrderentity();
  158.         $oeAccess->setUser($franchisee);
  159.         $oeAccess->setOrderentity($oe1);
  160.         $oeAccess->setApplication($app7);
  161.  
  162.         $oeAccessNegative = new AccessOrderentity();
  163.         $oeAccessNegative->setUser($franchisee);
  164.         $oeAccessNegative->setOrderentity($oe2);
  165.         $oeAccessNegative->setApplication($app7);
  166.         $oeAccessNegative->setNegativeOverride(true);
  167.  
  168.  
  169.         //CASE 8:  une app avec connecteur bluebean où le mec a accès à ses fixed-orderentities, mais pour "all orderentities", on a surchargé pour inverser le comportement (donc surcharge positive pour le mec qui avait pas )
  170.  
  171.         $app8 = $this->createApp(self::APP_BLUEBEAN_WITH_ACCESS_OVERRIDEN, self::BLUEBEAN_CONNECTOR_NAME);
  172.  
  173.         $oeAccess = new AccessOrderentity();
  174.         $oeAccess->setUser($franchisee);
  175.         $oeAccess->setOrderentity(null);
  176.         $oeAccess->setApplication($app8);
  177.  
  178.         $om->flush();
  179.     }
  180.  
  181.     /**
  182.      * @param string $name
  183.      * @param string $appConnector
  184.      * @return Application
  185.      */
  186.     public function createApp(string $name, string $appConnector): Application
  187.     {
  188.         $app = new Application();
  189.         $app->setName($name);
  190.         $app->setUrl('http://' . $name);
  191.         $app->setSamlNameID('externalID');
  192.         $app->setSlug($name);
  193.         $app->setConnector($appConnector);
  194.         $app->setIsBookmarkApplication(false);
  195.         $this->om->persist($app);
  196.  
  197.         return $app;
  198.     }
  199.  
  200.     public function getDependencies()
  201.     {
  202.         return [
  203.             UserFixtures::class,
  204.             OrderentityFixtures::class,
  205.         ];
  206.     }
  207.  
  208. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement