|
|
@@ -0,0 +1,99 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+declare(strict_types=1);
|
|
|
+
|
|
|
+namespace App\Tests\Unit\DoctrineExtension\Education;
|
|
|
+
|
|
|
+use App\Doctrine\Education\CurrentEducationNotationConfigExtension;
|
|
|
+use App\Entity\Access\Access;
|
|
|
+use App\Entity\Education\EducationNotationConfig;
|
|
|
+use App\Entity\Organization\Organization;
|
|
|
+use Doctrine\ORM\QueryBuilder;
|
|
|
+use PHPUnit\Framework\TestCase;
|
|
|
+use Symfony\Bundle\SecurityBundle\Security;
|
|
|
+
|
|
|
+class CurrentEducationNotationConfigExtensionTest extends TestCase
|
|
|
+{
|
|
|
+ private $security;
|
|
|
+ private $queryBuilder;
|
|
|
+ private $extension;
|
|
|
+ private $user;
|
|
|
+ private $organization;
|
|
|
+
|
|
|
+ protected function setUp(): void
|
|
|
+ {
|
|
|
+ $this->security = $this->createMock(Security::class);
|
|
|
+ $this->queryBuilder = $this->createMock(QueryBuilder::class);
|
|
|
+ $this->user = $this->createMock(Access::class);
|
|
|
+ $this->organization = $this->createMock(Organization::class);
|
|
|
+
|
|
|
+ $this->extension = new CurrentEducationNotationConfigExtension($this->security);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testSupportsReturnsTrueForEducationNotationConfigClass()
|
|
|
+ {
|
|
|
+ $this->assertTrue($this->extension->supports(EducationNotationConfig::class, null));
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testSupportsReturnsFalseForOtherClasses()
|
|
|
+ {
|
|
|
+ $classes = ['OtherClass', Access::class];
|
|
|
+
|
|
|
+ foreach ($classes as $class) {
|
|
|
+ $this->assertFalse($this->extension->supports($class, null));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testAddWhere()
|
|
|
+ {
|
|
|
+ $this->user->method('getOrganization')->willReturn($this->organization);
|
|
|
+ $this->security->method('getUser')->willReturn($this->user);
|
|
|
+ $this->queryBuilder->method('getRootAliases')->willReturn(['o']);
|
|
|
+
|
|
|
+ $this->queryBuilder->expects($this->once())
|
|
|
+ ->method('andWhere')
|
|
|
+ ->with('o.organization = :organization')
|
|
|
+ ->willReturn($this->queryBuilder);
|
|
|
+
|
|
|
+ $this->queryBuilder->expects($this->once())
|
|
|
+ ->method('setParameter')
|
|
|
+ ->with('organization', $this->organization)
|
|
|
+ ->willReturn($this->queryBuilder);
|
|
|
+
|
|
|
+ $reflection = new \ReflectionClass($this->extension);
|
|
|
+ $method = $reflection->getMethod('addWhere');
|
|
|
+ $method->setAccessible(true);
|
|
|
+ $method->invoke($this->extension, $this->queryBuilder, EducationNotationConfig::class, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testAddWhereWithNullUser()
|
|
|
+ {
|
|
|
+ $this->security->method('getUser')->willReturn(null);
|
|
|
+ $this->queryBuilder->method('getRootAliases')->willReturn(['o']);
|
|
|
+ $this->queryBuilder->expects($this->never())
|
|
|
+ ->method('andWhere');
|
|
|
+ $this->queryBuilder->expects($this->never())
|
|
|
+ ->method('setParameter');
|
|
|
+
|
|
|
+ $reflection = new \ReflectionClass($this->extension);
|
|
|
+ $method = $reflection->getMethod('addWhere');
|
|
|
+ $method->setAccessible(true);
|
|
|
+ $method->invoke($this->extension, $this->queryBuilder, EducationNotationConfig::class, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testAddWhereWithNullOrganization()
|
|
|
+ {
|
|
|
+ $this->user->method('getOrganization')->willReturn(null);
|
|
|
+ $this->security->method('getUser')->willReturn($this->user);
|
|
|
+ $this->queryBuilder->method('getRootAliases')->willReturn(['o']);
|
|
|
+ $this->queryBuilder->expects($this->never())
|
|
|
+ ->method('andWhere');
|
|
|
+ $this->queryBuilder->expects($this->never())
|
|
|
+ ->method('setParameter');
|
|
|
+
|
|
|
+ $reflection = new \ReflectionClass($this->extension);
|
|
|
+ $method = $reflection->getMethod('addWhere');
|
|
|
+ $method->setAccessible(true);
|
|
|
+ $method->invoke($this->extension, $this->queryBuilder, EducationNotationConfig::class, null);
|
|
|
+ }
|
|
|
+}
|