|
|
@@ -5,6 +5,7 @@ namespace App\Tests\Unit\Service\Access;
|
|
|
use App\ApiResources\Profile\AccessProfile;
|
|
|
use App\ApiResources\Profile\OrganizationProfile;
|
|
|
use App\Entity\Access\Access;
|
|
|
+use App\Entity\Access\Preferences;
|
|
|
use App\Entity\Core\File;
|
|
|
use App\Entity\Organization\Organization;
|
|
|
use App\Entity\Person\Person;
|
|
|
@@ -15,6 +16,7 @@ use App\Service\Access\Utils as AccessUtils;
|
|
|
use App\Service\Organization\OrganizationProfileCreator;
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
|
use Doctrine\Common\Collections\Collection;
|
|
|
+use Doctrine\ORM\EntityManagerInterface;
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
use Symfony\Component\Security\Core\Exception\AuthenticationException;
|
|
|
@@ -31,12 +33,14 @@ class AccessProfileCreatorTest extends TestCase
|
|
|
private MockObject|Organization $organization;
|
|
|
private MockObject|Access $access;
|
|
|
private MockObject|OrganizationProfile $organizationProfile;
|
|
|
+ private MockObject|EntityManagerInterface $entityManager;
|
|
|
|
|
|
public function setUp(): void
|
|
|
{
|
|
|
$this->organizationProfileCreator = $this->getMockBuilder(OrganizationProfileCreator::class)->disableOriginalConstructor()->getMock();
|
|
|
$this->accessRepository = $this->getMockBuilder(AccessRepository::class)->disableOriginalConstructor()->getMock();
|
|
|
$this->accessUtils = $this->getMockBuilder(AccessUtils::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $this->entityManager = $this->getMockBuilder(EntityManagerInterface::class)->disableOriginalConstructor()->getMock();
|
|
|
|
|
|
$this->emptyCollection = $this->getMockBuilder(Collection::class)->getMock();
|
|
|
$this->emptyCollection->method('isEmpty')->willReturn(true);
|
|
|
@@ -57,7 +61,7 @@ class AccessProfileCreatorTest extends TestCase
|
|
|
{
|
|
|
$this->accessProfileCreator = $this
|
|
|
->getMockBuilder(AccessProfileCreator::class)
|
|
|
- ->setConstructorArgs([$this->organizationProfileCreator, $this->accessRepository, $this->accessUtils])
|
|
|
+ ->setConstructorArgs([$this->organizationProfileCreator, $this->accessRepository, $this->accessUtils, $this->entityManager])
|
|
|
->setMethodsExcept(['getAccessProfile'])
|
|
|
->getMock();
|
|
|
|
|
|
@@ -79,7 +83,7 @@ class AccessProfileCreatorTest extends TestCase
|
|
|
{
|
|
|
$accessProfileCreator = $this
|
|
|
->getMockBuilder(AccessProfileCreator::class)
|
|
|
- ->setConstructorArgs([$this->organizationProfileCreator, $this->accessRepository, $this->accessUtils])
|
|
|
+ ->setConstructorArgs([$this->organizationProfileCreator, $this->accessRepository, $this->accessUtils, $this->entityManager])
|
|
|
->setMethodsExcept(['getAccessProfile'])
|
|
|
->getMock();
|
|
|
|
|
|
@@ -92,6 +96,17 @@ class AccessProfileCreatorTest extends TestCase
|
|
|
->with($this->access)
|
|
|
->willReturn([$this->access, $otherAccess1, $otherAccess2]);
|
|
|
|
|
|
+ // Find valid accesses
|
|
|
+ $this->access
|
|
|
+ ->method('getPreferences')
|
|
|
+ ->willReturn(null);
|
|
|
+
|
|
|
+ // create the profile
|
|
|
+ $accessProfileCreator
|
|
|
+ ->expects(self::once())
|
|
|
+ ->method('createPreferences')
|
|
|
+ ->with($this->access);
|
|
|
+
|
|
|
// create the profile
|
|
|
$accessProfileCreator
|
|
|
->expects(self::once())
|
|
|
@@ -169,7 +184,7 @@ class AccessProfileCreatorTest extends TestCase
|
|
|
{
|
|
|
$accessProfileCreator = $this
|
|
|
->getMockBuilder(AccessProfileCreator::class)
|
|
|
- ->setConstructorArgs([$this->organizationProfileCreator, $this->accessRepository, $this->accessUtils])
|
|
|
+ ->setConstructorArgs([$this->organizationProfileCreator, $this->accessRepository, $this->accessUtils, $this->entityManager])
|
|
|
->setMethodsExcept(['getAccessProfile'])
|
|
|
->getMock();
|
|
|
|
|
|
@@ -215,7 +230,7 @@ class AccessProfileCreatorTest extends TestCase
|
|
|
{
|
|
|
$this->accessProfileCreator = $this
|
|
|
->getMockBuilder(AccessProfileCreator::class)
|
|
|
- ->setConstructorArgs([$this->organizationProfileCreator, $this->accessRepository, $this->accessUtils])
|
|
|
+ ->setConstructorArgs([$this->organizationProfileCreator, $this->accessRepository, $this->accessUtils, $this->entityManager])
|
|
|
->setMethodsExcept(['createCompleteAccessProfile'])
|
|
|
->getMock();
|
|
|
|
|
|
@@ -352,7 +367,7 @@ class AccessProfileCreatorTest extends TestCase
|
|
|
{
|
|
|
$accessProfileCreator = $this
|
|
|
->getMockBuilder(AccessProfileCreator::class)
|
|
|
- ->setConstructorArgs([$this->organizationProfileCreator, $this->accessRepository, $this->accessUtils])
|
|
|
+ ->setConstructorArgs([$this->organizationProfileCreator, $this->accessRepository, $this->accessUtils, $this->entityManager])
|
|
|
->setMethodsExcept(['createLightAccessProfile'])
|
|
|
->getMock();
|
|
|
|
|
|
@@ -365,9 +380,13 @@ class AccessProfileCreatorTest extends TestCase
|
|
|
$person->expects(self::once())->method('getGender')->willReturn(GenderEnum::MISTER);
|
|
|
$person->expects(self::once())->method('getImage')->willReturn($image);
|
|
|
|
|
|
+ $preferences = $this->getMockBuilder(Preferences::class)->getMock();
|
|
|
+ $preferences->expects(self::once())->method('getId')->willReturn(1);
|
|
|
+
|
|
|
$this->access->expects(self::once())->method('getId')->willReturn(1);
|
|
|
$this->access->method('getOrganization')->willReturn($this->organization);
|
|
|
$this->access->method('getPerson')->willReturn($person);
|
|
|
+ $this->access->expects(self::once())->method('getPreferences')->willReturn($preferences);
|
|
|
$this->access->expects(self::once())->method('getActivityYear')->willReturn(2020);
|
|
|
$this->access->expects(self::once())->method('getSuperAdminAccess')->willReturn(false);
|
|
|
|
|
|
@@ -387,5 +406,23 @@ class AccessProfileCreatorTest extends TestCase
|
|
|
$this->assertEquals(123, $accessProfile->getAvatarId());
|
|
|
$this->assertFalse($accessProfile->getIsSuperAdminAccess());
|
|
|
$this->assertEquals($this->organizationProfile, $accessProfile->getOrganization());
|
|
|
+ $this->assertEquals(1, $accessProfile->getPreferencesId());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @see AccessProfileCreator::createPreferences()
|
|
|
+ */
|
|
|
+ public function testCreatePreferences(): void
|
|
|
+ {
|
|
|
+ $accessProfileCreator = $this
|
|
|
+ ->getMockBuilder(AccessProfileCreator::class)
|
|
|
+ ->setConstructorArgs([$this->organizationProfileCreator, $this->accessRepository, $this->accessUtils, $this->entityManager])
|
|
|
+ ->setMethodsExcept(['createPreferences'])
|
|
|
+ ->getMock();
|
|
|
+
|
|
|
+ $this->access->expects(self::once())->method('setPreferences');
|
|
|
+ $this->entityManager->expects(self::once())->method('flush')->with($this->access);
|
|
|
+
|
|
|
+ $accessProfileCreator->createPreferences($this->access);
|
|
|
}
|
|
|
}
|