Skip to content

Commit

Permalink
[TASK] Add more functional tests for RegistrationService
Browse files Browse the repository at this point in the history
Closes #1276
  • Loading branch information
derhansen committed Oct 6, 2024
1 parent 2738596 commit 8030fa8
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Tests/Functional/Fixtures/check_registration_access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"tx_sfeventmgt_domain_model_registration"
,"uid","fe_user","notes"
,1,0,registration with no frontend user
,2,1,registration with frontend user uid 1
,3,2,registration with frontend user uid 2
"fe_users"
,"uid","username"
,1,"testuser1"
,2,"testuser2"
129 changes: 129 additions & 0 deletions Tests/Functional/Service/RegistrationServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -600,4 +600,133 @@ public function checkRegistrationSuccessReturnsTrueIfRegistrationSuccessful(): v
];
self::assertEquals($expected, $this->subject->checkRegistrationSuccess($event, $registration));
}

#[Test]
public function redirectPaymentEnabledReturnsFalseIfPaymentNotEnabledforEvent(): void
{
$event = new Event();
$registration = new Registration();
$registration->setEvent($event);

self::assertFalse($this->subject->redirectPaymentEnabled($registration));
}

#[Test]
public function isWaitlistRegistrationReturnsFalseIfWaitlistNotEnabled(): void
{
$event = new Event();
$event->setEnableWaitlist(false);

self::assertFalse($this->subject->isWaitlistRegistration($event, 1));
}

#[Test]
public function isWaitlistRegistrationReturnsTrueIfEventNotFullyBookedAndNotEnoughFreePlaces(): void
{
$event = new Event();
$event->setEnableWaitlist(true);
$event->setMaxParticipants(2);
$event->addRegistration(new Registration());

self::assertTrue($this->subject->isWaitlistRegistration($event, 2));
}

#[Test]
public function isWaitlistRegistrationReturnsTrueIfEventFullyBookedAndNotEnoughFreePlaces(): void
{
$event = new Event();
$event->setEnableWaitlist(true);
$event->setMaxParticipants(1);
$event->addRegistration(new Registration());

self::assertTrue($this->subject->isWaitlistRegistration($event, 1));
}

#[Test]
public function isWaitlistRegistrationReturnsFalseIfWaitlistEnabledButEnoughFreePlaces(): void
{
$event = new Event();
$event->setEnableWaitlist(true);
$event->setMaxParticipants(3);
$event->addRegistration(new Registration());

self::assertFalse($this->subject->isWaitlistRegistration($event, 2));
}

#[Test]
public function checkRegistrationAccessThrowsExceptionIfNoUserLoggedIn(): void
{
$this->importCSVDataSet(__DIR__ . '/../Fixtures/check_registration_access.csv');
$this->expectExceptionCode(1671627320);

/** @var Registration $existingRegistration */
$registration = $this->registrationRepository->findByUid(1);

$serverRequest = new ServerRequest();
$this->subject->checkRegistrationAccess($serverRequest, $registration);
}

#[Test]
public function checkRegistrationAccessThrowsExceptionIfRegistrationHasNoFeUser(): void
{
$this->importCSVDataSet(__DIR__ . '/../Fixtures/check_registration_access.csv');
$this->expectExceptionCode(1671627320);

$user = new FrontendUserAuthentication();
$user->user['uid'] = 1;

$this->get(Context::class)->setAspect(
'frontend.user',
GeneralUtility::makeInstance(UserAspect::class, $user)
);

/** @var Registration $existingRegistration */
$registration = $this->registrationRepository->findByUid(1);

$serverRequest = new ServerRequest();
$this->subject->checkRegistrationAccess($serverRequest, $registration);
}

#[Test]
public function checkRegistrationAccessThrowsExceptionIfFeUserNotEqualToRegistrationFeUser(): void
{
$this->importCSVDataSet(__DIR__ . '/../Fixtures/check_registration_access.csv');
$this->expectExceptionCode(1671627320);

$user = new FrontendUserAuthentication();
$user->user['uid'] = 1;

$this->get(Context::class)->setAspect(
'frontend.user',
GeneralUtility::makeInstance(UserAspect::class, $user)
);

/** @var Registration $existingRegistration */
$registration = $this->registrationRepository->findByUid(3);

$serverRequest = new ServerRequest();
$this->subject->checkRegistrationAccess($serverRequest, $registration);
}

#[Test]
public function checkRegistrationAccessThrowsNoExceptionIfFeUserEqualToRegistrationFeUser(): void
{
$this->importCSVDataSet(__DIR__ . '/../Fixtures/check_registration_access.csv');

$user = new FrontendUserAuthentication();
$user->user['uid'] = 1;

$this->get(Context::class)->setAspect(
'frontend.user',
GeneralUtility::makeInstance(UserAspect::class, $user)
);

/** @var Registration $existingRegistration */
$registration = $this->registrationRepository->findByUid(2);

$serverRequest = new ServerRequest();
$this->subject->checkRegistrationAccess($serverRequest, $registration);

self::assertTrue(true);
}
}

0 comments on commit 8030fa8

Please sign in to comment.