| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace App\Test\Service\Organization;
- use App\ApiResources\Profile\OrganizationProfile;
- use App\Entity\Organization\Organization;
- use App\Entity\Organization\Parameters;
- use App\Entity\Organization\Settings;
- use App\Entity\Organization\Subdomain;
- use App\Enum\Organization\PrincipalTypeEnum;
- use App\Service\Network\Tree;
- use App\Service\Organization\OrganizationProfileCreator;
- use App\Service\Security\Module;
- use PHPUnit\Framework\TestCase;
- class OrganizationProfileCreatorTest extends TestCase
- {
- private Organization $organization;
- private Module $moduleMock;
- private Tree $treeMock;
- private OrganizationProfileCreator $organizationProfileCreator;
- public function setUp():void
- {
- $this->organization = new Organization();
- $this->moduleMock = $this->getMockBuilder(Module::class)->disableOriginalConstructor()->getMock();
- $this->moduleMock
- ->method('getOrganizationModules')
- ->with($this->organization)
- ->willReturn(["MODULE_A", "MODULE_B"]);
- $this->treeMock = $this->getMockBuilder(Tree::class)->disableOriginalConstructor()->getMock();
- $parent = new Organization();
- $parent->setName('Parent');
- $parent->setParameters(new Parameters());
- $this->treeMock
- ->method('findAllParentsAndSortByType')
- ->with($this->organization)
- ->willReturn([$parent, $parent]);
- $organizationUtils = new \App\Service\Organization\Utils();
- $this->organizationProfileCreator = new OrganizationProfileCreator($this->moduleMock,$this->treeMock, $organizationUtils);
- $this->organization->setPrincipalType(PrincipalTypeEnum::ARTISTIC_EDUCATION_ONLY());
- $settings = new Settings();
- $settings->setProduct('adminassos');
- $parameters = new Parameters();
- $parameters->setShowAdherentList(true);
- $subdomain = new Subdomain();
- $this->organization
- ->setParameters($parameters)
- ->setSettings($settings)
- ->addSubdomain($subdomain)
- ->setName('Foo')
- ;
- }
- /**
- * @see OrganizationProfileCreator::createCompleteOrganizationProfile()
- */
- public function testCreateCompleteOrganizationProfile(){
- $organizationProfile = $this->organizationProfileCreator->createCompleteOrganizationProfile($this->organization);
- $this->assertInstanceOf(OrganizationProfile::class, $organizationProfile);
- }
- public function testCreateOrganizationProfileWithoutAdherentListBecauseOfPrincipalType(){
- $organizationProfile = $this->organizationProfileCreator->createCompleteOrganizationProfile($this->organization);
- $this->assertFalse($organizationProfile->getShowAdherentList());
- }
- public function testCreateOrganizationProfileWithoutAdherentList(){
- $this->organization->setPrincipalType(PrincipalTypeEnum::ARTISTIC_PRACTICE_ONLY());
- $this->organization->getParameters()->setShowAdherentList(false);
- $organizationProfile = $this->organizationProfileCreator->createCompleteOrganizationProfile($this->organization);
- $this->assertFalse($organizationProfile->getShowAdherentList());
- }
- public function testCreateOrganizationProfileWithAdherentList(){
- $this->organization->setPrincipalType(PrincipalTypeEnum::ARTISTIC_PRACTICE_ONLY());
- $organizationProfile = $this->organizationProfileCreator->createCompleteOrganizationProfile($this->organization);
- $this->assertTrue($organizationProfile->getShowAdherentList());
- }
- }
|