OrganizationProfileCreatorTest.php 3.3 KB

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