ModuleTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace App\Test\Service\Security;
  3. use App\Entity\Organization\Organization;
  4. use App\Entity\Organization\Settings;
  5. use App\Service\Utils\Parser;
  6. use App\Service\Utils\Reflection;
  7. use PHPUnit\Framework\TestCase;
  8. use App\Service\Security\Module;
  9. class ModuleTest extends TestCase
  10. {
  11. const OPENTALENT_CONFIG = __DIR__.'/../../../config/opentalent';
  12. private Reflection $reflectionMock;
  13. private Parser $parser;
  14. public function setUp():void
  15. {
  16. $this->reflectionMock = $this->getMockBuilder(Reflection::class)->disableOriginalConstructor()->getMock();
  17. $this->parser= new Parser();
  18. }
  19. /**
  20. * @see Module::getModuleBySettings()
  21. */
  22. public function testGetModuleBySettings(){
  23. $settingsMock = $this->getMockBuilder(Settings::class)->getMock();
  24. $settingsMock
  25. ->expects($this->once())
  26. ->method('getModules')
  27. ->willReturn(["Sms" => true]);
  28. $organizationMock = $this->getMockBuilder(Organization::class)->getMock();
  29. $organizationMock
  30. ->expects($this->once())
  31. ->method('getSettings')
  32. ->willReturn($settingsMock);
  33. $module = new Module($this->reflectionMock, $this->parser, self::OPENTALENT_CONFIG);
  34. $value = "Sms";
  35. // assert function to test whether 'value' is a value of array
  36. $this->assertContains($value, $module->getModuleBySettings($organizationMock)) ;
  37. }
  38. /**
  39. * @see Module::getModulesByConditions()
  40. */
  41. public function testGetModulesByConditions()
  42. {
  43. $organizationMock = $this->getMockBuilder(Organization::class)->getMock();
  44. $this->reflectionMock
  45. ->method('dynamicInvokeServiceWithArgsAndMethod')
  46. ->with('opentalent.network.utils', 'isCMF', array($organizationMock))
  47. ->willReturn(true);
  48. $module = new Module($this->reflectionMock, $this->parser, self::OPENTALENT_CONFIG);
  49. $value = "Network";
  50. // assert function to test whether 'value' is a value of array
  51. $this->assertContains($value, $module->getModulesByConditions($organizationMock)) ;
  52. }
  53. /**
  54. * @see Module::getModulesByProductConfiguration()
  55. */
  56. public function testGetModulesByProductConfiguration()
  57. {
  58. $module = new Module($this->reflectionMock, $this->parser, self::OPENTALENT_CONFIG);
  59. $value = "MessagesAdvanced";
  60. // assert function to test whether 'value' is a value of array
  61. $this->assertContains($value, $module->getModulesByProductConfiguration('artist-premium')) ;
  62. }
  63. }