Repository navigation
feat(mail): use the new email template blocks for guest invitations #1720
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3fd6a4f
fix: embed inline logo in guest invitation emails
klaussalminenq5 0aa348f
Update Mail.php
klaussalminenq5 bbdc35d
fix(mail): set the guest invitation subject on the template
skjnldsv 772f1fd
feat(mail): use the new email template blocks for guest invitations
skjnldsv 78bcdd3
chore(psalm): raise PHP version to 8.3 for Nextcloud 36
skjnldsv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\Guests\Test\Unit; | ||
|
|
||
| use OCA\Guests\Mail; | ||
| use OCP\Defaults; | ||
| use OCP\IURLGenerator; | ||
| use OCP\IUser; | ||
| use OCP\IUserManager; | ||
| use OCP\IUserSession; | ||
| use OCP\L10N\IFactory; | ||
| use OCP\Mail\IEMailTemplate; | ||
| use OCP\Mail\IMailer; | ||
| use OCP\Mail\IMessage; | ||
| use OCP\Server; | ||
| use OCP\Share\IShare; | ||
| use PHPUnit\Framework\MockObject\MockObject; | ||
| use Test\TestCase; | ||
|
|
||
| class MailTest extends TestCase { | ||
| private IMailer&MockObject $mailer; | ||
| private IUserManager&MockObject $userManager; | ||
| private ?IEMailTemplate $sentTemplate = null; | ||
| private Mail $mail; | ||
|
|
||
| protected function setUp(): void { | ||
| parent::setUp(); | ||
|
|
||
| $this->mailer = $this->createMock(IMailer::class); | ||
| $this->mailer->method('createEMailTemplate') | ||
| ->willReturnCallback(fn (string $emailId) => Server::get(IMailer::class)->createEMailTemplate($emailId)); | ||
| $message = $this->createMock(IMessage::class); | ||
| $message->method('useTemplate') | ||
| ->willReturnCallback(function (IEMailTemplate $template) use ($message) { | ||
| $this->sentTemplate = $template; | ||
| return $message; | ||
| }); | ||
| $this->mailer->method('createMessage')->willReturn($message); | ||
|
|
||
| $sender = $this->createMock(IUser::class); | ||
| $sender->method('getDisplayName')->willReturn('Alice Martin'); | ||
| $sender->method('getEMailAddress')->willReturn('alice@example.com'); | ||
| $guest = $this->createMock(IUser::class); | ||
| $guest->method('getDisplayName')->willReturn('Jordan'); | ||
| $guest->method('getEMailAddress')->willReturn('jordan@partner.example'); | ||
|
|
||
| $this->userManager = $this->createMock(IUserManager::class); | ||
| $this->userManager->method('get')->willReturnMap([ | ||
| ['alice', $sender], | ||
| ['jordan@partner.example', $guest], | ||
| ]); | ||
| $userSession = $this->createMock(IUserSession::class); | ||
| $userSession->method('getUser')->willReturn($sender); | ||
|
|
||
| $defaults = $this->createMock(Defaults::class); | ||
| $defaults->method('getName')->willReturn('Nextcloud'); | ||
|
|
||
| $urlGenerator = $this->createMock(IURLGenerator::class); | ||
| $urlGenerator->method('linkToRouteAbsolute')->willReturnMap([ | ||
| ['core.lost.resetform', ['userId' => 'jordan@partner.example', 'token' => 'token'], 'https://cloud.example.com/reset'], | ||
| ['files.viewcontroller.showFile', ['fileid' => 42, 'direct' => 1], 'https://cloud.example.com/f/42'], | ||
| ]); | ||
|
|
||
| $this->mail = new Mail( | ||
| $userSession, | ||
| $this->mailer, | ||
| $defaults, | ||
| Server::get(IFactory::class), | ||
| $this->userManager, | ||
| $urlGenerator, | ||
| ); | ||
| } | ||
|
|
||
| private function createShare(string $note, ?\DateTime $expiration): IShare&MockObject { | ||
| $share = $this->createMock(IShare::class); | ||
| $share->method('getTarget')->willReturn('/Budget.xlsx'); | ||
| $share->method('getNodeId')->willReturn(42); | ||
| $share->method('getNote')->willReturn($note); | ||
| $share->method('getExpirationDate')->willReturn($expiration); | ||
| return $share; | ||
| } | ||
|
|
||
| public function testShareMail(): void { | ||
| $share = $this->createShare("Can you check\nthe travel line?", new \DateTime('2026-11-15')); | ||
| $this->mail->sendGuestInviteMail('alice', 'jordan@partner.example', 'token', 'en', $share); | ||
|
|
||
| $this->assertSame('Alice Martin shared Budget.xlsx with you', $this->sentTemplate->renderSubject()); | ||
| $text = $this->sentTemplate->renderText(); | ||
| $this->assertStringContainsString('Alice Martin (alice@example.com)', $text); | ||
| $this->assertStringContainsString("> Can you check\n> the travel line?", $text); | ||
| $this->assertStringContainsString('Valid until: Nov 15, 2026', $text); | ||
| $this->assertStringContainsString('Your login: jordan@partner.example', $text); | ||
| $this->assertStringContainsString('Activate account: https://cloud.example.com/reset', $text); | ||
| $this->assertStringContainsString('View share: https://cloud.example.com/f/42', $text); | ||
| } | ||
|
|
||
| public function testShareMailWithoutNoteAndExpiration(): void { | ||
| $share = $this->createShare('', null); | ||
| $this->mail->sendGuestInviteMail('alice', 'jordan@partner.example', 'token', 'en', $share); | ||
|
|
||
| $text = $this->sentTemplate->renderText(); | ||
| $this->assertStringNotContainsString('Note', $text); | ||
| $this->assertStringNotContainsString('Valid until', $text); | ||
| $this->assertStringContainsString('Your login: jordan@partner.example', $text); | ||
| } | ||
|
|
||
| public function testInviteMail(): void { | ||
| $this->mail->sendGuestInviteMail('alice', 'jordan@partner.example', 'token', 'en'); | ||
|
|
||
| $this->assertSame('Alice Martin invited you as a guest', $this->sentTemplate->renderSubject()); | ||
| $text = $this->sentTemplate->renderText(); | ||
| $this->assertStringContainsString('Alice Martin (alice@example.com)', $text); | ||
| $this->assertStringContainsString('Your login: jordan@partner.example', $text); | ||
| $this->assertStringContainsString('Activate account: https://cloud.example.com/reset', $text); | ||
| $this->assertStringNotContainsString('View share', $text); | ||
| } | ||
|
|
||
| public function testRightToLeftLanguage(): void { | ||
| $this->mail->sendGuestInviteMail('alice', 'jordan@partner.example', 'token', 'ar'); | ||
|
|
||
| $this->assertStringContainsString('lang="ar" xml:lang="ar" dir="rtl"', $this->sentTemplate->renderHtml()); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should branch off before merging this