|
|
@@ -1398,6 +1398,11 @@ class OrganizationFactoryTest extends TestCase
|
|
|
$organizationMemberCreationRequest->method('getGivenName')->willReturn('bOBBy');
|
|
|
$organizationMemberCreationRequest->method('getGender')->willReturn(GenderEnum::MISTER);
|
|
|
|
|
|
+ $this->personRepository
|
|
|
+ ->method('findOneBy')
|
|
|
+ ->with(['username' => 'bob'], null)
|
|
|
+ ->willReturn(null);
|
|
|
+
|
|
|
$personAddressPostal = $this->getMockBuilder(PersonAddressPostal::class)->getMock();
|
|
|
$organizationFactory
|
|
|
->expects(self::once())
|
|
|
@@ -1440,6 +1445,37 @@ class OrganizationFactoryTest extends TestCase
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ public function testMakeAccessNewPersonUsernameAlreadyInUse(): void
|
|
|
+ {
|
|
|
+ $organizationFactory = $this->getOrganizationFactoryMockFor('makeAccess');
|
|
|
+
|
|
|
+ $organizationMemberCreationRequest = $this->getMockBuilder(OrganizationMemberCreationRequest::class)->getMock();
|
|
|
+
|
|
|
+ $organizationMemberCreationRequest->method('getUsername')->willReturn('bob');
|
|
|
+ $organizationMemberCreationRequest->method('getName')->willReturn('Bob');
|
|
|
+ $organizationMemberCreationRequest->method('getGivenName')->willReturn('bOBBy');
|
|
|
+ $organizationMemberCreationRequest->method('getGender')->willReturn(GenderEnum::MISTER);
|
|
|
+
|
|
|
+ $person = $this->getMockBuilder(Person::class)->getMock();
|
|
|
+ $this->personRepository
|
|
|
+ ->method('findOneBy')
|
|
|
+ ->with(['username' => 'bob'], null)
|
|
|
+ ->willReturn($person);
|
|
|
+
|
|
|
+ $organizationFactory
|
|
|
+ ->expects(self::never())
|
|
|
+ ->method('makePersonPostalAddress');
|
|
|
+
|
|
|
+ $organizationFactory
|
|
|
+ ->expects(self::never())
|
|
|
+ ->method('makePersonContactPoint');
|
|
|
+
|
|
|
+ $this->expectException(\RuntimeException::class);
|
|
|
+ $this->expectExceptionMessage('Username already in use : bob');
|
|
|
+
|
|
|
+ $organizationFactory->makeAccess($organizationMemberCreationRequest);
|
|
|
+ }
|
|
|
+
|
|
|
public function testMakeAccessExistingPerson(): void
|
|
|
{
|
|
|
$organizationFactory = $this->getOrganizationFactoryMockFor('makeAccess');
|
|
|
@@ -1507,6 +1543,25 @@ class OrganizationFactoryTest extends TestCase
|
|
|
$organizationMemberCreationRequest->method('getEmail')->willReturn('email@domain.com');
|
|
|
$organizationMemberCreationRequest->method('getMobile')->willReturn('+33607080910');
|
|
|
|
|
|
+ $this->phoneNumberUtil
|
|
|
+ ->expects(self::exactly(2))
|
|
|
+ ->method('isPossibleNumber')
|
|
|
+ ->willReturnMap([
|
|
|
+ ['+33102030405', null, true],
|
|
|
+ ['+33607080910', null, true],
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $phoneNumber = $this->getMockBuilder(PhoneNumber::class)->getMock();
|
|
|
+ $mobilePhoneNumber = $this->getMockBuilder(PhoneNumber::class)->getMock();
|
|
|
+
|
|
|
+ $this->phoneNumberUtil
|
|
|
+ ->expects(self::exactly(2))
|
|
|
+ ->method('parse')
|
|
|
+ ->willReturnMap([
|
|
|
+ ['+33102030405', null, null, false, $phoneNumber],
|
|
|
+ ['+33607080910', null, null, false, $mobilePhoneNumber],
|
|
|
+ ]);
|
|
|
+
|
|
|
$contactPoint = $organizationFactory->makePersonContactPoint($organizationMemberCreationRequest);
|
|
|
|
|
|
$this->assertEquals(
|
|
|
@@ -1515,29 +1570,77 @@ class OrganizationFactoryTest extends TestCase
|
|
|
);
|
|
|
|
|
|
$this->assertEquals(
|
|
|
- '33',
|
|
|
- $contactPoint->getTelphone()->getCountryCode()
|
|
|
- );
|
|
|
- $this->assertEquals(
|
|
|
- '102030405',
|
|
|
- $contactPoint->getTelphone()->getNationalNumber()
|
|
|
+ 'email@domain.com',
|
|
|
+ $contactPoint->getEmail()
|
|
|
);
|
|
|
|
|
|
$this->assertEquals(
|
|
|
- '33',
|
|
|
- $contactPoint->getMobilPhone()->getCountryCode()
|
|
|
- );
|
|
|
- $this->assertEquals(
|
|
|
- '607080910',
|
|
|
- $contactPoint->getMobilPhone()->getNationalNumber()
|
|
|
+ $phoneNumber,
|
|
|
+ $contactPoint->getTelphone()
|
|
|
);
|
|
|
|
|
|
$this->assertEquals(
|
|
|
- 'email@domain.com',
|
|
|
- $contactPoint->getEmail()
|
|
|
+ $mobilePhoneNumber,
|
|
|
+ $contactPoint->getMobilPhone()
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ public function testMakeAccessContactPointInvalidPhone(): void
|
|
|
+ {
|
|
|
+ $organizationFactory = $this->getOrganizationFactoryMockFor('makePersonContactPoint');
|
|
|
+
|
|
|
+ $organizationMemberCreationRequest = $this->getMockBuilder(OrganizationMemberCreationRequest::class)->getMock();
|
|
|
+
|
|
|
+ $organizationMemberCreationRequest->method('getUsername')->willReturn('bob');
|
|
|
+ $organizationMemberCreationRequest->method('getPhone')->willReturn('invalid');
|
|
|
+ $organizationMemberCreationRequest->method('getEmail')->willReturn('email@domain.com');
|
|
|
+ $organizationMemberCreationRequest->method('getMobile')->willReturn('+33607080910');
|
|
|
+
|
|
|
+ $this->phoneNumberUtil
|
|
|
+ ->expects(self::once())
|
|
|
+ ->method('isPossibleNumber')
|
|
|
+ ->with('invalid')
|
|
|
+ ->willReturn(false);
|
|
|
+
|
|
|
+ $this->phoneNumberUtil
|
|
|
+ ->expects(self::never())
|
|
|
+ ->method('parse');
|
|
|
+
|
|
|
+ $this->expectException(\RuntimeException::class);
|
|
|
+ $this->expectExceptionMessage('Phone number is invalid or missing (person: bob)');
|
|
|
+
|
|
|
+ $organizationFactory->makePersonContactPoint($organizationMemberCreationRequest);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testMakeAccessContactPointInvalidMobilePhone(): void
|
|
|
+ {
|
|
|
+ $organizationFactory = $this->getOrganizationFactoryMockFor('makePersonContactPoint');
|
|
|
+
|
|
|
+ $organizationMemberCreationRequest = $this->getMockBuilder(OrganizationMemberCreationRequest::class)->getMock();
|
|
|
+
|
|
|
+ $organizationMemberCreationRequest->method('getUsername')->willReturn('bob');
|
|
|
+ $organizationMemberCreationRequest->method('getPhone')->willReturn('+33102030405');
|
|
|
+ $organizationMemberCreationRequest->method('getEmail')->willReturn('email@domain.com');
|
|
|
+ $organizationMemberCreationRequest->method('getMobile')->willReturn('invalid');
|
|
|
+
|
|
|
+ $this->phoneNumberUtil
|
|
|
+ ->expects(self::exactly(2))
|
|
|
+ ->method('isPossibleNumber')
|
|
|
+ ->willReturnMap([
|
|
|
+ ['+33102030405', null, true],
|
|
|
+ ['invalid', null, false],
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $this->phoneNumberUtil
|
|
|
+ ->expects(self::never())
|
|
|
+ ->method('parse');
|
|
|
+
|
|
|
+ $this->expectException(\RuntimeException::class);
|
|
|
+ $this->expectExceptionMessage('Mobile phone number is invalid (person: bob)');
|
|
|
+
|
|
|
+ $organizationFactory->makePersonContactPoint($organizationMemberCreationRequest);
|
|
|
+ }
|
|
|
+
|
|
|
public function testMakePersonContactPointNoMobile(): void
|
|
|
{
|
|
|
$organizationFactory = $this->getOrganizationFactoryMockFor('makePersonContactPoint');
|
|
|
@@ -1547,6 +1650,12 @@ class OrganizationFactoryTest extends TestCase
|
|
|
$organizationMemberCreationRequest->method('getPhone')->willReturn('+33102030405');
|
|
|
$organizationMemberCreationRequest->method('getMobile')->willReturn(null);
|
|
|
|
|
|
+ $this->phoneNumberUtil
|
|
|
+ ->expects(self::once())
|
|
|
+ ->method('isPossibleNumber')
|
|
|
+ ->with('+33102030405')
|
|
|
+ ->willReturn(true);
|
|
|
+
|
|
|
$contactPoint = $organizationFactory->makePersonContactPoint($organizationMemberCreationRequest);
|
|
|
|
|
|
$this->assertEquals(
|