| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
- namespace App\Test\Service\Security;
- use App\Entity\Organization\Organization;
- use App\Entity\Organization\Settings;
- use App\Service\Utils\Parser;
- use App\Service\Utils\Reflection;
- use Doctrine\Common\Collections\ArrayCollection;
- use PHPUnit\Framework\TestCase;
- use App\Service\Security\Module;
- use App\Service\Cotisation\Utils as CotisationUtils;
- class ModuleTest extends TestCase
- {
- private const OPENTALENT_CONFIG = __DIR__.'/../../../config/opentalent';
- private Reflection $reflectionMock;
- private Parser $parser;
- public function setUp():void
- {
- $this->reflectionMock = $this->getMockBuilder(Reflection::class)->disableOriginalConstructor()->getMock();
- $this->parser = new Parser();
- }
- public function testGetOrganizationModules(): void
- {
- $module = $this->getMockBuilder(Module::class)
- ->setConstructorArgs([$this->reflectionMock, $this->parser, self::OPENTALENT_CONFIG])
- ->setMethodsExcept(['getOrganizationModules'])
- ->getMock();
- $module->expects(self::once())->method('getModuleBySettings')->willReturn(['Sms']);
- $module->expects(self::once())->method('getModulesByConditions')->willReturn(['CotisationCall']);
- $settings = $this->getMockBuilder(Settings::class)->disableOriginalConstructor()->getMock();
- $settings->expects(self::once())->method('getProduct')->willReturn('school');
- $organization = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock();
- $organization->expects(self::once())->method('getSettings')->willReturn($settings);
- $module->expects(self::once())->method('getModulesByProductConfiguration')->willReturn(['Notification']);
- $this->assertEqualsCanonicalizing(
- ['Sms', 'CotisationCall', 'Notification'],
- $module->getOrganizationModules($organization)
- );
- }
- /**
- * @see Module::getModuleBySettings()
- */
- public function testGetModuleBySettings(): void
- {
- $module = $this->getMockBuilder(Module::class)
- ->setConstructorArgs([$this->reflectionMock, $this->parser, self::OPENTALENT_CONFIG])
- ->setMethodsExcept(['getModuleBySettings'])
- ->getMock();
- $settingsMock = $this->getMockBuilder(Settings::class)->getMock();
- $settingsMock
- ->expects($this->once())
- ->method('getModules')
- ->willReturn(["Sms" => true]);
- $organizationMock = $this->getMockBuilder(Organization::class)->getMock();
- $organizationMock
- ->expects($this->once())
- ->method('getSettings')
- ->willReturn($settingsMock);
- $value = "Sms";
- // assert function to test whether 'value' is a value of array
- $this->assertContains($value, $module->getModuleBySettings($organizationMock)) ;
- }
- /**
- * @see Module::getModulesByConditions()
- */
- public function testGetModulesByConditions(): void
- {
- $module = $this->getMockBuilder(Module::class)
- ->setConstructorArgs([$this->reflectionMock, $this->parser, self::OPENTALENT_CONFIG])
- ->setMethodsExcept(['getModulesByConditions'])
- ->getMock();
- $organizationMock = $this->getMockBuilder(Organization::class)->getMock();
- $this->reflectionMock
- ->method('dynamicInvokeServiceWithArgsAndMethod')
- ->withConsecutive(
- [CotisationUtils::class, 'isLastParentAndCMF', array($organizationMock)]
- )
- ->willReturnOnConsecutiveCalls(
- [true]
- )
- ;
- $value = "CotisationCall";
- // assert function to test whether 'value' is a value of array
- $this->assertContains($value, $module->getModulesByConditions($organizationMock)) ;
- }
- /**
- * @see Module::getModulesByProductConfiguration()
- */
- public function testGetModulesByProductConfiguration()
- {
- $module = $this->getMockBuilder(Module::class)
- ->setConstructorArgs([$this->reflectionMock, $this->parser, self::OPENTALENT_CONFIG])
- ->setMethodsExcept(['getModulesByProductConfiguration'])
- ->getMock();
- $value = "MessagesAdvanced";
- // assert function to test whether 'value' is a value of array
- $this->assertContains($value, $module->getModulesByProductConfiguration('artist-premium')) ;
- }
- }
|