public function testEmailSuccessful() { /** * FIXME: Disable test for systems where no sendmail is available since code is static. * @link https://github.com/owncloud/core/pull/12085 */ if (is_null(\OC_Helper::findBinaryPath('sendmail'))) { $this->markTestSkipped('sendmail is not available'); } $randomToken = $this->container['SecureRandom']; $this->container['SecureRandom']->expects($this->once())->method('generate')->with('21')->will($this->returnValue('ThisIsMaybeANotSoSecretToken!')); $this->container['UserManager']->expects($this->once())->method('userExists')->with('ExistingUser')->will($this->returnValue(true)); $this->container['Config']->expects($this->once())->method('getUserValue')->with('ExistingUser', 'settings', 'email')->will($this->returnValue('*****@*****.**')); $this->container['SecureRandom']->expects($this->once())->method('getMediumStrengthGenerator')->will($this->returnValue($randomToken)); $this->container['Config']->expects($this->once())->method('setUserValue')->with('ExistingUser', 'owncloud', 'lostpassword', 'ThisIsMaybeANotSoSecretToken!'); $this->container['URLGenerator']->expects($this->once())->method('linkToRouteAbsolute')->with('core.lost.resetform', array('userId' => 'ExistingUser', 'token' => 'ThisIsMaybeANotSoSecretToken!'))->will($this->returnValue('https://ownCloud.com/index.php/lostpassword/')); $response = $this->lostController->email('ExistingUser'); $expectedResponse = array('status' => 'success'); $this->assertSame($expectedResponse, $response); }
public function testEmailCantSendException() { $this->secureRandom->expects($this->once())->method('generate')->with('21')->will($this->returnValue('ThisIsMaybeANotSoSecretToken!')); $this->userManager->expects($this->once())->method('userExists')->with('ExistingUser')->will($this->returnValue(true)); $this->userManager->expects($this->any())->method('get')->with('ExistingUser')->willReturn($this->existingUser); $this->config->expects($this->once())->method('setUserValue')->with('ExistingUser', 'owncloud', 'lostpassword', '12348:ThisIsMaybeANotSoSecretToken!'); $this->timeFactory->expects($this->once())->method('getTime')->will($this->returnValue(12348)); $this->urlGenerator->expects($this->once())->method('linkToRouteAbsolute')->with('core.lost.resetform', array('userId' => 'ExistingUser', 'token' => 'ThisIsMaybeANotSoSecretToken!'))->will($this->returnValue('https://ownCloud.com/index.php/lostpassword/')); $message = $this->getMockBuilder('\\OC\\Mail\\Message')->disableOriginalConstructor()->getMock(); $message->expects($this->at(0))->method('setTo')->with(['*****@*****.**' => 'ExistingUser']); $message->expects($this->at(1))->method('setSubject')->with(' password reset'); $message->expects($this->at(2))->method('setPlainBody')->with('Use the following link to reset your password: https://ownCloud.com/index.php/lostpassword/'); $message->expects($this->at(3))->method('setFrom')->with(['lostpassword-noreply@localhost' => null]); $this->mailer->expects($this->at(0))->method('createMessage')->will($this->returnValue($message)); $this->mailer->expects($this->at(1))->method('send')->with($message)->will($this->throwException(new \Exception())); $response = $this->lostController->email('ExistingUser'); $expectedResponse = ['status' => 'error', 'msg' => 'Couldn\'t send reset email. Please contact your administrator.']; $this->assertSame($expectedResponse, $response); }