|
|
@@ -185,6 +185,7 @@ class OrganizationFactoryTest extends TestCase
|
|
|
private readonly MockObject|ApiLegacyRequestService $apiLegacyRequestService;
|
|
|
private readonly MockObject|PhoneNumberUtil $phoneNumberUtil;
|
|
|
private readonly MockObject|FunctionTypeRepository $functionTypeRepository;
|
|
|
+ private readonly MockObject|\App\Repository\Access\AccessRepository $accessRepository;
|
|
|
|
|
|
public function setUp(): void
|
|
|
{
|
|
|
@@ -203,6 +204,7 @@ class OrganizationFactoryTest extends TestCase
|
|
|
$this->phoneNumberUtil = $this->getMockBuilder(PhoneNumberUtil::class)->disableOriginalConstructor()->getMock();
|
|
|
$this->functionTypeRepository = $this->getMockBuilder(FunctionTypeRepository::class)->disableOriginalConstructor()->getMock();
|
|
|
$this->fileManager = $this->getMockBuilder(FileManager::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $this->accessRepository = $this->getMockBuilder(\App\Repository\Access\AccessRepository::class)->disableOriginalConstructor()->getMock();
|
|
|
}
|
|
|
|
|
|
public function tearDown(): void
|
|
|
@@ -229,6 +231,7 @@ class OrganizationFactoryTest extends TestCase
|
|
|
$this->apiLegacyRequestService,
|
|
|
$this->functionTypeRepository,
|
|
|
$this->fileManager,
|
|
|
+ $this->accessRepository,
|
|
|
])
|
|
|
->setMethodsExcept(['setLoggerInterface', 'setPhoneNumberUtil', $methodName])
|
|
|
->getMock();
|
|
|
@@ -2190,4 +2193,67 @@ class OrganizationFactoryTest extends TestCase
|
|
|
|
|
|
$organizationFactory->switchDolibarrSocietyToProspect(123);
|
|
|
}
|
|
|
+
|
|
|
+ public function testSetAdminAccountPassword(): void
|
|
|
+ {
|
|
|
+ $organizationFactory = $this->getOrganizationFactoryMockFor('setAdminAccountPassword');
|
|
|
+
|
|
|
+ // Create mock organization
|
|
|
+ $organization = $this->getMockBuilder(Organization::class)->getMock();
|
|
|
+
|
|
|
+ // Create mock access with adminAccess=true
|
|
|
+ $access = $this->getMockBuilder(Access::class)->getMock();
|
|
|
+
|
|
|
+ // Create mock person
|
|
|
+ $person = $this->getMockBuilder(Person::class)->getMock();
|
|
|
+
|
|
|
+ // Set up the access to return the person
|
|
|
+ $access->method('getPerson')->willReturn($person);
|
|
|
+
|
|
|
+ // Set up the AccessRepository to return the access when findAdminAccess is called
|
|
|
+ $this->accessRepository->method('findAdminAccess')->with($organization)->willReturn($access);
|
|
|
+
|
|
|
+ // Expect the person's setPassword method to be called with the password
|
|
|
+ $person->expects(self::once())->method('setPassword')->with('Password123!');
|
|
|
+
|
|
|
+ // Expect the EntityManager's persist and flush methods to be called
|
|
|
+ $this->entityManager->expects(self::once())->method('persist')->with($person);
|
|
|
+ $this->entityManager->expects(self::once())->method('flush');
|
|
|
+
|
|
|
+ // Call the method with a valid password
|
|
|
+ $organizationFactory->setAdminAccountPassword($organization, 'Password123!');
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testSetAdminAccountPasswordInvalidPassword(): void
|
|
|
+ {
|
|
|
+ $organizationFactory = $this->getOrganizationFactoryMockFor('setAdminAccountPassword');
|
|
|
+
|
|
|
+ // Create mock organization
|
|
|
+ $organization = $this->getMockBuilder(Organization::class)->getMock();
|
|
|
+
|
|
|
+ // Expect an exception to be thrown for an invalid password
|
|
|
+ $this->expectException(\RuntimeException::class);
|
|
|
+ $this->expectExceptionMessage('Password must be at least 8 characters long and include at least one uppercase letter, one lowercase letter, one digit, and one special character.');
|
|
|
+
|
|
|
+ // Call the method with an invalid password
|
|
|
+ $organizationFactory->setAdminAccountPassword($organization, 'password');
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testSetAdminAccountPasswordNoAdminAccount(): void
|
|
|
+ {
|
|
|
+ $organizationFactory = $this->getOrganizationFactoryMockFor('setAdminAccountPassword');
|
|
|
+
|
|
|
+ // Create mock organization
|
|
|
+ $organization = $this->getMockBuilder(Organization::class)->getMock();
|
|
|
+
|
|
|
+ // Set up the AccessRepository to return null when findAdminAccess is called
|
|
|
+ $this->accessRepository->method('findAdminAccess')->with($organization)->willReturn(null);
|
|
|
+
|
|
|
+ // Expect an exception to be thrown when no admin account is found
|
|
|
+ $this->expectException(\RuntimeException::class);
|
|
|
+ $this->expectExceptionMessage('No admin account found for this organization.');
|
|
|
+
|
|
|
+ // Call the method with a valid password
|
|
|
+ $organizationFactory->setAdminAccountPassword($organization, 'Password123!');
|
|
|
+ }
|
|
|
}
|