Merge pull request #20860 from owncloud/use-user-getEMailAddress-all-over-the-place
User IUser::getEMailAddress() all over the place
This commit is contained in:
commit
7fefd4f4d9
|
@ -31,6 +31,7 @@ use OCP\IL10N;
|
||||||
use OCP\IUserManager;
|
use OCP\IUserManager;
|
||||||
use OCP\Mail\IMailer;
|
use OCP\Mail\IMailer;
|
||||||
use OCP\Security\ISecureRandom;
|
use OCP\Security\ISecureRandom;
|
||||||
|
use OCP\Util;
|
||||||
use Symfony\Component\Console\Helper\ProgressBar;
|
use Symfony\Component\Console\Helper\ProgressBar;
|
||||||
use Symfony\Component\Console\Helper\QuestionHelper;
|
use Symfony\Component\Console\Helper\QuestionHelper;
|
||||||
use Symfony\Component\Console\Helper\Table;
|
use Symfony\Component\Console\Helper\Table;
|
||||||
|
@ -358,14 +359,15 @@ class EncryptAll {
|
||||||
$progress = new ProgressBar($this->output, count($this->userPasswords));
|
$progress = new ProgressBar($this->output, count($this->userPasswords));
|
||||||
$progress->start();
|
$progress->start();
|
||||||
|
|
||||||
foreach ($this->userPasswords as $recipient => $password) {
|
foreach ($this->userPasswords as $uid => $password) {
|
||||||
$progress->advance();
|
$progress->advance();
|
||||||
if (!empty($password)) {
|
if (!empty($password)) {
|
||||||
$recipientDisplayName = $this->userManager->get($recipient)->getDisplayName();
|
$recipient = $this->userManager->get($uid);
|
||||||
$to = $this->config->getUserValue($recipient, 'settings', 'email', '');
|
$recipientDisplayName = $recipient->getDisplayName();
|
||||||
|
$to = $recipient->getEMailAddress();
|
||||||
|
|
||||||
if ($to === '') {
|
if ($to === '') {
|
||||||
$noMail[] = $recipient;
|
$noMail[] = $uid;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -380,12 +382,12 @@ class EncryptAll {
|
||||||
$message->setHtmlBody($htmlBody);
|
$message->setHtmlBody($htmlBody);
|
||||||
$message->setPlainBody($textBody);
|
$message->setPlainBody($textBody);
|
||||||
$message->setFrom([
|
$message->setFrom([
|
||||||
\OCP\Util::getDefaultEmailAddress('admin-noreply')
|
Util::getDefaultEmailAddress('admin-noreply')
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->mailer->send($message);
|
$this->mailer->send($message);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$noMail[] = $recipient;
|
$noMail[] = $uid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -199,7 +199,7 @@ class Users {
|
||||||
|
|
||||||
// Find the data
|
// Find the data
|
||||||
$data['quota'] = $this->fillStorageInfo($userId);
|
$data['quota'] = $this->fillStorageInfo($userId);
|
||||||
$data['email'] = $this->config->getUserValue($userId, 'settings', 'email');
|
$data['email'] = $targetUserObject->getEMailAddress();
|
||||||
$data['displayname'] = $targetUserObject->getDisplayName();
|
$data['displayname'] = $targetUserObject->getDisplayName();
|
||||||
|
|
||||||
return new OC_OCS_Result($data);
|
return new OC_OCS_Result($data);
|
||||||
|
|
|
@ -27,26 +27,27 @@
|
||||||
namespace OCA\Provisioning_API\Tests;
|
namespace OCA\Provisioning_API\Tests;
|
||||||
|
|
||||||
use OCA\Provisioning_API\Users;
|
use OCA\Provisioning_API\Users;
|
||||||
|
use OCP\API;
|
||||||
use OCP\IUserManager;
|
use OCP\IUserManager;
|
||||||
use OCP\IConfig;
|
use OCP\IConfig;
|
||||||
use OCP\IGroupManager;
|
|
||||||
use OCP\IUserSession;
|
use OCP\IUserSession;
|
||||||
|
use PHPUnit_Framework_MockObject_MockObject;
|
||||||
use Test\TestCase as OriginalTest;
|
use Test\TestCase as OriginalTest;
|
||||||
use OCP\ILogger;
|
use OCP\ILogger;
|
||||||
|
|
||||||
class UsersTest extends OriginalTest {
|
class UsersTest extends OriginalTest {
|
||||||
|
|
||||||
/** @var IUserManager */
|
/** @var IUserManager | PHPUnit_Framework_MockObject_MockObject */
|
||||||
protected $userManager;
|
protected $userManager;
|
||||||
/** @var IConfig */
|
/** @var IConfig | PHPUnit_Framework_MockObject_MockObject */
|
||||||
protected $config;
|
protected $config;
|
||||||
/** @var \OC\Group\Manager */
|
/** @var \OC\Group\Manager | PHPUnit_Framework_MockObject_MockObject */
|
||||||
protected $groupManager;
|
protected $groupManager;
|
||||||
/** @var IUserSession */
|
/** @var IUserSession | PHPUnit_Framework_MockObject_MockObject */
|
||||||
protected $userSession;
|
protected $userSession;
|
||||||
/** @var ILogger */
|
/** @var ILogger | PHPUnit_Framework_MockObject_MockObject */
|
||||||
protected $logger;
|
protected $logger;
|
||||||
/** @var Users */
|
/** @var Users | PHPUnit_Framework_MockObject_MockObject */
|
||||||
protected $api;
|
protected $api;
|
||||||
|
|
||||||
protected function tearDown() {
|
protected function tearDown() {
|
||||||
|
@ -83,7 +84,7 @@ class UsersTest extends OriginalTest {
|
||||||
->method('getUser')
|
->method('getUser')
|
||||||
->will($this->returnValue(null));
|
->will($this->returnValue(null));
|
||||||
|
|
||||||
$expected = new \OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED);
|
$expected = new \OC_OCS_Result(null, API::RESPOND_UNAUTHORISED);
|
||||||
$this->assertEquals($expected, $this->api->getUsers());
|
$this->assertEquals($expected, $this->api->getUsers());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,7 +204,7 @@ class UsersTest extends OriginalTest {
|
||||||
->method('getSubAdmin')
|
->method('getSubAdmin')
|
||||||
->will($this->returnValue($subAdminManager));
|
->will($this->returnValue($subAdminManager));
|
||||||
|
|
||||||
$expected = new \OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED);
|
$expected = new \OC_OCS_Result(null, API::RESPOND_UNAUTHORISED);
|
||||||
$this->assertEquals($expected, $this->api->getUsers());
|
$this->assertEquals($expected, $this->api->getUsers());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -464,7 +465,7 @@ class UsersTest extends OriginalTest {
|
||||||
->with()
|
->with()
|
||||||
->willReturn($subAdminManager);
|
->willReturn($subAdminManager);
|
||||||
|
|
||||||
$expected = new \OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED);
|
$expected = new \OC_OCS_Result(null, API::RESPOND_UNAUTHORISED);
|
||||||
$this->assertEquals($expected, $this->api->addUser());
|
$this->assertEquals($expected, $this->api->addUser());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -653,7 +654,7 @@ class UsersTest extends OriginalTest {
|
||||||
->method('getUser')
|
->method('getUser')
|
||||||
->will($this->returnValue(null));
|
->will($this->returnValue(null));
|
||||||
|
|
||||||
$expected = new \OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED);
|
$expected = new \OC_OCS_Result(null, API::RESPOND_UNAUTHORISED);
|
||||||
$this->assertEquals($expected, $this->api->getUser(['userid' => 'UserToGet']));
|
$this->assertEquals($expected, $this->api->getUser(['userid' => 'UserToGet']));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -669,7 +670,7 @@ class UsersTest extends OriginalTest {
|
||||||
->with('UserToGet')
|
->with('UserToGet')
|
||||||
->will($this->returnValue(null));
|
->will($this->returnValue(null));
|
||||||
|
|
||||||
$expected = new \OC_OCS_Result(null, \OCP\API::RESPOND_NOT_FOUND, 'The requested user could not be found');
|
$expected = new \OC_OCS_Result(null, API::RESPOND_NOT_FOUND, 'The requested user could not be found');
|
||||||
$this->assertEquals($expected, $this->api->getUser(['userid' => 'UserToGet']));
|
$this->assertEquals($expected, $this->api->getUser(['userid' => 'UserToGet']));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -680,6 +681,9 @@ class UsersTest extends OriginalTest {
|
||||||
->method('getUID')
|
->method('getUID')
|
||||||
->will($this->returnValue('admin'));
|
->will($this->returnValue('admin'));
|
||||||
$targetUser = $this->getMock('\OCP\IUser');
|
$targetUser = $this->getMock('\OCP\IUser');
|
||||||
|
$targetUser->expects($this->once())
|
||||||
|
->method('getEMailAddress')
|
||||||
|
->willReturn('demo@owncloud.org');
|
||||||
$this->userSession
|
$this->userSession
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getUser')
|
->method('getUser')
|
||||||
|
@ -704,11 +708,6 @@ class UsersTest extends OriginalTest {
|
||||||
->method('fillStorageInfo')
|
->method('fillStorageInfo')
|
||||||
->with('UserToGet')
|
->with('UserToGet')
|
||||||
->will($this->returnValue(['DummyValue']));
|
->will($this->returnValue(['DummyValue']));
|
||||||
$this->config
|
|
||||||
->expects($this->at(1))
|
|
||||||
->method('getUserValue')
|
|
||||||
->with('UserToGet', 'settings', 'email')
|
|
||||||
->will($this->returnValue('demo@owncloud.org'));
|
|
||||||
$targetUser
|
$targetUser
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getDisplayName')
|
->method('getDisplayName')
|
||||||
|
@ -732,6 +731,10 @@ class UsersTest extends OriginalTest {
|
||||||
->method('getUID')
|
->method('getUID')
|
||||||
->will($this->returnValue('subadmin'));
|
->will($this->returnValue('subadmin'));
|
||||||
$targetUser = $this->getMock('\OCP\IUser');
|
$targetUser = $this->getMock('\OCP\IUser');
|
||||||
|
$targetUser
|
||||||
|
->expects($this->once())
|
||||||
|
->method('getEMailAddress')
|
||||||
|
->willReturn('demo@owncloud.org');
|
||||||
$this->userSession
|
$this->userSession
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getUser')
|
->method('getUser')
|
||||||
|
@ -768,11 +771,6 @@ class UsersTest extends OriginalTest {
|
||||||
->method('fillStorageInfo')
|
->method('fillStorageInfo')
|
||||||
->with('UserToGet')
|
->with('UserToGet')
|
||||||
->will($this->returnValue(['DummyValue']));
|
->will($this->returnValue(['DummyValue']));
|
||||||
$this->config
|
|
||||||
->expects($this->at(1))
|
|
||||||
->method('getUserValue')
|
|
||||||
->with('UserToGet', 'settings', 'email')
|
|
||||||
->will($this->returnValue('demo@owncloud.org'));
|
|
||||||
$targetUser
|
$targetUser
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getDisplayName')
|
->method('getDisplayName')
|
||||||
|
@ -823,7 +821,7 @@ class UsersTest extends OriginalTest {
|
||||||
->method('getSubAdmin')
|
->method('getSubAdmin')
|
||||||
->will($this->returnValue($subAdminManager));
|
->will($this->returnValue($subAdminManager));
|
||||||
|
|
||||||
$expected = new \OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED);
|
$expected = new \OC_OCS_Result(null, API::RESPOND_UNAUTHORISED);
|
||||||
$this->assertEquals($expected, $this->api->getUser(['userid' => 'UserToGet']));
|
$this->assertEquals($expected, $this->api->getUser(['userid' => 'UserToGet']));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -865,15 +863,14 @@ class UsersTest extends OriginalTest {
|
||||||
->method('fillStorageInfo')
|
->method('fillStorageInfo')
|
||||||
->with('subadmin')
|
->with('subadmin')
|
||||||
->will($this->returnValue(['DummyValue']));
|
->will($this->returnValue(['DummyValue']));
|
||||||
$this->config
|
|
||||||
->expects($this->once())
|
|
||||||
->method('getUserValue')
|
|
||||||
->with('subadmin', 'settings', 'email')
|
|
||||||
->will($this->returnValue('subadmin@owncloud.org'));
|
|
||||||
$targetUser
|
$targetUser
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getDisplayName')
|
->method('getDisplayName')
|
||||||
->will($this->returnValue('Subadmin User'));
|
->will($this->returnValue('Subadmin User'));
|
||||||
|
$targetUser
|
||||||
|
->expects($this->once())
|
||||||
|
->method('getEMailAddress')
|
||||||
|
->will($this->returnValue('subadmin@owncloud.org'));
|
||||||
|
|
||||||
$expected = new \OC_OCS_Result([
|
$expected = new \OC_OCS_Result([
|
||||||
'quota' => ['DummyValue'],
|
'quota' => ['DummyValue'],
|
||||||
|
@ -889,7 +886,7 @@ class UsersTest extends OriginalTest {
|
||||||
->method('getUser')
|
->method('getUser')
|
||||||
->will($this->returnValue(null));
|
->will($this->returnValue(null));
|
||||||
|
|
||||||
$expected = new \OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED);
|
$expected = new \OC_OCS_Result(null, API::RESPOND_UNAUTHORISED);
|
||||||
$this->assertEquals($expected, $this->api->editUser(['userid' => 'UserToEdit']));
|
$this->assertEquals($expected, $this->api->editUser(['userid' => 'UserToEdit']));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,8 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use OCP\IUser;
|
||||||
|
|
||||||
OC_JSON::checkLoggedIn();
|
OC_JSON::checkLoggedIn();
|
||||||
OCP\JSON::callCheck();
|
OCP\JSON::callCheck();
|
||||||
|
|
||||||
|
@ -135,17 +137,23 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo
|
||||||
$itemSource = (string)$_POST['itemSource'];
|
$itemSource = (string)$_POST['itemSource'];
|
||||||
$recipient = (string)$_POST['recipient'];
|
$recipient = (string)$_POST['recipient'];
|
||||||
|
|
||||||
|
$userManager = \OC::$server->getUserManager();
|
||||||
|
$recipientList = [];
|
||||||
if($shareType === \OCP\Share::SHARE_TYPE_USER) {
|
if($shareType === \OCP\Share::SHARE_TYPE_USER) {
|
||||||
$recipientList[] = $recipient;
|
$recipientList[] = $userManager->get($recipient);
|
||||||
} elseif ($shareType === \OCP\Share::SHARE_TYPE_GROUP) {
|
} elseif ($shareType === \OCP\Share::SHARE_TYPE_GROUP) {
|
||||||
$recipientList = \OC_Group::usersInGroup($recipient);
|
$recipientList = \OC_Group::usersInGroup($recipient);
|
||||||
|
$group = \OC::$server->getGroupManager()->get($recipient);
|
||||||
|
$recipientList = $group->searchUsers('');
|
||||||
}
|
}
|
||||||
// don't send a mail to the user who shared the file
|
// don't send a mail to the user who shared the file
|
||||||
$recipientList = array_diff($recipientList, array(\OCP\User::getUser()));
|
$recipientList = array_filter($recipientList, function($user) {
|
||||||
|
/** @var IUser $user */
|
||||||
|
return $user->getUID() !== \OCP\User::getUser();
|
||||||
|
});
|
||||||
|
|
||||||
$mailNotification = new \OC\Share\MailNotifications(
|
$mailNotification = new \OC\Share\MailNotifications(
|
||||||
\OC::$server->getUserSession()->getUser()->getUID(),
|
\OC::$server->getUserSession()->getUser(),
|
||||||
\OC::$server->getConfig(),
|
|
||||||
\OC::$server->getL10N('lib'),
|
\OC::$server->getL10N('lib'),
|
||||||
\OC::$server->getMailer(),
|
\OC::$server->getMailer(),
|
||||||
\OC::$server->getLogger(),
|
\OC::$server->getLogger(),
|
||||||
|
@ -183,8 +191,7 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo
|
||||||
$to_address = (string)$_POST['toaddress'];
|
$to_address = (string)$_POST['toaddress'];
|
||||||
|
|
||||||
$mailNotification = new \OC\Share\MailNotifications(
|
$mailNotification = new \OC\Share\MailNotifications(
|
||||||
\OC::$server->getUserSession()->getUser()->getUID(),
|
\OC::$server->getUserSession()->getUser(),
|
||||||
\OC::$server->getConfig(),
|
|
||||||
\OC::$server->getL10N('lib'),
|
\OC::$server->getL10N('lib'),
|
||||||
\OC::$server->getMailer(),
|
\OC::$server->getMailer(),
|
||||||
\OC::$server->getLogger(),
|
\OC::$server->getLogger(),
|
||||||
|
@ -199,7 +206,6 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
\OCP\Util::writeLog('sharing', "Couldn't read date: " . $e->getMessage(), \OCP\Util::ERROR);
|
\OCP\Util::writeLog('sharing', "Couldn't read date: " . $e->getMessage(), \OCP\Util::ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $mailNotification->sendLinkShareMail($to_address, $file, $link, $expiration);
|
$result = $mailNotification->sendLinkShareMail($to_address, $file, $link, $expiration);
|
||||||
|
|
|
@ -218,13 +218,12 @@ class LostController extends Controller {
|
||||||
throw new \Exception($this->l10n->t('Couldn\'t send reset email. Please make sure your username is correct.'));
|
throw new \Exception($this->l10n->t('Couldn\'t send reset email. Please make sure your username is correct.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$email = $this->config->getUserValue($user, 'settings', 'email');
|
$userObject = $this->userManager->get($user);
|
||||||
|
$email = $userObject->getEMailAddress();
|
||||||
|
|
||||||
if (empty($email)) {
|
if (empty($email)) {
|
||||||
throw new \Exception(
|
throw new \Exception(
|
||||||
$this->l10n->t('Couldn\'t send reset email because there is no '.
|
$this->l10n->t('Could not send reset email because there is no email address for this username. Please contact your administrator.')
|
||||||
'email address for this username. Please ' .
|
|
||||||
'contact your administrator.')
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,11 +41,11 @@ class OC_OCS_Cloud {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getCurrentUser() {
|
public static function getCurrentUser() {
|
||||||
$email=\OC::$server->getConfig()->getUserValue(OC_User::getUser(), 'settings', 'email', '');
|
$userObject = \OC::$server->getUserManager()->get(OC_User::getUser());
|
||||||
$data = array(
|
$data = array(
|
||||||
'id' => OC_User::getUser(),
|
'id' => $userObject->getUID(),
|
||||||
'display-name' => OC_User::getDisplayName(),
|
'display-name' => $userObject->getDisplayName(),
|
||||||
'email' => $email,
|
'email' => $userObject->getEMailAddress(),
|
||||||
);
|
);
|
||||||
return new OC_OCS_Result($data);
|
return new OC_OCS_Result($data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,11 +28,12 @@
|
||||||
namespace OC\Share;
|
namespace OC\Share;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use OCP\IConfig;
|
|
||||||
use OCP\IL10N;
|
use OCP\IL10N;
|
||||||
|
use OCP\IUser;
|
||||||
use OCP\Mail\IMailer;
|
use OCP\Mail\IMailer;
|
||||||
use OCP\ILogger;
|
use OCP\ILogger;
|
||||||
use OCP\Defaults;
|
use OCP\Defaults;
|
||||||
|
use OCP\Util;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class MailNotifications
|
* Class MailNotifications
|
||||||
|
@ -41,16 +42,14 @@ use OCP\Defaults;
|
||||||
*/
|
*/
|
||||||
class MailNotifications {
|
class MailNotifications {
|
||||||
|
|
||||||
/** @var string sender userId */
|
/** @var IUser sender userId */
|
||||||
private $userId;
|
private $user;
|
||||||
/** @var string sender email address */
|
/** @var string sender email address */
|
||||||
private $replyTo;
|
private $replyTo;
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $senderDisplayName;
|
private $senderDisplayName;
|
||||||
/** @var IL10N */
|
/** @var IL10N */
|
||||||
private $l;
|
private $l;
|
||||||
/** @var IConfig */
|
|
||||||
private $config;
|
|
||||||
/** @var IMailer */
|
/** @var IMailer */
|
||||||
private $mailer;
|
private $mailer;
|
||||||
/** @var Defaults */
|
/** @var Defaults */
|
||||||
|
@ -59,34 +58,31 @@ class MailNotifications {
|
||||||
private $logger;
|
private $logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $uid user id
|
* @param IUser $user
|
||||||
* @param IConfig $config
|
|
||||||
* @param IL10N $l10n
|
* @param IL10N $l10n
|
||||||
* @param IMailer $mailer
|
* @param IMailer $mailer
|
||||||
* @param ILogger $logger
|
* @param ILogger $logger
|
||||||
* @param Defaults $defaults
|
* @param Defaults $defaults
|
||||||
*/
|
*/
|
||||||
public function __construct($uid,
|
public function __construct(IUser $user,
|
||||||
IConfig $config,
|
|
||||||
IL10N $l10n,
|
IL10N $l10n,
|
||||||
IMailer $mailer,
|
IMailer $mailer,
|
||||||
ILogger $logger,
|
ILogger $logger,
|
||||||
Defaults $defaults) {
|
Defaults $defaults) {
|
||||||
$this->l = $l10n;
|
$this->l = $l10n;
|
||||||
$this->userId = $uid;
|
$this->user = $user;
|
||||||
$this->config = $config;
|
|
||||||
$this->mailer = $mailer;
|
$this->mailer = $mailer;
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
$this->defaults = $defaults;
|
$this->defaults = $defaults;
|
||||||
|
|
||||||
$this->replyTo = $this->config->getUserValue($this->userId, 'settings', 'email', null);
|
$this->replyTo = $this->user->getEMailAddress();
|
||||||
$this->senderDisplayName = \OCP\User::getDisplayName($this->userId);
|
$this->senderDisplayName = $this->user->getDisplayName();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* inform users if a file was shared with them
|
* inform users if a file was shared with them
|
||||||
*
|
*
|
||||||
* @param array $recipientList list of recipients
|
* @param IUser[] $recipientList list of recipients
|
||||||
* @param string $itemSource shared item source
|
* @param string $itemSource shared item source
|
||||||
* @param string $itemType shared item type
|
* @param string $itemType shared item type
|
||||||
* @return array list of user to whom the mail send operation failed
|
* @return array list of user to whom the mail send operation failed
|
||||||
|
@ -95,15 +91,15 @@ class MailNotifications {
|
||||||
$noMail = [];
|
$noMail = [];
|
||||||
|
|
||||||
foreach ($recipientList as $recipient) {
|
foreach ($recipientList as $recipient) {
|
||||||
$recipientDisplayName = \OCP\User::getDisplayName($recipient);
|
$recipientDisplayName = $recipient->getDisplayName();
|
||||||
$to = $this->config->getUserValue($recipient, 'settings', 'email', '');
|
$to = $recipient->getEMailAddress();
|
||||||
|
|
||||||
if ($to === '') {
|
if ($to === '') {
|
||||||
$noMail[] = $recipientDisplayName;
|
$noMail[] = $recipientDisplayName;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$items = \OCP\Share::getItemSharedWithUser($itemType, $itemSource, $recipient);
|
$items = $this->getItemSharedWithUser($itemSource, $itemType, $recipient);
|
||||||
$filename = trim($items[0]['file_target'], '/');
|
$filename = trim($items[0]['file_target'], '/');
|
||||||
$subject = (string) $this->l->t('%s shared »%s« with you', array($this->senderDisplayName, $filename));
|
$subject = (string) $this->l->t('%s shared »%s« with you', array($this->senderDisplayName, $filename));
|
||||||
$expiration = null;
|
$expiration = null;
|
||||||
|
@ -134,7 +130,7 @@ class MailNotifications {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$link = \OCP\Util::linkToAbsolute('files', 'index.php', $args);
|
$link = Util::linkToAbsolute('files', 'index.php', $args);
|
||||||
|
|
||||||
list($htmlBody, $textBody) = $this->createMailBody($filename, $link, $expiration, 'internal');
|
list($htmlBody, $textBody) = $this->createMailBody($filename, $link, $expiration, 'internal');
|
||||||
|
|
||||||
|
@ -146,7 +142,7 @@ class MailNotifications {
|
||||||
$message->setHtmlBody($htmlBody);
|
$message->setHtmlBody($htmlBody);
|
||||||
$message->setPlainBody($textBody);
|
$message->setPlainBody($textBody);
|
||||||
$message->setFrom([
|
$message->setFrom([
|
||||||
\OCP\Util::getDefaultEmailAddress('sharing-noreply') =>
|
Util::getDefaultEmailAddress('sharing-noreply') =>
|
||||||
(string)$this->l->t('%s via %s', [
|
(string)$this->l->t('%s via %s', [
|
||||||
$this->senderDisplayName,
|
$this->senderDisplayName,
|
||||||
$this->defaults->getName()
|
$this->defaults->getName()
|
||||||
|
@ -187,7 +183,7 @@ class MailNotifications {
|
||||||
$message->setHtmlBody($htmlBody);
|
$message->setHtmlBody($htmlBody);
|
||||||
$message->setPlainBody($textBody);
|
$message->setPlainBody($textBody);
|
||||||
$message->setFrom([
|
$message->setFrom([
|
||||||
\OCP\Util::getDefaultEmailAddress('sharing-noreply') =>
|
Util::getDefaultEmailAddress('sharing-noreply') =>
|
||||||
(string)$this->l->t('%s via %s', [
|
(string)$this->l->t('%s via %s', [
|
||||||
$this->senderDisplayName,
|
$this->senderDisplayName,
|
||||||
$this->defaults->getName()
|
$this->defaults->getName()
|
||||||
|
@ -210,7 +206,7 @@ class MailNotifications {
|
||||||
* @param string $filename the shared file
|
* @param string $filename the shared file
|
||||||
* @param string $link link to the shared file
|
* @param string $link link to the shared file
|
||||||
* @param int $expiration expiration date (timestamp)
|
* @param int $expiration expiration date (timestamp)
|
||||||
* @param bool $prefix prefix of mail template files
|
* @param string $prefix prefix of mail template files
|
||||||
* @return array an array of the html mail body and the plain text mail body
|
* @return array an array of the html mail body and the plain text mail body
|
||||||
*/
|
*/
|
||||||
private function createMailBody($filename, $link, $expiration, $prefix = '') {
|
private function createMailBody($filename, $link, $expiration, $prefix = '') {
|
||||||
|
@ -233,4 +229,14 @@ class MailNotifications {
|
||||||
return [$htmlMail, $plainTextMail];
|
return [$htmlMail, $plainTextMail];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $itemSource
|
||||||
|
* @param $itemType
|
||||||
|
* @param IUser $recipient
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function getItemSharedWithUser($itemSource, $itemType, $recipient) {
|
||||||
|
return Share::getItemSharedWithUser($itemType, $itemSource, $recipient->getUID());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -312,7 +312,7 @@ class User implements IUser {
|
||||||
* @since 9.0.0
|
* @since 9.0.0
|
||||||
*/
|
*/
|
||||||
public function getEMailAddress() {
|
public function getEMailAddress() {
|
||||||
return $this->config->getUserValue($this->uid, 'settings', 'email');
|
return $this->config->getUserValue($this->uid, 'settings', 'email', null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -74,7 +74,7 @@ interface IL10N {
|
||||||
/**
|
/**
|
||||||
* Localization
|
* Localization
|
||||||
* @param string $type Type of localization
|
* @param string $type Type of localization
|
||||||
* @param array $data parameters for this localization
|
* @param int|string $data parameters for this localization
|
||||||
* @param array $options currently supports following options:
|
* @param array $options currently supports following options:
|
||||||
* - 'width': handed into \Punic\Calendar::formatDate as second parameter
|
* - 'width': handed into \Punic\Calendar::formatDate as second parameter
|
||||||
* @return string|false
|
* @return string|false
|
||||||
|
|
|
@ -164,6 +164,10 @@ class UsersController extends Controller {
|
||||||
$subAdminGroups[$key] = $subAdminGroup->getGID();
|
$subAdminGroups[$key] = $subAdminGroup->getGID();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$displayName = $user->getEMailAddress();
|
||||||
|
if (is_null($displayName)) {
|
||||||
|
$displayName = '';
|
||||||
|
}
|
||||||
return [
|
return [
|
||||||
'name' => $user->getUID(),
|
'name' => $user->getUID(),
|
||||||
'displayname' => $user->getDisplayName(),
|
'displayname' => $user->getDisplayName(),
|
||||||
|
@ -173,7 +177,7 @@ class UsersController extends Controller {
|
||||||
'storageLocation' => $user->getHome(),
|
'storageLocation' => $user->getHome(),
|
||||||
'lastLogin' => $user->getLastLogin() * 1000,
|
'lastLogin' => $user->getLastLogin() * 1000,
|
||||||
'backend' => $user->getBackendClassName(),
|
'backend' => $user->getBackendClassName(),
|
||||||
'email' => $this->config->getUserValue($user->getUID(), 'settings', 'email', ''),
|
'email' => $displayName,
|
||||||
'isRestoreDisabled' => !$restorePossible,
|
'isRestoreDisabled' => !$restorePossible,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,23 +54,24 @@ if ($config->getSystemValue('enable_avatars', true) === true) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Highlight navigation entry
|
// Highlight navigation entry
|
||||||
OC_App::setActiveNavigationEntry( 'personal' );
|
OC::$server->getNavigationManager()->setActiveEntry('personal');
|
||||||
|
|
||||||
$storageInfo=OC_Helper::getStorageInfo('/');
|
$storageInfo=OC_Helper::getStorageInfo('/');
|
||||||
|
|
||||||
$email=$config->getUserValue(OC_User::getUser(), 'settings', 'email', '');
|
$user = OC::$server->getUserManager()->get(OC_User::getUser());
|
||||||
|
$email = $user->getEMailAddress();
|
||||||
|
|
||||||
$userLang=$config->getUserValue( OC_User::getUser(), 'core', 'lang', OC_L10N::findLanguage() );
|
$userLang=$config->getUserValue( OC_User::getUser(), 'core', 'lang', OC_L10N::findLanguage() );
|
||||||
$languageCodes=OC_L10N::findAvailableLanguages();
|
$languageCodes=OC_L10N::findAvailableLanguages();
|
||||||
|
|
||||||
// array of common languages
|
// array of common languages
|
||||||
$commonlangcodes = array(
|
$commonLangCodes = array(
|
||||||
'en', 'es', 'fr', 'de', 'de_DE', 'ja', 'ar', 'ru', 'nl', 'it', 'pt_BR', 'pt_PT', 'da', 'fi_FI', 'nb_NO', 'sv', 'tr', 'zh_CN', 'ko'
|
'en', 'es', 'fr', 'de', 'de_DE', 'ja', 'ar', 'ru', 'nl', 'it', 'pt_BR', 'pt_PT', 'da', 'fi_FI', 'nb_NO', 'sv', 'tr', 'zh_CN', 'ko'
|
||||||
);
|
);
|
||||||
|
|
||||||
$languageNames=include 'languageCodes.php';
|
$languageNames=include 'languageCodes.php';
|
||||||
$languages=array();
|
$languages=array();
|
||||||
$commonlanguages = array();
|
$commonLanguages = array();
|
||||||
foreach($languageCodes as $lang) {
|
foreach($languageCodes as $lang) {
|
||||||
$l = \OC::$server->getL10N('settings', $lang);
|
$l = \OC::$server->getL10N('settings', $lang);
|
||||||
// TRANSLATORS this is the language name for the language switcher in the personal settings and should be the localized version
|
// TRANSLATORS this is the language name for the language switcher in the personal settings and should be the localized version
|
||||||
|
@ -82,12 +83,12 @@ foreach($languageCodes as $lang) {
|
||||||
$ln=array('code'=>$lang, 'name'=>$lang);
|
$ln=array('code'=>$lang, 'name'=>$lang);
|
||||||
}
|
}
|
||||||
|
|
||||||
// put apropriate languages into apropriate arrays, to print them sorted
|
// put appropriate languages into appropriate arrays, to print them sorted
|
||||||
// used language -> common languages -> divider -> other languages
|
// used language -> common languages -> divider -> other languages
|
||||||
if ($lang === $userLang) {
|
if ($lang === $userLang) {
|
||||||
$userLang = $ln;
|
$userLang = $ln;
|
||||||
} elseif (in_array($lang, $commonlangcodes)) {
|
} elseif (in_array($lang, $commonLangCodes)) {
|
||||||
$commonlanguages[array_search($lang, $commonlangcodes)]=$ln;
|
$commonLanguages[array_search($lang, $commonLangCodes)]=$ln;
|
||||||
} else {
|
} else {
|
||||||
$languages[]=$ln;
|
$languages[]=$ln;
|
||||||
}
|
}
|
||||||
|
@ -101,7 +102,7 @@ if (!is_array($userLang)) {
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
ksort($commonlanguages);
|
ksort($commonLanguages);
|
||||||
|
|
||||||
// sort now by displayed language not the iso-code
|
// sort now by displayed language not the iso-code
|
||||||
usort( $languages, function ($a, $b) {
|
usort( $languages, function ($a, $b) {
|
||||||
|
@ -142,7 +143,7 @@ $tmpl->assign('usage_relative', $storageInfo['relative']);
|
||||||
$tmpl->assign('clients', $clients);
|
$tmpl->assign('clients', $clients);
|
||||||
$tmpl->assign('email', $email);
|
$tmpl->assign('email', $email);
|
||||||
$tmpl->assign('languages', $languages);
|
$tmpl->assign('languages', $languages);
|
||||||
$tmpl->assign('commonlanguages', $commonlanguages);
|
$tmpl->assign('commonlanguages', $commonLanguages);
|
||||||
$tmpl->assign('activelanguage', $userLang);
|
$tmpl->assign('activelanguage', $userLang);
|
||||||
$tmpl->assign('passwordChangeSupported', OC_User::canUserChangePassword(OC_User::getUser()));
|
$tmpl->assign('passwordChangeSupported', OC_User::canUserChangePassword(OC_User::getUser()));
|
||||||
$tmpl->assign('displayNameChangeSupported', OC_User::canUserChangeDisplayName(OC_User::getUser()));
|
$tmpl->assign('displayNameChangeSupported', OC_User::canUserChangeDisplayName(OC_User::getUser()));
|
||||||
|
|
|
@ -20,8 +20,18 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace OC\Core\LostPassword\Controller;
|
namespace OC\Core\LostPassword\Controller;
|
||||||
use OC\Core\Application;
|
|
||||||
use OCP\AppFramework\Http\TemplateResponse;
|
use OCP\AppFramework\Http\TemplateResponse;
|
||||||
|
use OCP\AppFramework\Utility\ITimeFactory;
|
||||||
|
use OCP\IConfig;
|
||||||
|
use OCP\IL10N;
|
||||||
|
use OCP\IRequest;
|
||||||
|
use OCP\IURLGenerator;
|
||||||
|
use OCP\IUser;
|
||||||
|
use OCP\IUserManager;
|
||||||
|
use OCP\Mail\IMailer;
|
||||||
|
use OCP\Security\ISecureRandom;
|
||||||
|
use PHPUnit_Framework_MockObject_MockObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class LostControllerTest
|
* Class LostControllerTest
|
||||||
|
@ -30,47 +40,84 @@ use OCP\AppFramework\Http\TemplateResponse;
|
||||||
*/
|
*/
|
||||||
class LostControllerTest extends \PHPUnit_Framework_TestCase {
|
class LostControllerTest extends \PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
private $container;
|
|
||||||
/** @var LostController */
|
/** @var LostController */
|
||||||
private $lostController;
|
private $lostController;
|
||||||
|
/** @var IUser */
|
||||||
|
private $existingUser;
|
||||||
|
/** @var IURLGenerator | PHPUnit_Framework_MockObject_MockObject */
|
||||||
|
private $urlGenerator;
|
||||||
|
/** @var IL10N */
|
||||||
|
private $l10n;
|
||||||
|
/** @var IUserManager | PHPUnit_Framework_MockObject_MockObject */
|
||||||
|
private $userManager;
|
||||||
|
/** @var \OC_Defaults */
|
||||||
|
private $defaults;
|
||||||
|
/** @var IConfig | PHPUnit_Framework_MockObject_MockObject */
|
||||||
|
private $config;
|
||||||
|
/** @var IMailer | PHPUnit_Framework_MockObject_MockObject */
|
||||||
|
private $mailer;
|
||||||
|
/** @var ISecureRandom | PHPUnit_Framework_MockObject_MockObject */
|
||||||
|
private $secureRandom;
|
||||||
|
/** @var ITimeFactory | PHPUnit_Framework_MockObject_MockObject */
|
||||||
|
private $timeFactory;
|
||||||
|
/** @var IRequest */
|
||||||
|
private $request;
|
||||||
|
|
||||||
protected function setUp() {
|
protected function setUp() {
|
||||||
$app = new Application();
|
|
||||||
$this->container = $app->getContainer();
|
$this->existingUser = $this->getMockBuilder('OCP\IUser')
|
||||||
$this->container['AppName'] = 'core';
|
|
||||||
$this->container['Config'] = $this->getMockBuilder('\OCP\IConfig')
|
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
$this->container['L10N'] = $this->getMockBuilder('\OCP\IL10N')
|
|
||||||
|
$this->existingUser
|
||||||
|
->expects($this->any())
|
||||||
|
->method('getEMailAddress')
|
||||||
|
->willReturn('test@example.com');
|
||||||
|
|
||||||
|
$this->config = $this->getMockBuilder('\OCP\IConfig')
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
$this->container['L10N']
|
$this->l10n = $this->getMockBuilder('\OCP\IL10N')
|
||||||
|
->disableOriginalConstructor()->getMock();
|
||||||
|
$this->l10n
|
||||||
->expects($this->any())
|
->expects($this->any())
|
||||||
->method('t')
|
->method('t')
|
||||||
->will($this->returnCallback(function($text, $parameters = array()) {
|
->will($this->returnCallback(function($text, $parameters = array()) {
|
||||||
return vsprintf($text, $parameters);
|
return vsprintf($text, $parameters);
|
||||||
}));
|
}));
|
||||||
$this->container['Defaults'] = $this->getMockBuilder('\OC_Defaults')
|
$this->defaults = $this->getMockBuilder('\OC_Defaults')
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
$this->container['UserManager'] = $this->getMockBuilder('\OCP\IUserManager')
|
$this->userManager = $this->getMockBuilder('\OCP\IUserManager')
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
$this->container['Config'] = $this->getMockBuilder('\OCP\IConfig')
|
$this->urlGenerator = $this->getMockBuilder('\OCP\IURLGenerator')
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
$this->container['URLGenerator'] = $this->getMockBuilder('\OCP\IURLGenerator')
|
$this->mailer = $this->getMockBuilder('\OCP\Mail\IMailer')
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
$this->container['Mailer'] = $this->getMockBuilder('\OCP\Mail\IMailer')
|
$this->secureRandom = $this->getMockBuilder('\OCP\Security\ISecureRandom')
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
$this->container['SecureRandom'] = $this->getMockBuilder('\OCP\Security\ISecureRandom')
|
$this->timeFactory = $this->getMockBuilder('\OCP\AppFramework\Utility\ITimeFactory')
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
$this->container['TimeFactory'] = $this->getMockBuilder('\OCP\AppFramework\Utility\ITimeFactory')
|
$this->request = $this->getMockBuilder('OCP\IRequest')
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
$this->container['IsEncryptionEnabled'] = true;
|
$this->lostController = new LostController(
|
||||||
$this->lostController = $this->container['LostController'];
|
'Core',
|
||||||
|
$this->request,
|
||||||
|
$this->urlGenerator,
|
||||||
|
$this->userManager,
|
||||||
|
$this->defaults,
|
||||||
|
$this->l10n,
|
||||||
|
$this->config,
|
||||||
|
$this->secureRandom,
|
||||||
|
'lostpassword-noreply@localhost',
|
||||||
|
true,
|
||||||
|
$this->mailer,
|
||||||
|
$this->timeFactory
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testResetFormUnsuccessful() {
|
public function testResetFormUnsuccessful() {
|
||||||
$userId = 'admin';
|
$userId = 'admin';
|
||||||
$token = 'MySecretToken';
|
$token = 'MySecretToken';
|
||||||
|
|
||||||
$this->container['URLGenerator']
|
$this->urlGenerator
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('linkToRouteAbsolute')
|
->method('linkToRouteAbsolute')
|
||||||
->with('core.lost.setPassword', array('userId' => 'admin', 'token' => 'MySecretToken'))
|
->with('core.lost.setPassword', array('userId' => 'admin', 'token' => 'MySecretToken'))
|
||||||
|
@ -89,7 +136,7 @@ class LostControllerTest extends \PHPUnit_Framework_TestCase {
|
||||||
public function testEmailUnsucessful() {
|
public function testEmailUnsucessful() {
|
||||||
$existingUser = 'ExistingUser';
|
$existingUser = 'ExistingUser';
|
||||||
$nonExistingUser = 'NonExistingUser';
|
$nonExistingUser = 'NonExistingUser';
|
||||||
$this->container['UserManager']
|
$this->userManager
|
||||||
->expects($this->any())
|
->expects($this->any())
|
||||||
->method('userExists')
|
->method('userExists')
|
||||||
->will($this->returnValueMap(array(
|
->will($this->returnValueMap(array(
|
||||||
|
@ -106,7 +153,7 @@ class LostControllerTest extends \PHPUnit_Framework_TestCase {
|
||||||
$this->assertSame($expectedResponse, $response);
|
$this->assertSame($expectedResponse, $response);
|
||||||
|
|
||||||
// With no mail address
|
// With no mail address
|
||||||
$this->container['Config']
|
$this->config
|
||||||
->expects($this->any())
|
->expects($this->any())
|
||||||
->method('getUserValue')
|
->method('getUserValue')
|
||||||
->with($existingUser, 'settings', 'email')
|
->with($existingUser, 'settings', 'email')
|
||||||
|
@ -120,35 +167,35 @@ class LostControllerTest extends \PHPUnit_Framework_TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testEmailSuccessful() {
|
public function testEmailSuccessful() {
|
||||||
$randomToken = $this->container['SecureRandom'];
|
$randomToken = $this->secureRandom;
|
||||||
$this->container['SecureRandom']
|
$this->secureRandom
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('generate')
|
->method('generate')
|
||||||
->with('21')
|
->with('21')
|
||||||
->will($this->returnValue('ThisIsMaybeANotSoSecretToken!'));
|
->will($this->returnValue('ThisIsMaybeANotSoSecretToken!'));
|
||||||
$this->container['UserManager']
|
$this->userManager
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('userExists')
|
->method('userExists')
|
||||||
->with('ExistingUser')
|
->with('ExistingUser')
|
||||||
->will($this->returnValue(true));
|
->will($this->returnValue(true));
|
||||||
$this->container['TimeFactory']
|
$this->userManager
|
||||||
|
->expects($this->any())
|
||||||
|
->method('get')
|
||||||
|
->with('ExistingUser')
|
||||||
|
->willReturn($this->existingUser);
|
||||||
|
$this->timeFactory
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getTime')
|
->method('getTime')
|
||||||
->will($this->returnValue(12348));
|
->will($this->returnValue(12348));
|
||||||
$this->container['Config']
|
$this->secureRandom
|
||||||
->expects($this->once())
|
|
||||||
->method('getUserValue')
|
|
||||||
->with('ExistingUser', 'settings', 'email')
|
|
||||||
->will($this->returnValue('test@example.com'));
|
|
||||||
$this->container['SecureRandom']
|
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getMediumStrengthGenerator')
|
->method('getMediumStrengthGenerator')
|
||||||
->will($this->returnValue($randomToken));
|
->will($this->returnValue($randomToken));
|
||||||
$this->container['Config']
|
$this->config
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('setUserValue')
|
->method('setUserValue')
|
||||||
->with('ExistingUser', 'owncloud', 'lostpassword', '12348:ThisIsMaybeANotSoSecretToken!');
|
->with('ExistingUser', 'owncloud', 'lostpassword', '12348:ThisIsMaybeANotSoSecretToken!');
|
||||||
$this->container['URLGenerator']
|
$this->urlGenerator
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('linkToRouteAbsolute')
|
->method('linkToRouteAbsolute')
|
||||||
->with('core.lost.resetform', array('userId' => 'ExistingUser', 'token' => 'ThisIsMaybeANotSoSecretToken!'))
|
->with('core.lost.resetform', array('userId' => 'ExistingUser', 'token' => 'ThisIsMaybeANotSoSecretToken!'))
|
||||||
|
@ -171,11 +218,11 @@ class LostControllerTest extends \PHPUnit_Framework_TestCase {
|
||||||
->expects($this->at(3))
|
->expects($this->at(3))
|
||||||
->method('setFrom')
|
->method('setFrom')
|
||||||
->with(['lostpassword-noreply@localhost' => null]);
|
->with(['lostpassword-noreply@localhost' => null]);
|
||||||
$this->container['Mailer']
|
$this->mailer
|
||||||
->expects($this->at(0))
|
->expects($this->at(0))
|
||||||
->method('createMessage')
|
->method('createMessage')
|
||||||
->will($this->returnValue($message));
|
->will($this->returnValue($message));
|
||||||
$this->container['Mailer']
|
$this->mailer
|
||||||
->expects($this->at(1))
|
->expects($this->at(1))
|
||||||
->method('send')
|
->method('send')
|
||||||
->with($message);
|
->with($message);
|
||||||
|
@ -186,35 +233,35 @@ class LostControllerTest extends \PHPUnit_Framework_TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testEmailCantSendException() {
|
public function testEmailCantSendException() {
|
||||||
$randomToken = $this->container['SecureRandom'];
|
$randomToken = $this->secureRandom;
|
||||||
$this->container['SecureRandom']
|
$this->secureRandom
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('generate')
|
->method('generate')
|
||||||
->with('21')
|
->with('21')
|
||||||
->will($this->returnValue('ThisIsMaybeANotSoSecretToken!'));
|
->will($this->returnValue('ThisIsMaybeANotSoSecretToken!'));
|
||||||
$this->container['UserManager']
|
$this->userManager
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('userExists')
|
->method('userExists')
|
||||||
->with('ExistingUser')
|
->with('ExistingUser')
|
||||||
->will($this->returnValue(true));
|
->will($this->returnValue(true));
|
||||||
$this->container['Config']
|
$this->userManager
|
||||||
->expects($this->once())
|
->expects($this->any())
|
||||||
->method('getUserValue')
|
->method('get')
|
||||||
->with('ExistingUser', 'settings', 'email')
|
->with('ExistingUser')
|
||||||
->will($this->returnValue('test@example.com'));
|
->willReturn($this->existingUser);
|
||||||
$this->container['SecureRandom']
|
$this->secureRandom
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getMediumStrengthGenerator')
|
->method('getMediumStrengthGenerator')
|
||||||
->will($this->returnValue($randomToken));
|
->will($this->returnValue($randomToken));
|
||||||
$this->container['Config']
|
$this->config
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('setUserValue')
|
->method('setUserValue')
|
||||||
->with('ExistingUser', 'owncloud', 'lostpassword', '12348:ThisIsMaybeANotSoSecretToken!');
|
->with('ExistingUser', 'owncloud', 'lostpassword', '12348:ThisIsMaybeANotSoSecretToken!');
|
||||||
$this->container['TimeFactory']
|
$this->timeFactory
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getTime')
|
->method('getTime')
|
||||||
->will($this->returnValue(12348));
|
->will($this->returnValue(12348));
|
||||||
$this->container['URLGenerator']
|
$this->urlGenerator
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('linkToRouteAbsolute')
|
->method('linkToRouteAbsolute')
|
||||||
->with('core.lost.resetform', array('userId' => 'ExistingUser', 'token' => 'ThisIsMaybeANotSoSecretToken!'))
|
->with('core.lost.resetform', array('userId' => 'ExistingUser', 'token' => 'ThisIsMaybeANotSoSecretToken!'))
|
||||||
|
@ -237,11 +284,11 @@ class LostControllerTest extends \PHPUnit_Framework_TestCase {
|
||||||
->expects($this->at(3))
|
->expects($this->at(3))
|
||||||
->method('setFrom')
|
->method('setFrom')
|
||||||
->with(['lostpassword-noreply@localhost' => null]);
|
->with(['lostpassword-noreply@localhost' => null]);
|
||||||
$this->container['Mailer']
|
$this->mailer
|
||||||
->expects($this->at(0))
|
->expects($this->at(0))
|
||||||
->method('createMessage')
|
->method('createMessage')
|
||||||
->will($this->returnValue($message));
|
->will($this->returnValue($message));
|
||||||
$this->container['Mailer']
|
$this->mailer
|
||||||
->expects($this->at(1))
|
->expects($this->at(1))
|
||||||
->method('send')
|
->method('send')
|
||||||
->with($message)
|
->with($message)
|
||||||
|
@ -253,7 +300,7 @@ class LostControllerTest extends \PHPUnit_Framework_TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetPasswordUnsuccessful() {
|
public function testSetPasswordUnsuccessful() {
|
||||||
$this->container['Config']
|
$this->config
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getUserValue')
|
->method('getUserValue')
|
||||||
->with('InvalidTokenUser', 'owncloud', 'lostpassword', null)
|
->with('InvalidTokenUser', 'owncloud', 'lostpassword', null)
|
||||||
|
@ -275,7 +322,7 @@ class LostControllerTest extends \PHPUnit_Framework_TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetPasswordSuccessful() {
|
public function testSetPasswordSuccessful() {
|
||||||
$this->container['Config']
|
$this->config
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getUserValue')
|
->method('getUserValue')
|
||||||
->with('ValidTokenUser', 'owncloud', 'lostpassword', null)
|
->with('ValidTokenUser', 'owncloud', 'lostpassword', null)
|
||||||
|
@ -290,16 +337,16 @@ class LostControllerTest extends \PHPUnit_Framework_TestCase {
|
||||||
->method('setPassword')
|
->method('setPassword')
|
||||||
->with('NewPassword')
|
->with('NewPassword')
|
||||||
->will($this->returnValue(true));
|
->will($this->returnValue(true));
|
||||||
$this->container['UserManager']
|
$this->userManager
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('get')
|
->method('get')
|
||||||
->with('ValidTokenUser')
|
->with('ValidTokenUser')
|
||||||
->will($this->returnValue($user));
|
->will($this->returnValue($user));
|
||||||
$this->container['Config']
|
$this->config
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('deleteUserValue')
|
->method('deleteUserValue')
|
||||||
->with('ValidTokenUser', 'owncloud', 'lostpassword');
|
->with('ValidTokenUser', 'owncloud', 'lostpassword');
|
||||||
$this->container['TimeFactory']
|
$this->timeFactory
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getTime')
|
->method('getTime')
|
||||||
->will($this->returnValue(12348));
|
->will($this->returnValue(12348));
|
||||||
|
@ -310,19 +357,19 @@ class LostControllerTest extends \PHPUnit_Framework_TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetPasswordExpiredToken() {
|
public function testSetPasswordExpiredToken() {
|
||||||
$this->container['Config']
|
$this->config
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getUserValue')
|
->method('getUserValue')
|
||||||
->with('ValidTokenUser', 'owncloud', 'lostpassword', null)
|
->with('ValidTokenUser', 'owncloud', 'lostpassword', null)
|
||||||
->will($this->returnValue('12345:TheOnlyAndOnlyOneTokenToResetThePassword'));
|
->will($this->returnValue('12345:TheOnlyAndOnlyOneTokenToResetThePassword'));
|
||||||
$user = $this->getMockBuilder('\OCP\IUser')
|
$user = $this->getMockBuilder('\OCP\IUser')
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
$this->container['UserManager']
|
$this->userManager
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('get')
|
->method('get')
|
||||||
->with('ValidTokenUser')
|
->with('ValidTokenUser')
|
||||||
->will($this->returnValue($user));
|
->will($this->returnValue($user));
|
||||||
$this->container['TimeFactory']
|
$this->timeFactory
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getTime')
|
->method('getTime')
|
||||||
->will($this->returnValue(55546));
|
->will($this->returnValue(55546));
|
||||||
|
@ -336,14 +383,14 @@ class LostControllerTest extends \PHPUnit_Framework_TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetPasswordInvalidDataInDb() {
|
public function testSetPasswordInvalidDataInDb() {
|
||||||
$this->container['Config']
|
$this->config
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getUserValue')
|
->method('getUserValue')
|
||||||
->with('ValidTokenUser', 'owncloud', 'lostpassword', null)
|
->with('ValidTokenUser', 'owncloud', 'lostpassword', null)
|
||||||
->will($this->returnValue('TheOnlyAndOnlyOneTokenToResetThePassword'));
|
->will($this->returnValue('TheOnlyAndOnlyOneTokenToResetThePassword'));
|
||||||
$user = $this->getMockBuilder('\OCP\IUser')
|
$user = $this->getMockBuilder('\OCP\IUser')
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
$this->container['UserManager']
|
$this->userManager
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('get')
|
->method('get')
|
||||||
->with('ValidTokenUser')
|
->with('ValidTokenUser')
|
||||||
|
@ -358,7 +405,7 @@ class LostControllerTest extends \PHPUnit_Framework_TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetPasswordExpiredTokenDueToLogin() {
|
public function testSetPasswordExpiredTokenDueToLogin() {
|
||||||
$this->container['Config']
|
$this->config
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getUserValue')
|
->method('getUserValue')
|
||||||
->with('ValidTokenUser', 'owncloud', 'lostpassword', null)
|
->with('ValidTokenUser', 'owncloud', 'lostpassword', null)
|
||||||
|
@ -369,12 +416,12 @@ class LostControllerTest extends \PHPUnit_Framework_TestCase {
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getLastLogin')
|
->method('getLastLogin')
|
||||||
->will($this->returnValue(12346));
|
->will($this->returnValue(12346));
|
||||||
$this->container['UserManager']
|
$this->userManager
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('get')
|
->method('get')
|
||||||
->with('ValidTokenUser')
|
->with('ValidTokenUser')
|
||||||
->will($this->returnValue($user));
|
->will($this->returnValue($user));
|
||||||
$this->container['TimeFactory']
|
$this->timeFactory
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getTime')
|
->method('getTime')
|
||||||
->will($this->returnValue(12345));
|
->will($this->returnValue(12345));
|
||||||
|
@ -388,7 +435,7 @@ class LostControllerTest extends \PHPUnit_Framework_TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIsSetPasswordWithoutTokenFailing() {
|
public function testIsSetPasswordWithoutTokenFailing() {
|
||||||
$this->container['Config']
|
$this->config
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getUserValue')
|
->method('getUserValue')
|
||||||
->with('ValidTokenUser', 'owncloud', 'lostpassword', null)
|
->with('ValidTokenUser', 'owncloud', 'lostpassword', null)
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
use OC\Share\MailNotifications;
|
use OC\Share\MailNotifications;
|
||||||
use OCP\IConfig;
|
use OCP\IConfig;
|
||||||
use OCP\IL10N;
|
use OCP\IL10N;
|
||||||
|
use OCP\IUser;
|
||||||
use OCP\Mail\IMailer;
|
use OCP\Mail\IMailer;
|
||||||
use OCP\ILogger;
|
use OCP\ILogger;
|
||||||
use OCP\Defaults;
|
use OCP\Defaults;
|
||||||
|
@ -30,23 +31,21 @@ use OCP\Defaults;
|
||||||
* Class MailNotificationsTest
|
* Class MailNotificationsTest
|
||||||
*/
|
*/
|
||||||
class MailNotificationsTest extends \Test\TestCase {
|
class MailNotificationsTest extends \Test\TestCase {
|
||||||
/** @var IConfig */
|
|
||||||
private $config;
|
|
||||||
/** @var IL10N */
|
/** @var IL10N */
|
||||||
private $l10n;
|
private $l10n;
|
||||||
/** @var IMailer */
|
/** @var IMailer | PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $mailer;
|
private $mailer;
|
||||||
/** @var ILogger */
|
/** @var ILogger */
|
||||||
private $logger;
|
private $logger;
|
||||||
/** @var Defaults */
|
/** @var Defaults | PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $defaults;
|
private $defaults;
|
||||||
|
/** @var IUser | PHPUnit_Framework_MockObject_MockObject */
|
||||||
|
private $user;
|
||||||
|
|
||||||
|
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$this->config = $this->getMockBuilder('\OCP\IConfig')
|
|
||||||
->disableOriginalConstructor()->getMock();
|
|
||||||
$this->l10n = $this->getMockBuilder('\OCP\IL10N')
|
$this->l10n = $this->getMockBuilder('\OCP\IL10N')
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
$this->mailer = $this->getMockBuilder('\OCP\Mail\IMailer')
|
$this->mailer = $this->getMockBuilder('\OCP\Mail\IMailer')
|
||||||
|
@ -55,12 +54,29 @@ class MailNotificationsTest extends \Test\TestCase {
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
$this->defaults = $this->getMockBuilder('\OCP\Defaults')
|
$this->defaults = $this->getMockBuilder('\OCP\Defaults')
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
|
$this->user = $this->getMockBuilder('\OCP\IUser')
|
||||||
|
->disableOriginalConstructor()->getMock();
|
||||||
|
|
||||||
$this->l10n->expects($this->any())
|
$this->l10n->expects($this->any())
|
||||||
->method('t')
|
->method('t')
|
||||||
->will($this->returnCallback(function($text, $parameters = array()) {
|
->will($this->returnCallback(function($text, $parameters = array()) {
|
||||||
return vsprintf($text, $parameters);
|
return vsprintf($text, $parameters);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
$this->defaults
|
||||||
|
->expects($this->once())
|
||||||
|
->method('getName')
|
||||||
|
->will($this->returnValue('UnitTestCloud'));
|
||||||
|
|
||||||
|
$this->user
|
||||||
|
->expects($this->once())
|
||||||
|
->method('getEMailAddress')
|
||||||
|
->willReturn('sharer@owncloud.com');
|
||||||
|
$this->user
|
||||||
|
->expects($this->once())
|
||||||
|
->method('getDisplayName')
|
||||||
|
->willReturn('TestUser');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSendLinkShareMailWithoutReplyTo() {
|
public function testSendLinkShareMailWithoutReplyTo() {
|
||||||
|
@ -96,20 +112,8 @@ class MailNotificationsTest extends \Test\TestCase {
|
||||||
->with($message)
|
->with($message)
|
||||||
->will($this->returnValue([]));
|
->will($this->returnValue([]));
|
||||||
|
|
||||||
$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('sharer@owncloud.com'));
|
|
||||||
|
|
||||||
$mailNotifications = new MailNotifications(
|
$mailNotifications = new MailNotifications(
|
||||||
'TestUser',
|
$this->user,
|
||||||
$this->config,
|
|
||||||
$this->l10n,
|
$this->l10n,
|
||||||
$this->mailer,
|
$this->mailer,
|
||||||
$this->logger,
|
$this->logger,
|
||||||
|
@ -156,20 +160,8 @@ class MailNotificationsTest extends \Test\TestCase {
|
||||||
->with($message)
|
->with($message)
|
||||||
->will($this->returnValue([]));
|
->will($this->returnValue([]));
|
||||||
|
|
||||||
$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('sharer@owncloud.com'));
|
|
||||||
|
|
||||||
$mailNotifications = new MailNotifications(
|
$mailNotifications = new MailNotifications(
|
||||||
'TestUser',
|
$this->user,
|
||||||
$this->config,
|
|
||||||
$this->l10n,
|
$this->l10n,
|
||||||
$this->mailer,
|
$this->mailer,
|
||||||
$this->logger,
|
$this->logger,
|
||||||
|
@ -179,17 +171,65 @@ class MailNotificationsTest extends \Test\TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSendLinkShareMailException() {
|
public function testSendLinkShareMailException() {
|
||||||
|
$this->setupMailerMock('TestUser shared »MyFile« with you', ['lukas@owncloud.com']);
|
||||||
|
|
||||||
|
$mailNotifications = new MailNotifications(
|
||||||
|
$this->user,
|
||||||
|
$this->l10n,
|
||||||
|
$this->mailer,
|
||||||
|
$this->logger,
|
||||||
|
$this->defaults
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertSame(['lukas@owncloud.com'], $mailNotifications->sendLinkShareMail('lukas@owncloud.com', 'MyFile', 'https://owncloud.com/file/?foo=bar', 3600));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSendInternalShareMail() {
|
||||||
|
$this->setupMailerMock('TestUser shared »welcome.txt« with you', ['recipient@owncloud.com' => 'Recipient'], false);
|
||||||
|
|
||||||
|
/** @var MailNotifications | PHPUnit_Framework_MockObject_MockObject $mailNotifications */
|
||||||
|
$mailNotifications = $this->getMock('OC\Share\MailNotifications',['getItemSharedWithUser'], [
|
||||||
|
$this->user,
|
||||||
|
$this->l10n,
|
||||||
|
$this->mailer,
|
||||||
|
$this->logger,
|
||||||
|
$this->defaults]);
|
||||||
|
|
||||||
|
$mailNotifications->method('getItemSharedWithUser')
|
||||||
|
->withAnyParameters()
|
||||||
|
->willReturn([
|
||||||
|
['file_target' => '/welcome.txt']
|
||||||
|
]);
|
||||||
|
|
||||||
|
$recipient = $this->getMockBuilder('\OCP\IUser')
|
||||||
|
->disableOriginalConstructor()->getMock();
|
||||||
|
$recipient
|
||||||
|
->expects($this->once())
|
||||||
|
->method('getEMailAddress')
|
||||||
|
->willReturn('recipient@owncloud.com');
|
||||||
|
$recipient
|
||||||
|
->expects($this->once())
|
||||||
|
->method('getDisplayName')
|
||||||
|
->willReturn('Recipient');
|
||||||
|
|
||||||
|
$recipientList = [$recipient];
|
||||||
|
$result = $mailNotifications->sendInternalShareMail($recipientList, '3', 'file');
|
||||||
|
$this->assertSame([], $result);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function setupMailerMock($subject, $to, $exceptionOnSend = true) {
|
||||||
$message = $this->getMockBuilder('\OC\Mail\Message')
|
$message = $this->getMockBuilder('\OC\Mail\Message')
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
|
|
||||||
$message
|
$message
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('setSubject')
|
->method('setSubject')
|
||||||
->with('TestUser shared »MyFile« with you');
|
->with($subject);
|
||||||
$message
|
$message
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('setTo')
|
->method('setTo')
|
||||||
->with(['lukas@owncloud.com']);
|
->with($to);
|
||||||
$message
|
$message
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('setHtmlBody');
|
->method('setHtmlBody');
|
||||||
|
@ -205,33 +245,12 @@ class MailNotificationsTest extends \Test\TestCase {
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('createMessage')
|
->method('createMessage')
|
||||||
->will($this->returnValue($message));
|
->will($this->returnValue($message));
|
||||||
|
if ($exceptionOnSend) {
|
||||||
$this->mailer
|
$this->mailer
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('send')
|
->method('send')
|
||||||
->with($message)
|
->with($message)
|
||||||
->will($this->throwException(new Exception('Some Exception 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('sharer@owncloud.com'));
|
|
||||||
|
|
||||||
$mailNotifications = new MailNotifications(
|
|
||||||
'TestUser',
|
|
||||||
$this->config,
|
|
||||||
$this->l10n,
|
|
||||||
$this->mailer,
|
|
||||||
$this->logger,
|
|
||||||
$this->defaults
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertSame(['lukas@owncloud.com'], $mailNotifications->sendLinkShareMail('lukas@owncloud.com', 'MyFile', 'https://owncloud.com/file/?foo=bar', 3600));
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,8 @@ use OCP\AppFramework\Http;
|
||||||
use OCP\AppFramework\Http\DataResponse;
|
use OCP\AppFramework\Http\DataResponse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @group DB
|
||||||
|
*
|
||||||
* @package OC\Settings\Controller
|
* @package OC\Settings\Controller
|
||||||
*/
|
*/
|
||||||
class UsersControllerTest extends \Test\TestCase {
|
class UsersControllerTest extends \Test\TestCase {
|
||||||
|
@ -60,13 +62,17 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
$foo = $this->getMockBuilder('\OC\User\User')
|
$foo = $this->getMockBuilder('\OC\User\User')
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
$foo
|
$foo
|
||||||
->expects($this->exactly(3))
|
->expects($this->exactly(2))
|
||||||
->method('getUID')
|
->method('getUID')
|
||||||
->will($this->returnValue('foo'));
|
->will($this->returnValue('foo'));
|
||||||
$foo
|
$foo
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getDisplayName')
|
->method('getDisplayName')
|
||||||
->will($this->returnValue('M. Foo'));
|
->will($this->returnValue('M. Foo'));
|
||||||
|
$foo
|
||||||
|
->expects($this->once())
|
||||||
|
->method('getEMailAddress')
|
||||||
|
->will($this->returnValue('foo@bar.com'));
|
||||||
$foo
|
$foo
|
||||||
->method('getLastLogin')
|
->method('getLastLogin')
|
||||||
->will($this->returnValue(500));
|
->will($this->returnValue(500));
|
||||||
|
@ -80,13 +86,17 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
$admin = $this->getMockBuilder('\OC\User\User')
|
$admin = $this->getMockBuilder('\OC\User\User')
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
$admin
|
$admin
|
||||||
->expects($this->exactly(3))
|
->expects($this->exactly(2))
|
||||||
->method('getUID')
|
->method('getUID')
|
||||||
->will($this->returnValue('admin'));
|
->will($this->returnValue('admin'));
|
||||||
$admin
|
$admin
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getDisplayName')
|
->method('getDisplayName')
|
||||||
->will($this->returnValue('S. Admin'));
|
->will($this->returnValue('S. Admin'));
|
||||||
|
$admin
|
||||||
|
->expects($this->once())
|
||||||
|
->method('getEMailAddress')
|
||||||
|
->will($this->returnValue('admin@bar.com'));
|
||||||
$admin
|
$admin
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getLastLogin')
|
->method('getLastLogin')
|
||||||
|
@ -102,13 +112,17 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
$bar = $this->getMockBuilder('\OC\User\User')
|
$bar = $this->getMockBuilder('\OC\User\User')
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
$bar
|
$bar
|
||||||
->expects($this->exactly(3))
|
->expects($this->exactly(2))
|
||||||
->method('getUID')
|
->method('getUID')
|
||||||
->will($this->returnValue('bar'));
|
->will($this->returnValue('bar'));
|
||||||
$bar
|
$bar
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getDisplayName')
|
->method('getDisplayName')
|
||||||
->will($this->returnValue('B. Ar'));
|
->will($this->returnValue('B. Ar'));
|
||||||
|
$bar
|
||||||
|
->expects($this->once())
|
||||||
|
->method('getEMailAddress')
|
||||||
|
->will($this->returnValue('bar@dummy.com'));
|
||||||
$bar
|
$bar
|
||||||
->method('getLastLogin')
|
->method('getLastLogin')
|
||||||
->will($this->returnValue(3999));
|
->will($this->returnValue(3999));
|
||||||
|
@ -145,11 +159,11 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
->with('bar')
|
->with('bar')
|
||||||
->will($this->returnValue($bar));
|
->will($this->returnValue($bar));
|
||||||
$this->container['Config']
|
$this->container['Config']
|
||||||
->expects($this->exactly(6))
|
->expects($this->exactly(3))
|
||||||
->method('getUserValue')
|
->method('getUserValue')
|
||||||
->will($this->onConsecutiveCalls(1024, 'foo@bar.com',
|
->will($this->onConsecutiveCalls(1024,
|
||||||
404, 'admin@bar.com',
|
404,
|
||||||
2323, 'bar@dummy.com'));
|
2323));
|
||||||
|
|
||||||
$subadmin = $this->getMockBuilder('\OC\SubAdmin')
|
$subadmin = $this->getMockBuilder('\OC\SubAdmin')
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
|
@ -232,13 +246,17 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
$foo = $this->getMockBuilder('\OC\User\User')
|
$foo = $this->getMockBuilder('\OC\User\User')
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
$foo
|
$foo
|
||||||
->expects($this->exactly(3))
|
->expects($this->exactly(2))
|
||||||
->method('getUID')
|
->method('getUID')
|
||||||
->will($this->returnValue('foo'));
|
->will($this->returnValue('foo'));
|
||||||
$foo
|
$foo
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getDisplayName')
|
->method('getDisplayName')
|
||||||
->will($this->returnValue('M. Foo'));
|
->will($this->returnValue('M. Foo'));
|
||||||
|
$foo
|
||||||
|
->expects($this->once())
|
||||||
|
->method('getEMailAddress')
|
||||||
|
->will($this->returnValue('foo@bar.com'));
|
||||||
$foo
|
$foo
|
||||||
->method('getLastLogin')
|
->method('getLastLogin')
|
||||||
->will($this->returnValue(500));
|
->will($this->returnValue(500));
|
||||||
|
@ -252,13 +270,17 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
$admin = $this->getMockBuilder('\OC\User\User')
|
$admin = $this->getMockBuilder('\OC\User\User')
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
$admin
|
$admin
|
||||||
->expects($this->exactly(3))
|
->expects($this->exactly(2))
|
||||||
->method('getUID')
|
->method('getUID')
|
||||||
->will($this->returnValue('admin'));
|
->will($this->returnValue('admin'));
|
||||||
$admin
|
$admin
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getDisplayName')
|
->method('getDisplayName')
|
||||||
->will($this->returnValue('S. Admin'));
|
->will($this->returnValue('S. Admin'));
|
||||||
|
$admin
|
||||||
|
->expects($this->once())
|
||||||
|
->method('getEMailAddress')
|
||||||
|
->will($this->returnValue('admin@bar.com'));
|
||||||
$admin
|
$admin
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getLastLogin')
|
->method('getLastLogin')
|
||||||
|
@ -274,13 +296,17 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
$bar = $this->getMockBuilder('\OC\User\User')
|
$bar = $this->getMockBuilder('\OC\User\User')
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
$bar
|
$bar
|
||||||
->expects($this->exactly(3))
|
->expects($this->exactly(2))
|
||||||
->method('getUID')
|
->method('getUID')
|
||||||
->will($this->returnValue('bar'));
|
->will($this->returnValue('bar'));
|
||||||
$bar
|
$bar
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getDisplayName')
|
->method('getDisplayName')
|
||||||
->will($this->returnValue('B. Ar'));
|
->will($this->returnValue('B. Ar'));
|
||||||
|
$bar
|
||||||
|
->expects($this->once())
|
||||||
|
->method('getEMailAddress')
|
||||||
|
->will($this->returnValue('bar@dummy.com'));
|
||||||
$bar
|
$bar
|
||||||
->method('getLastLogin')
|
->method('getLastLogin')
|
||||||
->will($this->returnValue(3999));
|
->will($this->returnValue(3999));
|
||||||
|
@ -326,12 +352,12 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
->with('admin')
|
->with('admin')
|
||||||
->will($this->returnValue($admin));
|
->will($this->returnValue($admin));
|
||||||
$this->container['Config']
|
$this->container['Config']
|
||||||
->expects($this->exactly(6))
|
->expects($this->exactly(3))
|
||||||
->method('getUserValue')
|
->method('getUserValue')
|
||||||
->will($this->onConsecutiveCalls(
|
->will($this->onConsecutiveCalls(
|
||||||
2323, 'bar@dummy.com',
|
2323,
|
||||||
1024, 'foo@bar.com',
|
1024,
|
||||||
404, 'admin@bar.com'
|
404
|
||||||
));
|
));
|
||||||
|
|
||||||
$subgroup1 = $this->getMockBuilder('\OCP\IGroup')
|
$subgroup1 = $this->getMockBuilder('\OCP\IGroup')
|
||||||
|
@ -417,13 +443,17 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
$foo = $this->getMockBuilder('\OC\User\User')
|
$foo = $this->getMockBuilder('\OC\User\User')
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
$foo
|
$foo
|
||||||
->expects($this->exactly(3))
|
->expects($this->exactly(2))
|
||||||
->method('getUID')
|
->method('getUID')
|
||||||
->will($this->returnValue('foo'));
|
->will($this->returnValue('foo'));
|
||||||
$foo
|
$foo
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getDisplayName')
|
->method('getDisplayName')
|
||||||
->will($this->returnValue('M. Foo'));
|
->will($this->returnValue('M. Foo'));
|
||||||
|
$foo
|
||||||
|
->expects($this->once())
|
||||||
|
->method('getEMailAddress')
|
||||||
|
->will($this->returnValue('foo@bar.com'));
|
||||||
$foo
|
$foo
|
||||||
->method('getLastLogin')
|
->method('getLastLogin')
|
||||||
->will($this->returnValue(500));
|
->will($this->returnValue(500));
|
||||||
|
@ -437,13 +467,17 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
$admin = $this->getMockBuilder('\OC\User\User')
|
$admin = $this->getMockBuilder('\OC\User\User')
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
$admin
|
$admin
|
||||||
->expects($this->exactly(3))
|
->expects($this->exactly(2))
|
||||||
->method('getUID')
|
->method('getUID')
|
||||||
->will($this->returnValue('admin'));
|
->will($this->returnValue('admin'));
|
||||||
$admin
|
$admin
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getDisplayName')
|
->method('getDisplayName')
|
||||||
->will($this->returnValue('S. Admin'));
|
->will($this->returnValue('S. Admin'));
|
||||||
|
$admin
|
||||||
|
->expects($this->once())
|
||||||
|
->method('getEMailAddress')
|
||||||
|
->will($this->returnValue('admin@bar.com'));
|
||||||
$admin
|
$admin
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getLastLogin')
|
->method('getLastLogin')
|
||||||
|
@ -459,13 +493,17 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
$bar = $this->getMockBuilder('\OC\User\User')
|
$bar = $this->getMockBuilder('\OC\User\User')
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
$bar
|
$bar
|
||||||
->expects($this->exactly(3))
|
->expects($this->exactly(2))
|
||||||
->method('getUID')
|
->method('getUID')
|
||||||
->will($this->returnValue('bar'));
|
->will($this->returnValue('bar'));
|
||||||
$bar
|
$bar
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getDisplayName')
|
->method('getDisplayName')
|
||||||
->will($this->returnValue('B. Ar'));
|
->will($this->returnValue('B. Ar'));
|
||||||
|
$bar
|
||||||
|
->expects($this->once())
|
||||||
|
->method('getEMailAddress')
|
||||||
|
->will($this->returnValue('bar@dummy.com'));
|
||||||
$bar
|
$bar
|
||||||
->method('getLastLogin')
|
->method('getLastLogin')
|
||||||
->will($this->returnValue(3999));
|
->will($this->returnValue(3999));
|
||||||
|
@ -487,11 +525,9 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
->method('getUserGroupIds')
|
->method('getUserGroupIds')
|
||||||
->will($this->onConsecutiveCalls(array('Users', 'Support'), array('admins', 'Support'), array('External Users')));
|
->will($this->onConsecutiveCalls(array('Users', 'Support'), array('admins', 'Support'), array('External Users')));
|
||||||
$this->container['Config']
|
$this->container['Config']
|
||||||
->expects($this->exactly(6))
|
->expects($this->exactly(3))
|
||||||
->method('getUserValue')
|
->method('getUserValue')
|
||||||
->will($this->onConsecutiveCalls(1024, 'foo@bar.com',
|
->will($this->onConsecutiveCalls(1024, 404, 2323));
|
||||||
404, 'admin@bar.com',
|
|
||||||
2323, 'bar@dummy.com'));
|
|
||||||
|
|
||||||
$subadmin = $this->getMockBuilder('\OC\SubAdmin')
|
$subadmin = $this->getMockBuilder('\OC\SubAdmin')
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
|
@ -554,13 +590,17 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
$user = $this->getMockBuilder('\OC\User\User')
|
$user = $this->getMockBuilder('\OC\User\User')
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
$user
|
$user
|
||||||
->expects($this->exactly(3))
|
->expects($this->exactly(2))
|
||||||
->method('getUID')
|
->method('getUID')
|
||||||
->will($this->returnValue('foo'));
|
->will($this->returnValue('foo'));
|
||||||
$user
|
$user
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getDisplayName')
|
->method('getDisplayName')
|
||||||
->will($this->returnValue('M. Foo'));
|
->will($this->returnValue('M. Foo'));
|
||||||
|
$user
|
||||||
|
->expects($this->once())
|
||||||
|
->method('getEMailAddress')
|
||||||
|
->will($this->returnValue(null));
|
||||||
$user
|
$user
|
||||||
->method('getLastLogin')
|
->method('getLastLogin')
|
||||||
->will($this->returnValue(500));
|
->will($this->returnValue(500));
|
||||||
|
|
Loading…
Reference in New Issue