OrganizationProfileCreatorTest.php 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace App\Test\Service\Organization;
  3. use App\ApiResources\Profile\OrganizationProfile;
  4. use App\Entity\Organization\Organization;
  5. use App\Entity\Organization\Parameters;
  6. use App\Entity\Organization\Settings;
  7. use App\Entity\Organization\Subdomain;
  8. use App\Enum\Organization\PrincipalTypeEnum;
  9. use App\Service\Network\Tree;
  10. use App\Service\Organization\OrganizationProfileCreator;
  11. use App\Service\Security\Module;
  12. use PHPUnit\Framework\TestCase;
  13. class OrganizationProfileCreatorTest extends TestCase
  14. {
  15. private Organization $organization;
  16. private Module $moduleMock;
  17. private Tree $treeMock;
  18. private OrganizationProfileCreator $organizationProfileCreator;
  19. public function setUp():void
  20. {
  21. $this->organization = new Organization();
  22. $this->moduleMock = $this->getMockBuilder(Module::class)->disableOriginalConstructor()->getMock();
  23. $this->moduleMock
  24. ->method('getOrganizationModules')
  25. ->with($this->organization)
  26. ->willReturn(["MODULE_A", "MODULE_B"]);
  27. $this->treeMock = $this->getMockBuilder(Tree::class)->disableOriginalConstructor()->getMock();
  28. $parent = new Organization();
  29. $parent->setName('Parent');
  30. $parent->setParameters(new Parameters());
  31. $this->treeMock
  32. ->method('findAllParentsAndSortByType')
  33. ->with($this->organization)
  34. ->willReturn([$parent, $parent]);
  35. $organizationUtils = new \App\Service\Organization\Utils();
  36. $this->organizationProfileCreator = new OrganizationProfileCreator($this->moduleMock,$this->treeMock, $organizationUtils);
  37. $this->organization->setPrincipalType(PrincipalTypeEnum::ARTISTIC_EDUCATION_ONLY());
  38. $settings = new Settings();
  39. $settings->setProduct('adminassos');
  40. $parameters = new Parameters();
  41. $parameters->setShowAdherentList(true);
  42. $subdomain = new Subdomain();
  43. $this->organization
  44. ->setParameters($parameters)
  45. ->setSettings($settings)
  46. ->addSubdomain($subdomain)
  47. ->setName('Foo')
  48. ;
  49. }
  50. /**
  51. * @see OrganizationProfileCreator::createCompleteOrganizationProfile()
  52. */
  53. public function testCreateCompleteOrganizationProfile(){
  54. $organizationProfile = $this->organizationProfileCreator->createCompleteOrganizationProfile($this->organization);
  55. $this->assertInstanceOf(OrganizationProfile::class, $organizationProfile);
  56. }
  57. public function testCreateOrganizationProfileWithoutAdherentListBecauseOfPrincipalType(){
  58. $organizationProfile = $this->organizationProfileCreator->createCompleteOrganizationProfile($this->organization);
  59. $this->assertFalse($organizationProfile->getShowAdherentList());
  60. }
  61. public function testCreateOrganizationProfileWithoutAdherentList(){
  62. $this->organization->setPrincipalType(PrincipalTypeEnum::ARTISTIC_PRACTICE_ONLY());
  63. $this->organization->getParameters()->setShowAdherentList(false);
  64. $organizationProfile = $this->organizationProfileCreator->createCompleteOrganizationProfile($this->organization);
  65. $this->assertFalse($organizationProfile->getShowAdherentList());
  66. }
  67. public function testCreateOrganizationProfileWithAdherentList(){
  68. $this->organization->setPrincipalType(PrincipalTypeEnum::ARTISTIC_PRACTICE_ONLY());
  69. $organizationProfile = $this->organizationProfileCreator->createCompleteOrganizationProfile($this->organization);
  70. $this->assertTrue($organizationProfile->getShowAdherentList());
  71. }
  72. }