Skip to content

Commit

Permalink
Add default titles for titleless events in invitations
Browse files Browse the repository at this point in the history
Closes #19662

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
  • Loading branch information
tcitworld committed Apr 3, 2020
1 parent 054df03 commit 058ffa3
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 6 deletions.
5 changes: 4 additions & 1 deletion apps/dav/lib/CalDAV/Schedule/IMipPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
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;
Expand Down Expand Up @@ -246,7 +247,7 @@ public function schedule(Message $iTipMessage) {
'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()
Expand All @@ -257,6 +258,8 @@ public function schedule(Message $iTipMessage) {
$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,
Expand Down
54 changes: 49 additions & 5 deletions apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,40 @@
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);
Expand All @@ -67,6 +95,7 @@ protected function setUp(): void {
$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();
Expand Down Expand Up @@ -156,7 +185,7 @@ public function testDeliveryWithNoCommonName() {
/**
* @dataProvider dataNoMessageSendForPastEvents
*/
public function testNoMessageSendForPastEvents($veventParams, $expectsMail) {
public function testNoMessageSendForPastEvents(array $veventParams, bool $expectsMail) {

$this->config
->method('getAppValue')
Expand Down Expand Up @@ -194,7 +223,7 @@ public function dataNoMessageSendForPastEvents() {
/**
* @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);
Expand All @@ -220,7 +249,22 @@ public function dataIncludeResponseButtons() {
];
}

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();
Expand All @@ -239,7 +283,7 @@ private function _testMessage($attrs = [], $recipient = 'frodo@hobb.it' ) {
}


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) {
Expand All @@ -251,7 +295,7 @@ private function _expectSend( $recipient = 'frodo@hobb.it', $expectSend = true,

$this->emailTemplate->expects($this->once())
->method('setSubject')
->with('Invitation: Fellowship meeting');
->with($subject);
$this->mailMessage->expects($this->once())
->method('setTo')
->with([$recipient => null]);
Expand Down

0 comments on commit 058ffa3

Please sign in to comment.