/** * @test * @return void */ public function checkRegistrationSuccessSucceedsWhenAllConditionsMet() { $registration = $this->getMock('DERHANSEN\\SfEventMgt\\Domain\\Model\\Registration', [], [], '', false); $registrations = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage', [], [], '', false); $registrations->expects($this->any())->method('count')->will($this->returnValue(9)); $event = $this->getMock('DERHANSEN\\SfEventMgt\\Domain\\Model\\Event', [], [], '', false); $startdate = new \DateTime(); $startdate->add(\DateInterval::createFromDateString('tomorrow')); $event->expects($this->once())->method('getEnableRegistration')->will($this->returnValue(true)); $event->expects($this->once())->method('getStartdate')->will($this->returnValue($startdate)); $event->expects($this->any())->method('getRegistration')->will($this->returnValue($registrations)); $event->expects($this->any())->method('getMaxParticipants')->will($this->returnValue(10)); $success = $this->subject->checkRegistrationSuccess($event, $registration, $result); $this->assertTrue($success); $this->assertEquals($result, RegistrationResult::REGISTRATION_SUCCESSFUL); }
/** * Saves the registration * * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event * @validate $registration \DERHANSEN\SfEventMgt\Validation\Validator\RegistrationValidator * * @return void */ public function saveRegistrationAction(Registration $registration, Event $event) { $autoConfirmation = (bool) $this->settings['registration']['autoConfirmation']; $result = RegistrationResult::REGISTRATION_SUCCESSFUL; $success = $this->registrationService->checkRegistrationSuccess($event, $registration, $result); // Save registration if no errors if ($success) { $isWaitlistRegistration = $this->registrationService->isWaitlistRegistration($event, $registration->getAmountOfRegistrations()); $linkValidity = (int) $this->settings['confirmation']['linkValidity']; if ($linkValidity === 0) { // Use 3600 seconds as default value if not set $linkValidity = 3600; } $confirmationUntil = new \DateTime(); $confirmationUntil->add(new \DateInterval('PT' . $linkValidity . 'S')); $registration->setEvent($event); $registration->setPid($event->getPid()); $registration->setConfirmationUntil($confirmationUntil); $registration->setLanguage($GLOBALS['TSFE']->config['config']['language']); $registration->setFeUser($this->registrationService->getCurrentFeUserObject()); $registration->setWaitlist($isWaitlistRegistration); $registration->_setProperty('_languageUid', $GLOBALS['TSFE']->sys_language_uid); $this->registrationRepository->add($registration); // Persist registration, so we have an UID $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager')->persistAll(); // Add new registration (or waitlist registration) to event if ($isWaitlistRegistration) { $event->addRegistrationWaitlist($registration); $messageType = MessageType::REGISTRATION_WAITLIST_NEW; } else { $event->addRegistration($registration); $messageType = MessageType::REGISTRATION_NEW; } $this->eventRepository->update($event); // Send notifications to user and admin if confirmation link should be sent if (!$autoConfirmation) { $this->notificationService->sendUserMessage($event, $registration, $this->settings, $messageType); $this->notificationService->sendAdminMessage($event, $registration, $this->settings, $messageType); } // Create given amount of registrations if necessary if ($registration->getAmountOfRegistrations() > 1) { $this->registrationService->createDependingRegistrations($registration); } // Clear cache for configured pages $this->utilityService->clearCacheForConfiguredUids($this->settings); } if ($autoConfirmation && $success) { $this->redirect('confirmRegistration', null, null, ['reguid' => $registration->getUid(), 'hmac' => $this->hashService->generateHmac('reg-' . $registration->getUid())]); } else { $this->redirect('saveRegistrationResult', null, null, ['result' => $result]); } }