ModuleTest.php 2.3 KB

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