4646use OCP \Mail \IMailer ;
4747use OCP \Mail \IMessage ;
4848use OCP \Security \ISecureRandom ;
49+ use PHPUnit \Framework \MockObject \MockObject ;
4950use Sabre \VObject \Component \VCalendar ;
5051use Sabre \VObject \ITip \Message ;
5152use Test \TestCase ;
5253
5354class IMipPluginTest extends TestCase {
5455
56+ /** @var IMessage|MockObject */
57+ private $ mailMessage ;
58+
59+ /** @var IMailer|MockObject */
60+ private $ mailer ;
61+
62+ /** @var IEMailTemplate|MockObject */
63+ private $ emailTemplate ;
64+
65+ /** @var IAttachment|MockObject */
66+ private $ emailAttachment ;
67+
68+ /** @var ITimeFactory|MockObject */
69+ private $ timeFactory ;
70+
71+ /** @var IConfig|MockObject */
72+ private $ config ;
73+
74+ /** @var IUserManager|MockObject */
75+ private $ userManager ;
76+
77+ /** @var IQueryBuilder|MockObject */
78+ private $ queryBuilder ;
79+
80+ /** @var IMipPlugin */
81+ private $ plugin ;
82+
5583 protected function setUp (): void {
5684 $ this ->mailMessage = $ this ->createMock (IMessage::class);
5785 $ this ->mailMessage ->method ('setFrom ' )->willReturn ($ this ->mailMessage );
@@ -67,6 +95,7 @@ protected function setUp(): void {
6795 $ this ->emailAttachment = $ this ->createMock (IAttachment::class);
6896 $ this ->mailer ->method ('createAttachment ' )->willReturn ($ this ->emailAttachment );
6997
98+ /** @var ILogger|MockObject $logger */
7099 $ logger = $ this ->getMockBuilder (ILogger::class)->disableOriginalConstructor ()->getMock ();
71100
72101 $ this ->timeFactory = $ this ->getMockBuilder (ITimeFactory::class)->disableOriginalConstructor ()->getMock ();
@@ -156,7 +185,7 @@ public function testDeliveryWithNoCommonName() {
156185 /**
157186 * @dataProvider dataNoMessageSendForPastEvents
158187 */
159- public function testNoMessageSendForPastEvents ($ veventParams , $ expectsMail ) {
188+ public function testNoMessageSendForPastEvents (array $ veventParams , bool $ expectsMail ) {
160189
161190 $ this ->config
162191 ->method ('getAppValue ' )
@@ -194,7 +223,7 @@ public function dataNoMessageSendForPastEvents() {
194223 /**
195224 * @dataProvider dataIncludeResponseButtons
196225 */
197- public function testIncludeResponseButtons ( $ config_setting , $ recipient , $ has_buttons ) {
226+ public function testIncludeResponseButtons (string $ config_setting , string $ recipient , bool $ has_buttons ) {
198227 $ message = $ this ->_testMessage ([],$ recipient );
199228
200229 $ this ->_expectSend ($ recipient , true , $ has_buttons );
@@ -220,7 +249,22 @@ public function dataIncludeResponseButtons() {
220249 ];
221250 }
222251
223- private function _testMessage (
$ attrs = [],
$ recipient =
'[email protected] ' ) {
252+ public function testMessageSendWhenEventWithoutName () {
253+ $ this ->config
254+ ->method ('getAppValue ' )
255+ ->with ('dav ' , 'invitation_link_recipients ' , 'yes ' )
256+ ->willReturn ('yes ' );
257+
258+ $ message = $ this ->_testMessage (['SUMMARY ' => '' ]);
259+ $ this ->
_expectSend (
'[email protected] ' ,
true ,
true ,
'Invitation: Untitled event ' );
260+ $ this ->emailTemplate ->expects ($ this ->once ())
261+ ->method ('addHeading ' )
262+ ->with ('Mr. Wizard invited you to »Untitled event« ' );
263+ $ this ->plugin ->schedule ($ message );
264+ $ this ->assertEquals ('1.1 ' , $ message ->getScheduleStatus ());
265+ }
266+
267+ private function _testMessage (
array $ attrs = [],
string $ recipient =
'[email protected] ' ) {
224268 $ message = new Message ();
225269 $ message ->method = 'REQUEST ' ;
226270 $ message ->message = new VCalendar ();
@@ -239,7 +283,7 @@ private function _testMessage($attrs = [], $recipient = '
[email protected] ' ) {
239283 }
240284
241285
242- private function _expectSend (
$ recipient =
'[email protected] ' ,
$ expectSend =
true ,
$ expectButtons =
true ) {
286+ private function _expectSend (
string $ recipient =
'[email protected] ' ,
bool $ expectSend =
true ,
bool $ expectButtons =
true , string $ subject = ' Invitation: Fellowship meeting ' ) {
243287
244288 // if the event is in the past, we skip out
245289 if (!$ expectSend ) {
@@ -251,7 +295,7 @@ private function _expectSend( $recipient = '
[email protected] ', $expectSend = true,
251295
252296 $ this ->emailTemplate ->expects ($ this ->once ())
253297 ->method ('setSubject ' )
254- ->with (' Invitation: Fellowship meeting ' );
298+ ->with ($ subject );
255299 $ this ->mailMessage ->expects ($ this ->once ())
256300 ->method ('setTo ' )
257301 ->with ([$ recipient => null ]);
0 commit comments