public function testSendLinkShareMailException() { $message = $this->getMockBuilder('\\OC\\Mail\\Message')->disableOriginalConstructor()->getMock(); $message->expects($this->once())->method('setSubject')->with('TestUser shared »MyFile« with you'); $message->expects($this->once())->method('setTo')->with(['*****@*****.**']); $message->expects($this->once())->method('setHtmlBody'); $message->expects($this->once())->method('setPlainBody'); $message->expects($this->once())->method('setFrom')->with([\OCP\Util::getDefaultEmailAddress('sharing-noreply') => 'TestUser via UnitTestCloud']); $this->mailer->expects($this->once())->method('createMessage')->will($this->returnValue($message)); $this->mailer->expects($this->once())->method('send')->with($message)->will($this->throwException(new Exception('Some Exception Message'))); $this->defaults->expects($this->once())->method('getName')->will($this->returnValue('UnitTestCloud')); $this->config->expects($this->at(0))->method('getUserValue')->with('TestUser', 'settings', 'email', null)->will($this->returnValue('*****@*****.**')); $mailNotifications = new MailNotifications('TestUser', $this->config, $this->l10n, $this->mailer, $this->logger, $this->defaults); $this->assertSame(['*****@*****.**'], $mailNotifications->sendLinkShareMail('*****@*****.**', 'MyFile', 'https://owncloud.com/file/?foo=bar', 3600)); }
public function testSendEmailToUser() { $maxTime = 200; $user = '******'; $userDisplayName = 'user two'; $email = $user . '@localhost'; $this->mailer->expects($this->once())->method('send')->with($this->message); $this->message->expects($this->once())->method('setTo')->with([$email => $userDisplayName]); $this->message->expects($this->once())->method('setSubject'); $this->message->expects($this->once())->method('setPlainBody'); $this->message->expects($this->once())->method('setFrom'); $userObject = $this->getMock('OCP\\IUser'); $userObject->expects($this->any())->method('getDisplayName')->willReturn($userDisplayName); $this->userManager->expects($this->any())->method('get')->willReturnMap([[$user, $userObject], [$user . $user, null]]); $users = $this->mailQueueHandler->getAffectedUsers(1, $maxTime); $this->assertEquals([$user], $users); $this->mailQueueHandler->sendEmailToUser($user, $email, 'en', 'UTC', $maxTime); // Invalid user, no object no email $this->mailQueueHandler->sendEmailToUser($user . $user, $email, 'en', 'UTC', $maxTime); }