diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2020-04-07 11:22:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-07 11:22:17 +0200 |
commit | e266666380a4cc9d748dab895a1038f20fe07832 (patch) | |
tree | cfe184b91bdb1299f93ef2680047f09de84d1da3 | |
parent | 50ad706a33820610b2299376ad406a6be0acfc4b (diff) | |
parent | 058ffa37ff33f898497f92b1b8c6e528170a4215 (diff) | |
download | nextcloud-server-e266666380a4cc9d748dab895a1038f20fe07832.tar.gz nextcloud-server-e266666380a4cc9d748dab895a1038f20fe07832.zip |
Merge pull request #20188 from nextcloud/bug/19662/add-default-title-for-event-in-invitatios
Add default titles for titleless events in invitations
-rw-r--r-- | apps/dav/lib/CalDAV/Schedule/IMipPlugin.php | 5 | ||||
-rw-r--r-- | apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php | 54 |
2 files changed, 53 insertions, 6 deletions
diff --git a/apps/dav/lib/CalDAV/Schedule/IMipPlugin.php b/apps/dav/lib/CalDAV/Schedule/IMipPlugin.php index cb3bfb4f43d..5493eb693f9 100644 --- a/apps/dav/lib/CalDAV/Schedule/IMipPlugin.php +++ b/apps/dav/lib/CalDAV/Schedule/IMipPlugin.php @@ -43,6 +43,7 @@ use OCP\L10N\IFactory as L10NFactory; use OCP\Mail\IEMailTemplate; use OCP\Mail\IMailer; use OCP\Security\ISecureRandom; +use OCP\Util; use Sabre\CalDAV\Schedule\IMipPlugin as SabreIMipPlugin; use Sabre\VObject\Component\VCalendar; use Sabre\VObject\Component\VEvent; @@ -246,7 +247,7 @@ class IMipPlugin extends SabreIMipPlugin { 'meeting_url' => (string)$meetingUrl ?: $defaultVal, ]; - $fromEMail = \OCP\Util::getDefaultEmailAddress('invitations-noreply'); + $fromEMail = Util::getDefaultEmailAddress('invitations-noreply'); $fromName = $l10n->t('%1$s via %2$s', [$senderName, $this->defaults->getName()]); $message = $this->mailer->createMessage() @@ -257,6 +258,8 @@ class IMipPlugin extends SabreIMipPlugin { $template = $this->mailer->createEMailTemplate('dav.calendarInvite.' . $method, $data); $template->addHeader(); + $summary = ((string) $summary !== '') ? (string) $summary : $l10n->t('Untitled event'); + $this->addSubjectAndHeading($template, $l10n, $method, $summary, $meetingAttendeeName, $meetingInviteeName); $this->addBulletList($template, $l10n, $meetingWhen, $meetingLocation, diff --git a/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php b/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php index 226db0578c1..0f990cd8ca6 100644 --- a/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php +++ b/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php @@ -46,12 +46,40 @@ use OCP\Mail\IEMailTemplate; use OCP\Mail\IMailer; use OCP\Mail\IMessage; use OCP\Security\ISecureRandom; +use PHPUnit\Framework\MockObject\MockObject; use Sabre\VObject\Component\VCalendar; use Sabre\VObject\ITip\Message; use Test\TestCase; class IMipPluginTest extends TestCase { + /** @var IMessage|MockObject */ + private $mailMessage; + + /** @var IMailer|MockObject */ + private $mailer; + + /** @var IEMailTemplate|MockObject */ + private $emailTemplate; + + /** @var IAttachment|MockObject */ + private $emailAttachment; + + /** @var ITimeFactory|MockObject */ + private $timeFactory; + + /** @var IConfig|MockObject */ + private $config; + + /** @var IUserManager|MockObject */ + private $userManager; + + /** @var IQueryBuilder|MockObject */ + private $queryBuilder; + + /** @var IMipPlugin */ + private $plugin; + protected function setUp(): void { $this->mailMessage = $this->createMock(IMessage::class); $this->mailMessage->method('setFrom')->willReturn($this->mailMessage); @@ -67,6 +95,7 @@ class IMipPluginTest extends TestCase { $this->emailAttachment = $this->createMock(IAttachment::class); $this->mailer->method('createAttachment')->willReturn($this->emailAttachment); + /** @var ILogger|MockObject $logger */ $logger = $this->getMockBuilder(ILogger::class)->disableOriginalConstructor()->getMock(); $this->timeFactory = $this->getMockBuilder(ITimeFactory::class)->disableOriginalConstructor()->getMock(); @@ -156,7 +185,7 @@ class IMipPluginTest extends TestCase { /** * @dataProvider dataNoMessageSendForPastEvents */ - public function testNoMessageSendForPastEvents($veventParams, $expectsMail) { + public function testNoMessageSendForPastEvents(array $veventParams, bool $expectsMail) { $this->config ->method('getAppValue') @@ -194,7 +223,7 @@ class IMipPluginTest extends TestCase { /** * @dataProvider dataIncludeResponseButtons */ - public function testIncludeResponseButtons( $config_setting, $recipient, $has_buttons ) { + public function testIncludeResponseButtons(string $config_setting, string $recipient, bool $has_buttons ) { $message = $this->_testMessage([],$recipient); $this->_expectSend($recipient, true, $has_buttons); @@ -220,7 +249,22 @@ class IMipPluginTest extends TestCase { ]; } - private function _testMessage($attrs = [], $recipient = 'frodo@hobb.it' ) { + public function testMessageSendWhenEventWithoutName() { + $this->config + ->method('getAppValue') + ->with('dav', 'invitation_link_recipients', 'yes') + ->willReturn('yes'); + + $message = $this->_testMessage(['SUMMARY' => '']); + $this->_expectSend('frodo@hobb.it', true, true,'Invitation: Untitled event'); + $this->emailTemplate->expects($this->once()) + ->method('addHeading') + ->with('Mr. Wizard invited you to »Untitled event«'); + $this->plugin->schedule($message); + $this->assertEquals('1.1', $message->getScheduleStatus()); + } + + private function _testMessage(array $attrs = [], string $recipient = 'frodo@hobb.it' ) { $message = new Message(); $message->method = 'REQUEST'; $message->message = new VCalendar(); @@ -239,7 +283,7 @@ class IMipPluginTest extends TestCase { } - private function _expectSend( $recipient = 'frodo@hobb.it', $expectSend = true, $expectButtons = true ) { + private function _expectSend(string $recipient = 'frodo@hobb.it', bool $expectSend = true, bool $expectButtons = true, string $subject = 'Invitation: Fellowship meeting') { // if the event is in the past, we skip out if (!$expectSend) { @@ -251,7 +295,7 @@ class IMipPluginTest extends TestCase { $this->emailTemplate->expects($this->once()) ->method('setSubject') - ->with('Invitation: Fellowship meeting'); + ->with($subject); $this->mailMessage->expects($this->once()) ->method('setTo') ->with([$recipient => null]); |