/**
  * Tests if fromEventProperty returns expected attachments for objectStorage property
  * @test
  */
 public function getAttachmentsReturnsAttachmentsFromEventPropertyWithObjectStorage()
 {
     $registration = new \DERHANSEN\SfEventMgt\Domain\Model\Registration();
     $event = new \DERHANSEN\SfEventMgt\Domain\Model\Event();
     $mockFile1 = $this->getMock('TYPO3\\CMS\\Core\\Resource\\File', ['getForLocalProcessing'], [], '', false);
     $mockFile1->expects($this->any())->method('getForLocalProcessing')->will($this->returnValue('/path/to/somefile.pdf'));
     $mockFileRef1 = $this->getMock('TYPO3\\CMS\\Extbase\\Domain\\Model\\FileReference', ['getOriginalResource'], [], '', false);
     $mockFileRef1->expects($this->any())->method('getOriginalResource')->will($this->returnValue($mockFile1));
     $mockFile2 = $this->getMock('TYPO3\\CMS\\Core\\Resource\\File', ['getForLocalProcessing'], [], '', false);
     $mockFile2->expects($this->any())->method('getForLocalProcessing')->will($this->returnValue('/path/to/anotherfile.pdf'));
     $mockFileRef2 = $this->getMock('TYPO3\\CMS\\Extbase\\Domain\\Model\\FileReference', ['getOriginalResource'], [], '', false);
     $mockFileRef2->expects($this->any())->method('getOriginalResource')->will($this->returnValue($mockFile2));
     $event->addFiles($mockFileRef1);
     $event->addFiles($mockFileRef2);
     $registration->setEvent($event);
     $settings = ['notification' => ['registrationNew' => ['attachments' => ['user' => ['fromEventProperty' => ['files']]]]]];
     $expected = ['/path/to/somefile.pdf', '/path/to/anotherfile.pdf'];
     $attachments = $this->subject->getAttachments($settings, $registration, MessageType::REGISTRATION_NEW, MessageRecipient::USER);
     $this->assertEquals($expected, $attachments);
 }
 /**
  * Executes all validation tests defined by the given data provider
  * Not really testing, just mocking if everything is called as expected
  *
  * @test
  * @dataProvider settingsDataProvider
  */
 public function validatorReturnsExpectedResults($settings, $fields, $hasErrors, $expected)
 {
     $registration = new \DERHANSEN\SfEventMgt\Domain\Model\Registration();
     $registration->setFirstname('John');
     $registration->setLastname('Doe');
     $registration->setEmail('*****@*****.**');
     foreach ($fields as $key => $value) {
         $registration->_setProperty($key, $value);
     }
     // Inject configuration and configurationManager
     $configurationManager = $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager', ['getConfiguration'], [], '', false);
     $configurationManager->expects($this->once())->method('getConfiguration')->will($this->returnValue($settings));
     $this->inject($this->validator, 'configurationManager', $configurationManager);
     // Inject the object manager
     $validationError = $this->getMock('TYPO3\\CMS\\Extbase\\Error\\Error', [], [], '', false);
     $validationResult = $this->getMock('TYPO3\\CMS\\Extbase\\Error\\Result', [], [], '', false);
     $validationResult->expects($this->any())->method('hasErrors')->will($this->returnValue($hasErrors));
     $validationResult->expects($this->any())->method('getErrors')->will($this->returnValue([$validationError]));
     $notEmptyValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\NotEmptyValidator', [], [], '', false);
     $notEmptyValidator->expects($this->any())->method('validate')->will($this->returnValue($validationResult));
     $booleanValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\BooleanValidator', [], [], '', false);
     $booleanValidator->expects($this->any())->method('validate')->will($this->returnValue($validationResult));
     $recaptchaValidator = $this->getMock('DERHANSEN\\SfEventMgt\\Validation\\Validator\\RecaptchaValidator', [], [], '', false);
     $recaptchaValidator->expects($this->any())->method('validate')->will($this->returnValue($validationResult));
     // Create a map of arguments to return values
     $map = [['string', 'city', $notEmptyValidator], ['string', 'zip', $notEmptyValidator], ['string', 'recaptcha', $recaptchaValidator], ['boolean', 'accepttc', $booleanValidator]];
     $this->validator->expects($this->any())->method('getValidator')->will($this->returnValueMap($map));
     $this->assertEquals($expected, $this->validator->validate($registration)->hasErrors());
 }
 /**
  * Test that only confirmed registrations get notified. Also test, if the ignoreNotifications
  * flag is evaluated
  *
  * @test
  * @return void
  */
 public function sendCustomNotificationReturnsExpectedAmountOfNotificationsSent()
 {
     $event = new \DERHANSEN\SfEventMgt\Domain\Model\Event();
     $registration1 = new \DERHANSEN\SfEventMgt\Domain\Model\Registration();
     $registration1->setConfirmed(FALSE);
     $registration2 = new \DERHANSEN\SfEventMgt\Domain\Model\Registration();
     $registration2->setConfirmed(TRUE);
     $registration3 = new \DERHANSEN\SfEventMgt\Domain\Model\Registration();
     $registration3->setConfirmed(TRUE);
     $registration4 = new \DERHANSEN\SfEventMgt\Domain\Model\Registration();
     $registration4->setConfirmed(TRUE);
     $registration4->setIgnoreNotifications(TRUE);
     /** @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage $registrations */
     $registrations = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
     $registrations->attach($registration1);
     $registrations->attach($registration2);
     $registrations->attach($registration3);
     $registrations->attach($registration4);
     $mockNotificationService = $this->getMock('DERHANSEN\\SfEventMgt\\Service\\NotificationService', array('sendUserMessage'));
     $mockNotificationService->expects($this->any())->method('sendUserMessage')->will($this->returnValue(TRUE));
     $registrationRepository = $this->getMock('DERHANSEN\\SfEventMgt\\Domain\\Repository\\RegistrationRepository', array('findNotificationRegistrations'), array(), '', FALSE);
     $registrationRepository->expects($this->once())->method('findNotificationRegistrations')->will($this->returnValue($registrations));
     $this->inject($mockNotificationService, 'registrationRepository', $registrationRepository);
     $result = $mockNotificationService->sendCustomNotification($event, 'aTemplate', array('someSettings'));
     $this->assertEquals(2, $result);
 }