|
|
@@ -11,8 +11,32 @@ use \App\Service\Network\Utils as NetworkUtils;
|
|
|
|
|
|
class UtilsTest extends TestCase
|
|
|
{
|
|
|
+ private $organizationMock;
|
|
|
+
|
|
|
+ private $organizationRepositoryMock;
|
|
|
+
|
|
|
+ private $networkUtilsMock;
|
|
|
+
|
|
|
+ private $organizationUtilsMock;
|
|
|
+
|
|
|
public function setUp(): void
|
|
|
{
|
|
|
+ $this->organizationRepositoryMock =
|
|
|
+ $this
|
|
|
+ ->getMockBuilder(OrganizationRepository::class)
|
|
|
+ ->disableOriginalConstructor()
|
|
|
+ ->getMock();
|
|
|
+
|
|
|
+ $this->networkUtilsMock =
|
|
|
+ $this
|
|
|
+ ->getMockBuilder(NetworkUtils::class)
|
|
|
+ ->disableOriginalConstructor()
|
|
|
+ ->getMock();
|
|
|
+
|
|
|
+ $this->organizationUtilsMock =
|
|
|
+ $this
|
|
|
+ ->getMockBuilder(OrganizationUtils::class)
|
|
|
+ ->getMock();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -25,31 +49,19 @@ class UtilsTest extends TestCase
|
|
|
->method('getId')
|
|
|
->willReturn(1);
|
|
|
|
|
|
- $organizationRepositoryMock =
|
|
|
- $this
|
|
|
- ->getMockBuilder(OrganizationRepository::class)
|
|
|
- ->disableOriginalConstructor()
|
|
|
- ->getMock();
|
|
|
- $organizationRepositoryMock
|
|
|
+ $this->organizationRepositoryMock
|
|
|
->expects($this->once())
|
|
|
->method('isLastParent')
|
|
|
->with($organizationMock)
|
|
|
->willReturn(true);
|
|
|
|
|
|
- $networkUtilsMock =
|
|
|
- $this
|
|
|
- ->getMockBuilder(NetworkUtils::class)
|
|
|
- ->disableOriginalConstructor()
|
|
|
- ->getMock();
|
|
|
- $networkUtilsMock
|
|
|
+ $this->networkUtilsMock
|
|
|
->expects($this->once())
|
|
|
->method('isCMF')
|
|
|
->with($organizationMock)
|
|
|
->willReturn(true);
|
|
|
|
|
|
- $organizationUtilsMock = $this->getMockBuilder(OrganizationUtils::class)->getMock();
|
|
|
-
|
|
|
- $utils = new Utils($networkUtilsMock, $organizationUtilsMock, $organizationRepositoryMock);
|
|
|
+ $utils = new Utils($this->networkUtilsMock, $this->organizationUtilsMock, $this->organizationRepositoryMock);
|
|
|
$this->assertTrue($utils->isLastParentAndCMF($organizationMock));
|
|
|
}
|
|
|
|
|
|
@@ -63,31 +75,166 @@ class UtilsTest extends TestCase
|
|
|
->method('getId')
|
|
|
->willReturn(1);
|
|
|
|
|
|
- $organizationRepositoryMock =
|
|
|
- $this
|
|
|
- ->getMockBuilder(OrganizationRepository::class)
|
|
|
- ->disableOriginalConstructor()
|
|
|
- ->getMock();
|
|
|
- $organizationRepositoryMock
|
|
|
+ $this->organizationRepositoryMock
|
|
|
->expects($this->once())
|
|
|
->method('isLastParent')
|
|
|
->with($organizationMock)
|
|
|
->willReturn(false);
|
|
|
|
|
|
- $networkUtilsMock =
|
|
|
- $this
|
|
|
- ->getMockBuilder(NetworkUtils::class)
|
|
|
- ->disableOriginalConstructor()
|
|
|
- ->getMock();
|
|
|
- $networkUtilsMock
|
|
|
+ $this->networkUtilsMock
|
|
|
->expects($this->never())
|
|
|
+ ->method('isCMF');
|
|
|
+
|
|
|
+ $utils = new Utils($this->networkUtilsMock, $this->organizationUtilsMock, $this->organizationRepositoryMock);
|
|
|
+ $this->assertFalse($utils->isLastParentAndCMF($organizationMock));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @see Utils::isStructureAndCMF()
|
|
|
+ */
|
|
|
+ public function testIsStructureAndCMF(): void
|
|
|
+ {
|
|
|
+ $organizationMock = $this->getMockBuilder(Organization::class)->getMock();
|
|
|
+
|
|
|
+ $this->organizationUtilsMock
|
|
|
+ ->expects($this->once())
|
|
|
+ ->method('isStructure')
|
|
|
+ ->with($organizationMock)
|
|
|
+ ->willReturn(true);
|
|
|
+
|
|
|
+ $this->networkUtilsMock
|
|
|
+ ->expects($this->once())
|
|
|
->method('isCMF')
|
|
|
->with($organizationMock)
|
|
|
->willReturn(true);
|
|
|
|
|
|
- $organizationUtilsMock = $this->getMockBuilder(OrganizationUtils::class)->getMock();
|
|
|
+ $utils = new Utils($this->networkUtilsMock, $this->organizationUtilsMock, $this->organizationRepositoryMock);
|
|
|
+ $this->assertTrue($utils->isStructureAndCMF($organizationMock));
|
|
|
+ }
|
|
|
|
|
|
- $utils = new Utils($networkUtilsMock, $organizationUtilsMock, $organizationRepositoryMock);
|
|
|
- $this->assertFalse($utils->isLastParentAndCMF($organizationMock));
|
|
|
+ /**
|
|
|
+ * @see Utils::isStructureAndCMF()
|
|
|
+ */
|
|
|
+ public function testIsNotStructureAndCMF(): void
|
|
|
+ {
|
|
|
+ $organizationMock = $this->getMockBuilder(Organization::class)->getMock();
|
|
|
+
|
|
|
+ $this->organizationUtilsMock
|
|
|
+ ->expects($this->once())
|
|
|
+ ->method('isStructure')
|
|
|
+ ->with($organizationMock)
|
|
|
+ ->willReturn(false);
|
|
|
+
|
|
|
+ $this->networkUtilsMock
|
|
|
+ ->expects($this->never())
|
|
|
+ ->method('isCMF');
|
|
|
+
|
|
|
+ $utils = new Utils($this->networkUtilsMock, $this->organizationUtilsMock, $this->organizationRepositoryMock);
|
|
|
+ $this->assertFalse($utils->isStructureAndCMF($organizationMock));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @see Utils::isManagerAndCMF()
|
|
|
+ */
|
|
|
+ public function testIsManagerAndCMF(): void
|
|
|
+ {
|
|
|
+ $organizationMock = $this->getMockBuilder(Organization::class)->getMock();
|
|
|
+
|
|
|
+ $this->organizationUtilsMock
|
|
|
+ ->expects($this->once())
|
|
|
+ ->method('isManager')
|
|
|
+ ->with($organizationMock)
|
|
|
+ ->willReturn(true);
|
|
|
+
|
|
|
+ $this->networkUtilsMock
|
|
|
+ ->expects($this->once())
|
|
|
+ ->method('isCMF')
|
|
|
+ ->with($organizationMock)
|
|
|
+ ->willReturn(true);
|
|
|
+
|
|
|
+ $utils = new Utils($this->networkUtilsMock, $this->organizationUtilsMock, $this->organizationRepositoryMock);
|
|
|
+ $this->assertTrue($utils->isManagerAndCMF($organizationMock));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @see Utils::isManagerAndCMF()
|
|
|
+ */
|
|
|
+ public function testIsNotManagerAndCMF(): void
|
|
|
+ {
|
|
|
+ $organizationMock = $this->getMockBuilder(Organization::class)->getMock();
|
|
|
+
|
|
|
+ $this->organizationUtilsMock
|
|
|
+ ->expects($this->once())
|
|
|
+ ->method('isManager')
|
|
|
+ ->with($organizationMock)
|
|
|
+ ->willReturn(false);
|
|
|
+
|
|
|
+ $this->networkUtilsMock
|
|
|
+ ->expects($this->never())
|
|
|
+ ->method('isCMF');
|
|
|
+
|
|
|
+ $utils = new Utils($this->networkUtilsMock, $this->organizationUtilsMock, $this->organizationRepositoryMock);
|
|
|
+ $this->assertFalse($utils->isManagerAndCMF($organizationMock));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @see Utils::isManagerAndNotLastParentAndCMF()
|
|
|
+ */
|
|
|
+ public function testIsManagerAndNotLastParentAndCMF(): void
|
|
|
+ {
|
|
|
+ $organizationMock = $this->getMockBuilder(Organization::class)->getMock();
|
|
|
+ $organizationMock
|
|
|
+ ->method('getId')
|
|
|
+ ->willReturn(1);
|
|
|
+
|
|
|
+ $this->organizationUtilsMock
|
|
|
+ ->expects($this->once())
|
|
|
+ ->method('isManager')
|
|
|
+ ->with($organizationMock)
|
|
|
+ ->willReturn(true);
|
|
|
+
|
|
|
+ $this->organizationRepositoryMock
|
|
|
+ ->expects($this->once())
|
|
|
+ ->method('isLastParent')
|
|
|
+ ->with($organizationMock)
|
|
|
+ ->willReturn(false);
|
|
|
+
|
|
|
+ $this->networkUtilsMock
|
|
|
+ ->expects($this->never())
|
|
|
+ ->method('isCMF');
|
|
|
+
|
|
|
+ $utils = new Utils($this->networkUtilsMock, $this->organizationUtilsMock, $this->organizationRepositoryMock);
|
|
|
+ $this->assertTrue($utils->isManagerAndNotLastParentAndCMF($organizationMock));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @see Utils::isManagerAndLastParentAndCMF()
|
|
|
+ */
|
|
|
+ public function testIsManagerAndLastParentAndCMF(): void
|
|
|
+ {
|
|
|
+ $organizationMock = $this->getMockBuilder(Organization::class)->getMock();
|
|
|
+ $organizationMock
|
|
|
+ ->method('getId')
|
|
|
+ ->willReturn(1);
|
|
|
+
|
|
|
+ $this->organizationUtilsMock
|
|
|
+ ->expects($this->once())
|
|
|
+ ->method('isManager')
|
|
|
+ ->with($organizationMock)
|
|
|
+ ->willReturn(true);
|
|
|
+
|
|
|
+ $this->organizationRepositoryMock
|
|
|
+ ->expects($this->once())
|
|
|
+ ->method('isLastParent')
|
|
|
+ ->with($organizationMock)
|
|
|
+ ->willReturn(true);
|
|
|
+
|
|
|
+ $this->networkUtilsMock
|
|
|
+ ->expects($this->once())
|
|
|
+ ->method('isCMF')
|
|
|
+ ->willReturn(true);
|
|
|
+
|
|
|
+ $utils = new Utils($this->networkUtilsMock, $this->organizationUtilsMock, $this->organizationRepositoryMock);
|
|
|
+ $this->assertTrue($utils->isManagerAndLastParentAndCMF($organizationMock));
|
|
|
}
|
|
|
}
|