OrganizationProfileCreatorTest.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. $this->organizationProfileCreator = new OrganizationProfileCreator($this->moduleMock,$this->treeMock);
  36. $this->organization->setPrincipalType(PrincipalTypeEnum::ARTISTIC_EDUCATION_ONLY());
  37. $settings = new Settings();
  38. $settings->setProduct('adminassos');
  39. $parameters = new Parameters();
  40. $parameters->setShowAdherentList(true);
  41. $subdomain = new Subdomain();
  42. $this->organization
  43. ->setParameters($parameters)
  44. ->setSettings($settings)
  45. ->addSubdomain($subdomain)
  46. ->setName('Foo')
  47. ;
  48. }
  49. /**
  50. * @see OrganizationProfileCreator::createCompleteOrganizationProfile()
  51. */
  52. public function testCreateCompleteOrganizationProfile(){
  53. $organizationProfile = $this->organizationProfileCreator->createCompleteOrganizationProfile($this->organization);
  54. $this->assertInstanceOf(OrganizationProfile::class, $organizationProfile);
  55. }
  56. public function testCreateOrganizationProfileWithoutAdherentListBecauseOfPrincipalType(){
  57. $organizationProfile = $this->organizationProfileCreator->createCompleteOrganizationProfile($this->organization);
  58. $this->assertFalse($organizationProfile->getShowAdherentList());
  59. }
  60. public function testCreateOrganizationProfileWithoutAdherentList(){
  61. $this->organization->setPrincipalType(PrincipalTypeEnum::ARTISTIC_PRACTICE_ONLY());
  62. $this->organization->getParameters()->setShowAdherentList(false);
  63. $organizationProfile = $this->organizationProfileCreator->createCompleteOrganizationProfile($this->organization);
  64. $this->assertFalse($organizationProfile->getShowAdherentList());
  65. }
  66. public function testCreateOrganizationProfileWithAdherentList(){
  67. $this->organization->setPrincipalType(PrincipalTypeEnum::ARTISTIC_PRACTICE_ONLY());
  68. $organizationProfile = $this->organizationProfileCreator->createCompleteOrganizationProfile($this->organization);
  69. $this->assertTrue($organizationProfile->getShowAdherentList());
  70. }
  71. }