ModuleTest.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 Doctrine\Common\Collections\ArrayCollection;
  8. use PHPUnit\Framework\TestCase;
  9. use App\Service\Security\Module;
  10. class ModuleTest extends TestCase
  11. {
  12. const OPENTALENT_CONFIG = __DIR__.'/../../../config/opentalent';
  13. private Reflection $reflectionMock;
  14. private Parser $parser;
  15. public function setUp():void
  16. {
  17. $this->reflectionMock = $this->getMockBuilder(Reflection::class)->disableOriginalConstructor()->getMock();
  18. $this->parser = new Parser();
  19. }
  20. public function testGetOrganizationModules() {
  21. $module = $this->getMockBuilder(Module::class)
  22. ->onlyMethods(['getModuleBySettings', 'getModulesByConditions', 'getModulesByProductConfiguration'])
  23. ->disableOriginalConstructor()
  24. ->getMock();
  25. $module->expects(self::once())->method('getModuleBySettings')->willReturn(['Sms']);
  26. $module->expects(self::once())->method('getModulesByConditions')->willReturn(['CotisationCall']);
  27. $settings = $this->getMockBuilder(Settings::class)->disableOriginalConstructor()->getMock();
  28. $settings->expects(self::once())->method('getProduct')->willReturn('school');
  29. $organization = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock();
  30. $organization->expects(self::once())->method('getSettings')->willReturn($settings);
  31. $module->expects(self::once())->method('getModulesByProductConfiguration')->willReturn(['Notification']);
  32. $this->assertEqualsCanonicalizing(
  33. ['Sms', 'CotisationCall', 'Notification'],
  34. $module->getOrganizationModules($organization)
  35. );
  36. }
  37. /**
  38. * @see Module::getModuleBySettings()
  39. */
  40. public function testGetModuleBySettings(){
  41. $settingsMock = $this->getMockBuilder(Settings::class)->getMock();
  42. $settingsMock
  43. ->expects($this->once())
  44. ->method('getModules')
  45. ->willReturn(["Sms" => true]);
  46. $organizationMock = $this->getMockBuilder(Organization::class)->getMock();
  47. $organizationMock
  48. ->expects($this->once())
  49. ->method('getSettings')
  50. ->willReturn($settingsMock);
  51. $module = new Module($this->reflectionMock, $this->parser, self::OPENTALENT_CONFIG);
  52. $value = "Sms";
  53. // assert function to test whether 'value' is a value of array
  54. $this->assertContains($value, $module->getModuleBySettings($organizationMock)) ;
  55. }
  56. /**
  57. * @see Module::getModulesByConditions()
  58. */
  59. public function testGetModulesByConditions()
  60. {
  61. $organizationMock = $this->getMockBuilder(Organization::class)->getMock();
  62. $this->reflectionMock
  63. ->method('dynamicInvokeServiceWithArgsAndMethod')
  64. ->withConsecutive(
  65. ['App\\Service\\Cotisation\\Utils', 'isLastParentAndCMF', array($organizationMock)]
  66. )
  67. ->willReturnOnConsecutiveCalls(
  68. [true]
  69. )
  70. ;
  71. $module = new Module($this->reflectionMock, $this->parser, self::OPENTALENT_CONFIG);
  72. $value = "CotisationCall";
  73. // assert function to test whether 'value' is a value of array
  74. $this->assertContains($value, $module->getModulesByConditions($organizationMock)) ;
  75. }
  76. /**
  77. * @see Module::getModulesByProductConfiguration()
  78. */
  79. public function testGetModulesByProductConfiguration()
  80. {
  81. $module = new Module($this->reflectionMock, $this->parser, self::OPENTALENT_CONFIG);
  82. $value = "MessagesAdvanced";
  83. // assert function to test whether 'value' is a value of array
  84. $this->assertContains($value, $module->getModulesByProductConfiguration('artist-premium')) ;
  85. }
  86. }