2828
2929namespace OCA \DAV \Tests \unit \CalDAV \Schedule ;
3030
31- use OC \Mail \Mailer ;
3231use OCA \DAV \CalDAV \Schedule \IMipPlugin ;
3332use OCP \AppFramework \Utility \ITimeFactory ;
3433use OCP \DB \QueryBuilder \IQueryBuilder ;
4645use OCP \Mail \IMailer ;
4746use OCP \Mail \IMessage ;
4847use OCP \Security \ISecureRandom ;
48+ use PHPUnit \Framework \MockObject \MockObject ;
4949use Sabre \VObject \Component \VCalendar ;
5050use Sabre \VObject \ITip \Message ;
5151use Test \TestCase ;
5252
5353class IMipPluginTest extends TestCase {
5454
55+ /** @var IMessage|MockObject */
56+ private $ mailMessage ;
57+
58+ /** @var IMailer|MockObject */
59+ private $ mailer ;
60+
61+ /** @var IEMailTemplate|MockObject */
62+ private $ emailTemplate ;
63+
64+ /** @var IAttachment|MockObject */
65+ private $ emailAttachment ;
66+
67+ /** @var ITimeFactory|MockObject */
68+ private $ timeFactory ;
69+
70+ /** @var IConfig|MockObject */
71+ private $ config ;
72+
73+ /** @var IUserManager|MockObject */
74+ private $ userManager ;
75+
76+ /** @var IQueryBuilder|MockObject */
77+ private $ queryBuilder ;
78+
79+ /** @var IMipPlugin */
80+ private $ plugin ;
81+
5582 protected function setUp (): void {
5683 $ this ->mailMessage = $ this ->createMock (IMessage::class);
5784 $ this ->mailMessage ->method ('setFrom ' )->willReturn ($ this ->mailMessage );
@@ -67,6 +94,7 @@ protected function setUp(): void {
6794 $ this ->emailAttachment = $ this ->createMock (IAttachment::class);
6895 $ this ->mailer ->method ('createAttachment ' )->willReturn ($ this ->emailAttachment );
6996
97+ /** @var ILogger|MockObject $logger */
7098 $ logger = $ this ->getMockBuilder (ILogger::class)->disableOriginalConstructor ()->getMock ();
7199
72100 $ this ->timeFactory = $ this ->getMockBuilder (ITimeFactory::class)->disableOriginalConstructor ()->getMock ();
@@ -156,7 +184,7 @@ public function testDeliveryWithNoCommonName() {
156184 /**
157185 * @dataProvider dataNoMessageSendForPastEvents
158186 */
159- public function testNoMessageSendForPastEvents ($ veventParams , $ expectsMail ) {
187+ public function testNoMessageSendForPastEvents (array $ veventParams , bool $ expectsMail ) {
160188
161189 $ this ->config
162190 ->method ('getAppValue ' )
@@ -194,7 +222,7 @@ public function dataNoMessageSendForPastEvents() {
194222 /**
195223 * @dataProvider dataIncludeResponseButtons
196224 */
197- public function testIncludeResponseButtons ( $ config_setting , $ recipient , $ has_buttons ) {
225+ public function testIncludeResponseButtons (string $ config_setting , string $ recipient , bool $ has_buttons ) {
198226 $ message = $ this ->_testMessage ([],$ recipient );
199227
200228 $ this ->_expectSend ($ recipient , true , $ has_buttons );
@@ -220,7 +248,22 @@ public function dataIncludeResponseButtons() {
220248 ];
221249 }
222250
223- private function _testMessage (
$ attrs = [],
$ recipient =
'[email protected] ' ) {
251+ public function testMessageSendWhenEventWithoutName () {
252+ $ this ->config
253+ ->method ('getAppValue ' )
254+ ->with ('dav ' , 'invitation_link_recipients ' , 'yes ' )
255+ ->willReturn ('yes ' );
256+
257+ $ message = $ this ->_testMessage (['SUMMARY ' => '' ]);
258+ $ this ->
_expectSend (
'[email protected] ' ,
true ,
true ,
'Invitation: Event without name ' );
259+ $ this ->emailTemplate ->expects ($ this ->once ())
260+ ->method ('addHeading ' )
261+ ->with ('Mr. Wizard invited you to »Event without name« ' );
262+ $ this ->plugin ->schedule ($ message );
263+ $ this ->assertEquals ('1.1 ' , $ message ->getScheduleStatus ());
264+ }
265+
266+ private function _testMessage (
array $ attrs = [],
string $ recipient =
'[email protected] ' ) {
224267 $ message = new Message ();
225268 $ message ->method = 'REQUEST ' ;
226269 $ message ->message = new VCalendar ();
@@ -239,7 +282,7 @@ private function _testMessage($attrs = [], $recipient = '
[email protected] ' ) {
239282 }
240283
241284
242- private function _expectSend (
$ recipient =
'[email protected] ' ,
$ expectSend =
true ,
$ expectButtons =
true ) {
285+ private function _expectSend (
string $ recipient =
'[email protected] ' ,
bool $ expectSend =
true ,
bool $ expectButtons =
true , string $ subject = ' Invitation: Fellowship meeting ' ) {
243286
244287 // if the event is in the past, we skip out
245288 if (!$ expectSend ) {
@@ -251,7 +294,7 @@ private function _expectSend( $recipient = '
[email protected] ', $expectSend = true,
251294
252295 $ this ->emailTemplate ->expects ($ this ->once ())
253296 ->method ('setSubject ' )
254- ->with (' Invitation: Fellowship meeting ' );
297+ ->with ($ subject );
255298 $ this ->mailMessage ->expects ($ this ->once ())
256299 ->method ('setTo ' )
257300 ->with ([$ recipient => null ]);
0 commit comments