|
|
@@ -0,0 +1,48 @@
|
|
|
+<?php
|
|
|
+namespace App\Test\Service\Security;
|
|
|
+
|
|
|
+use App\Entity\Access\Access;
|
|
|
+use App\Service\Security\SwitchUser;
|
|
|
+use Doctrine\Common\Collections\ArrayCollection;
|
|
|
+use PHPUnit\Framework\TestCase;
|
|
|
+
|
|
|
+class SwitchUserTest extends TestCase
|
|
|
+{
|
|
|
+ public function setUp():void
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @see SwitchUser::isAllowedToSwitch()
|
|
|
+ */
|
|
|
+ public function testIsAllowedToSwitch(){
|
|
|
+ $childrenMockMock = $this->getMockBuilder(Access::class)->getMock();
|
|
|
+
|
|
|
+ $children = new ArrayCollection();
|
|
|
+ $children->add($childrenMockMock);
|
|
|
+
|
|
|
+ $userMockMock = $this->getMockBuilder(Access::class)->getMock();
|
|
|
+ $userMockMock
|
|
|
+ ->expects($this->once())
|
|
|
+ ->method('getChildren')
|
|
|
+ ->willReturn($children);
|
|
|
+
|
|
|
+ $switchUser = new SwitchUser();
|
|
|
+ $this->assertTrue($switchUser->isAllowedToSwitch($userMockMock, $childrenMockMock));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @see SwitchUser::isAllowedToSwitch()
|
|
|
+ */
|
|
|
+ public function testIsNotAllowedToSwitch(){
|
|
|
+ $childrenMockMock = $this->getMockBuilder(Access::class)->getMock();
|
|
|
+ $userMockMock = $this->getMockBuilder(Access::class)->getMock();
|
|
|
+ $userMockMock
|
|
|
+ ->expects($this->once())
|
|
|
+ ->method('getChildren')
|
|
|
+ ->willReturn(new ArrayCollection());
|
|
|
+
|
|
|
+ $switchUser = new SwitchUser();
|
|
|
+ $this->assertFalse($switchUser->isAllowedToSwitch($userMockMock, $childrenMockMock));
|
|
|
+ }
|
|
|
+}
|