CurrentAccessExtensionTest.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Tests\Doctrine\Access;
  4. use App\Doctrine\Access\CurrentAccessExtension;
  5. use App\Entity\Access\Access;
  6. use App\Service\ServiceIterator\CurrentAccessExtensionIterator;
  7. use App\Tests\Unit\DoctrineExtension\AbstractExtensionTest;
  8. class CurrentAccessExtensionTest extends AbstractExtensionTest
  9. {
  10. private $extension;
  11. private $currentAccessExtensionIterator;
  12. protected function setUp(): void
  13. {
  14. parent::setUp();
  15. $this->currentAccessExtensionIterator = $this->createMock(CurrentAccessExtensionIterator::class);
  16. $this->extension = new CurrentAccessExtension($this->security, $this->currentAccessExtensionIterator);
  17. }
  18. public function testSupportsReturnsTrueForAccessClass()
  19. {
  20. $this->assertTrue($this->extension->supports(Access::class, null));
  21. }
  22. public function testSupportsReturnsFalseForOtherClasses()
  23. {
  24. $this->assertFalse($this->extension->supports('OtherClass', null));
  25. }
  26. public function testAddWhere()
  27. {
  28. $this->user->method('getOrganization')->willReturn($this->organization);
  29. $this->token->method('getUser')->willReturn($this->user);
  30. $this->security->method('getToken')->willReturn($this->token);
  31. $this->queryBuilder->method('getRootAliases')->willReturn(['a']);
  32. $this->queryBuilder->expects($this->once())
  33. ->method('andWhere')
  34. ->with('a.organization = :current_organization')
  35. ->willReturn($this->queryBuilder);
  36. $this->queryBuilder->expects($this->once())
  37. ->method('setParameter')
  38. ->with('current_organization', $this->organization)
  39. ->willReturn($this->queryBuilder);
  40. $this->currentAccessExtensionIterator->expects($this->once())
  41. ->method('addWhere')
  42. ->with($this->queryBuilder, '');
  43. $this->invokeAddWhere($this->extension, $this->queryBuilder, Access::class, null);
  44. }
  45. }