use OCP\IUserManager;
use OCP\Mail\IMailer;
use OCP\Security\ISecureRandom;
+use OCP\Util;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Helper\Table;
$progress = new ProgressBar($this->output, count($this->userPasswords));
$progress->start();
- foreach ($this->userPasswords as $recipient => $password) {
+ foreach ($this->userPasswords as $uid => $password) {
$progress->advance();
if (!empty($password)) {
- $recipientDisplayName = $this->userManager->get($recipient)->getDisplayName();
- $to = $this->config->getUserValue($recipient, 'settings', 'email', '');
+ $recipient = $this->userManager->get($uid);
+ $recipientDisplayName = $recipient->getDisplayName();
+ $to = $recipient->getEMailAddress();
if ($to === '') {
- $noMail[] = $recipient;
+ $noMail[] = $uid;
continue;
}
$message->setHtmlBody($htmlBody);
$message->setPlainBody($textBody);
$message->setFrom([
- \OCP\Util::getDefaultEmailAddress('admin-noreply')
+ Util::getDefaultEmailAddress('admin-noreply')
]);
$this->mailer->send($message);
} catch (\Exception $e) {
- $noMail[] = $recipient;
+ $noMail[] = $uid;
}
}
}
// Find the data
$data['quota'] = $this->fillStorageInfo($userId);
- $data['email'] = $this->config->getUserValue($userId, 'settings', 'email');
+ $data['email'] = $targetUserObject->getEMailAddress();
$data['displayname'] = $targetUserObject->getDisplayName();
return new OC_OCS_Result($data);
namespace OCA\Provisioning_API\Tests;
use OCA\Provisioning_API\Users;
+use OCP\API;
use OCP\IUserManager;
use OCP\IConfig;
-use OCP\IGroupManager;
use OCP\IUserSession;
+use PHPUnit_Framework_MockObject_MockObject;
use Test\TestCase as OriginalTest;
use OCP\ILogger;
class UsersTest extends OriginalTest {
- /** @var IUserManager */
+ /** @var IUserManager | PHPUnit_Framework_MockObject_MockObject */
protected $userManager;
- /** @var IConfig */
+ /** @var IConfig | PHPUnit_Framework_MockObject_MockObject */
protected $config;
- /** @var \OC\Group\Manager */
+ /** @var \OC\Group\Manager | PHPUnit_Framework_MockObject_MockObject */
protected $groupManager;
- /** @var IUserSession */
+ /** @var IUserSession | PHPUnit_Framework_MockObject_MockObject */
protected $userSession;
- /** @var ILogger */
+ /** @var ILogger | PHPUnit_Framework_MockObject_MockObject */
protected $logger;
- /** @var Users */
+ /** @var Users | PHPUnit_Framework_MockObject_MockObject */
protected $api;
protected function tearDown() {
->method('getUser')
->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());
}
->method('getSubAdmin')
->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());
}
->with()
->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());
}
->method('getUser')
->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']));
}
->with('UserToGet')
->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']));
}
->method('getUID')
->will($this->returnValue('admin'));
$targetUser = $this->getMock('\OCP\IUser');
+ $targetUser->expects($this->once())
+ ->method('getEMailAddress')
+ ->willReturn('demo@owncloud.org');
$this->userSession
->expects($this->once())
->method('getUser')
->method('fillStorageInfo')
->with('UserToGet')
->will($this->returnValue(['DummyValue']));
- $this->config
- ->expects($this->at(1))
- ->method('getUserValue')
- ->with('UserToGet', 'settings', 'email')
- ->will($this->returnValue('demo@owncloud.org'));
$targetUser
->expects($this->once())
->method('getDisplayName')
->method('getUID')
->will($this->returnValue('subadmin'));
$targetUser = $this->getMock('\OCP\IUser');
+ $targetUser
+ ->expects($this->once())
+ ->method('getEMailAddress')
+ ->willReturn('demo@owncloud.org');
$this->userSession
->expects($this->once())
->method('getUser')
->method('fillStorageInfo')
->with('UserToGet')
->will($this->returnValue(['DummyValue']));
- $this->config
- ->expects($this->at(1))
- ->method('getUserValue')
- ->with('UserToGet', 'settings', 'email')
- ->will($this->returnValue('demo@owncloud.org'));
$targetUser
->expects($this->once())
->method('getDisplayName')
->method('getSubAdmin')
->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']));
}
->method('fillStorageInfo')
->with('subadmin')
->will($this->returnValue(['DummyValue']));
- $this->config
- ->expects($this->once())
- ->method('getUserValue')
- ->with('subadmin', 'settings', 'email')
- ->will($this->returnValue('subadmin@owncloud.org'));
$targetUser
->expects($this->once())
->method('getDisplayName')
->will($this->returnValue('Subadmin User'));
+ $targetUser
+ ->expects($this->once())
+ ->method('getEMailAddress')
+ ->will($this->returnValue('subadmin@owncloud.org'));
$expected = new \OC_OCS_Result([
'quota' => ['DummyValue'],
->method('getUser')
->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']));
}
*
*/
+use OCP\IUser;
+
OC_JSON::checkLoggedIn();
OCP\JSON::callCheck();
$itemSource = (string)$_POST['itemSource'];
$recipient = (string)$_POST['recipient'];
+ $userManager = \OC::$server->getUserManager();
+ $recipientList = [];
if($shareType === \OCP\Share::SHARE_TYPE_USER) {
- $recipientList[] = $recipient;
+ $recipientList[] = $userManager->get($recipient);
} elseif ($shareType === \OCP\Share::SHARE_TYPE_GROUP) {
$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
- $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(
- \OC::$server->getUserSession()->getUser()->getUID(),
- \OC::$server->getConfig(),
+ \OC::$server->getUserSession()->getUser(),
\OC::$server->getL10N('lib'),
\OC::$server->getMailer(),
\OC::$server->getLogger(),
$to_address = (string)$_POST['toaddress'];
$mailNotification = new \OC\Share\MailNotifications(
- \OC::$server->getUserSession()->getUser()->getUID(),
- \OC::$server->getConfig(),
+ \OC::$server->getUserSession()->getUser(),
\OC::$server->getL10N('lib'),
\OC::$server->getMailer(),
\OC::$server->getLogger(),
} catch (Exception $e) {
\OCP\Util::writeLog('sharing', "Couldn't read date: " . $e->getMessage(), \OCP\Util::ERROR);
}
-
}
$result = $mailNotification->sendLinkShareMail($to_address, $file, $link, $expiration);
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)) {
throw new \Exception(
- $this->l10n->t('Couldn\'t send reset email because there is no '.
- 'email address for this username. Please ' .
- 'contact your administrator.')
+ $this->l10n->t('Could not send reset email because there is no email address for this username. Please contact your administrator.')
);
}
}
public static function getCurrentUser() {
- $email=\OC::$server->getConfig()->getUserValue(OC_User::getUser(), 'settings', 'email', '');
+ $userObject = \OC::$server->getUserManager()->get(OC_User::getUser());
$data = array(
- 'id' => OC_User::getUser(),
- 'display-name' => OC_User::getDisplayName(),
- 'email' => $email,
+ 'id' => $userObject->getUID(),
+ 'display-name' => $userObject->getDisplayName(),
+ 'email' => $userObject->getEMailAddress(),
);
return new OC_OCS_Result($data);
}
namespace OC\Share;
use DateTime;
-use OCP\IConfig;
use OCP\IL10N;
+use OCP\IUser;
use OCP\Mail\IMailer;
use OCP\ILogger;
use OCP\Defaults;
+use OCP\Util;
/**
* Class MailNotifications
*/
class MailNotifications {
- /** @var string sender userId */
- private $userId;
+ /** @var IUser sender userId */
+ private $user;
/** @var string sender email address */
private $replyTo;
/** @var string */
private $senderDisplayName;
/** @var IL10N */
private $l;
- /** @var IConfig */
- private $config;
/** @var IMailer */
private $mailer;
/** @var Defaults */
private $logger;
/**
- * @param string $uid user id
- * @param IConfig $config
+ * @param IUser $user
* @param IL10N $l10n
* @param IMailer $mailer
* @param ILogger $logger
* @param Defaults $defaults
*/
- public function __construct($uid,
- IConfig $config,
+ public function __construct(IUser $user,
IL10N $l10n,
IMailer $mailer,
ILogger $logger,
Defaults $defaults) {
$this->l = $l10n;
- $this->userId = $uid;
- $this->config = $config;
+ $this->user = $user;
$this->mailer = $mailer;
$this->logger = $logger;
$this->defaults = $defaults;
- $this->replyTo = $this->config->getUserValue($this->userId, 'settings', 'email', null);
- $this->senderDisplayName = \OCP\User::getDisplayName($this->userId);
+ $this->replyTo = $this->user->getEMailAddress();
+ $this->senderDisplayName = $this->user->getDisplayName();
}
/**
* 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 $itemType shared item type
* @return array list of user to whom the mail send operation failed
$noMail = [];
foreach ($recipientList as $recipient) {
- $recipientDisplayName = \OCP\User::getDisplayName($recipient);
- $to = $this->config->getUserValue($recipient, 'settings', 'email', '');
+ $recipientDisplayName = $recipient->getDisplayName();
+ $to = $recipient->getEMailAddress();
if ($to === '') {
$noMail[] = $recipientDisplayName;
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());
+ }
+
}
* @since 9.0.0
*/
public function getEMailAddress() {
- return $this->config->getUserValue($this->uid, 'settings', 'email');
+ return $this->config->getUserValue($this->uid, 'settings', 'email', null);
}
/**
$subAdminGroups[$key] = $subAdminGroup->getGID();
}
+ $displayName = $user->getEMailAddress();
+ if (is_null($displayName)) {
+ $displayName = '';
+ }
return [
'name' => $user->getUID(),
'displayname' => $user->getDisplayName(),
'storageLocation' => $user->getHome(),
'lastLogin' => $user->getLastLogin() * 1000,
'backend' => $user->getBackendClassName(),
- 'email' => $this->config->getUserValue($user->getUID(), 'settings', 'email', ''),
+ 'email' => $displayName,
'isRestoreDisabled' => !$restorePossible,
];
}
}
// Highlight navigation entry
-OC_App::setActiveNavigationEntry( 'personal' );
+OC::$server->getNavigationManager()->setActiveEntry('personal');
$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() );
$languageCodes=OC_L10N::findAvailableLanguages();
// 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'
);
$languageNames=include 'languageCodes.php';
$languages=array();
-$commonlanguages = array();
+$commonLanguages = array();
foreach($languageCodes as $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
$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
if ($lang === $userLang) {
$userLang = $ln;
- } elseif (in_array($lang, $commonlangcodes)) {
- $commonlanguages[array_search($lang, $commonlangcodes)]=$ln;
+ } elseif (in_array($lang, $commonLangCodes)) {
+ $commonLanguages[array_search($lang, $commonLangCodes)]=$ln;
} else {
$languages[]=$ln;
}
];
}
-ksort($commonlanguages);
+ksort($commonLanguages);
// sort now by displayed language not the iso-code
usort( $languages, function ($a, $b) {
$tmpl->assign('clients', $clients);
$tmpl->assign('email', $email);
$tmpl->assign('languages', $languages);
-$tmpl->assign('commonlanguages', $commonlanguages);
+$tmpl->assign('commonlanguages', $commonLanguages);
$tmpl->assign('activelanguage', $userLang);
$tmpl->assign('passwordChangeSupported', OC_User::canUserChangePassword(OC_User::getUser()));
$tmpl->assign('displayNameChangeSupported', OC_User::canUserChangeDisplayName(OC_User::getUser()));
*/
namespace OC\Core\LostPassword\Controller;
-use OC\Core\Application;
+
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 extends \PHPUnit_Framework_TestCase {
- private $container;
/** @var 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() {
- $app = new Application();
- $this->container = $app->getContainer();
- $this->container['AppName'] = 'core';
- $this->container['Config'] = $this->getMockBuilder('\OCP\IConfig')
+
+ $this->existingUser = $this->getMockBuilder('OCP\IUser')
+ ->disableOriginalConstructor()->getMock();
+
+ $this->existingUser
+ ->expects($this->any())
+ ->method('getEMailAddress')
+ ->willReturn('test@example.com');
+
+ $this->config = $this->getMockBuilder('\OCP\IConfig')
->disableOriginalConstructor()->getMock();
- $this->container['L10N'] = $this->getMockBuilder('\OCP\IL10N')
+ $this->l10n = $this->getMockBuilder('\OCP\IL10N')
->disableOriginalConstructor()->getMock();
- $this->container['L10N']
+ $this->l10n
->expects($this->any())
->method('t')
->will($this->returnCallback(function($text, $parameters = array()) {
return vsprintf($text, $parameters);
}));
- $this->container['Defaults'] = $this->getMockBuilder('\OC_Defaults')
+ $this->defaults = $this->getMockBuilder('\OC_Defaults')
->disableOriginalConstructor()->getMock();
- $this->container['UserManager'] = $this->getMockBuilder('\OCP\IUserManager')
+ $this->userManager = $this->getMockBuilder('\OCP\IUserManager')
->disableOriginalConstructor()->getMock();
- $this->container['Config'] = $this->getMockBuilder('\OCP\IConfig')
+ $this->urlGenerator = $this->getMockBuilder('\OCP\IURLGenerator')
->disableOriginalConstructor()->getMock();
- $this->container['URLGenerator'] = $this->getMockBuilder('\OCP\IURLGenerator')
+ $this->mailer = $this->getMockBuilder('\OCP\Mail\IMailer')
->disableOriginalConstructor()->getMock();
- $this->container['Mailer'] = $this->getMockBuilder('\OCP\Mail\IMailer')
+ $this->secureRandom = $this->getMockBuilder('\OCP\Security\ISecureRandom')
->disableOriginalConstructor()->getMock();
- $this->container['SecureRandom'] = $this->getMockBuilder('\OCP\Security\ISecureRandom')
+ $this->timeFactory = $this->getMockBuilder('\OCP\AppFramework\Utility\ITimeFactory')
->disableOriginalConstructor()->getMock();
- $this->container['TimeFactory'] = $this->getMockBuilder('\OCP\AppFramework\Utility\ITimeFactory')
+ $this->request = $this->getMockBuilder('OCP\IRequest')
->disableOriginalConstructor()->getMock();
- $this->container['IsEncryptionEnabled'] = true;
- $this->lostController = $this->container['LostController'];
+ $this->lostController = new 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() {
$userId = 'admin';
$token = 'MySecretToken';
- $this->container['URLGenerator']
+ $this->urlGenerator
->expects($this->once())
->method('linkToRouteAbsolute')
->with('core.lost.setPassword', array('userId' => 'admin', 'token' => 'MySecretToken'))
public function testEmailUnsucessful() {
$existingUser = 'ExistingUser';
$nonExistingUser = 'NonExistingUser';
- $this->container['UserManager']
+ $this->userManager
->expects($this->any())
->method('userExists')
->will($this->returnValueMap(array(
$this->assertSame($expectedResponse, $response);
// With no mail address
- $this->container['Config']
+ $this->config
->expects($this->any())
->method('getUserValue')
->with($existingUser, 'settings', 'email')
}
public function testEmailSuccessful() {
- $randomToken = $this->container['SecureRandom'];
- $this->container['SecureRandom']
+ $randomToken = $this->secureRandom;
+ $this->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['TimeFactory']
+ $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->timeFactory
->expects($this->once())
->method('getTime')
->will($this->returnValue(12348));
- $this->container['Config']
- ->expects($this->once())
- ->method('getUserValue')
- ->with('ExistingUser', 'settings', 'email')
- ->will($this->returnValue('test@example.com'));
- $this->container['SecureRandom']
+ $this->secureRandom
->expects($this->once())
->method('getMediumStrengthGenerator')
->will($this->returnValue($randomToken));
- $this->container['Config']
+ $this->config
->expects($this->once())
->method('setUserValue')
->with('ExistingUser', 'owncloud', 'lostpassword', '12348:ThisIsMaybeANotSoSecretToken!');
- $this->container['URLGenerator']
+ $this->urlGenerator
->expects($this->once())
->method('linkToRouteAbsolute')
->with('core.lost.resetform', array('userId' => 'ExistingUser', 'token' => 'ThisIsMaybeANotSoSecretToken!'))
->expects($this->at(3))
->method('setFrom')
->with(['lostpassword-noreply@localhost' => null]);
- $this->container['Mailer']
+ $this->mailer
->expects($this->at(0))
->method('createMessage')
->will($this->returnValue($message));
- $this->container['Mailer']
+ $this->mailer
->expects($this->at(1))
->method('send')
->with($message);
}
public function testEmailCantSendException() {
- $randomToken = $this->container['SecureRandom'];
- $this->container['SecureRandom']
+ $randomToken = $this->secureRandom;
+ $this->secureRandom
->expects($this->once())
->method('generate')
->with('21')
->will($this->returnValue('ThisIsMaybeANotSoSecretToken!'));
- $this->container['UserManager']
+ $this->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('test@example.com'));
- $this->container['SecureRandom']
+ $this->userManager
+ ->expects($this->any())
+ ->method('get')
+ ->with('ExistingUser')
+ ->willReturn($this->existingUser);
+ $this->secureRandom
->expects($this->once())
->method('getMediumStrengthGenerator')
->will($this->returnValue($randomToken));
- $this->container['Config']
+ $this->config
->expects($this->once())
->method('setUserValue')
->with('ExistingUser', 'owncloud', 'lostpassword', '12348:ThisIsMaybeANotSoSecretToken!');
- $this->container['TimeFactory']
+ $this->timeFactory
->expects($this->once())
->method('getTime')
->will($this->returnValue(12348));
- $this->container['URLGenerator']
+ $this->urlGenerator
->expects($this->once())
->method('linkToRouteAbsolute')
->with('core.lost.resetform', array('userId' => 'ExistingUser', 'token' => 'ThisIsMaybeANotSoSecretToken!'))
->expects($this->at(3))
->method('setFrom')
->with(['lostpassword-noreply@localhost' => null]);
- $this->container['Mailer']
+ $this->mailer
->expects($this->at(0))
->method('createMessage')
->will($this->returnValue($message));
- $this->container['Mailer']
+ $this->mailer
->expects($this->at(1))
->method('send')
->with($message)
}
public function testSetPasswordUnsuccessful() {
- $this->container['Config']
+ $this->config
->expects($this->once())
->method('getUserValue')
->with('InvalidTokenUser', 'owncloud', 'lostpassword', null)
}
public function testSetPasswordSuccessful() {
- $this->container['Config']
+ $this->config
->expects($this->once())
->method('getUserValue')
->with('ValidTokenUser', 'owncloud', 'lostpassword', null)
->method('setPassword')
->with('NewPassword')
->will($this->returnValue(true));
- $this->container['UserManager']
+ $this->userManager
->expects($this->once())
->method('get')
->with('ValidTokenUser')
->will($this->returnValue($user));
- $this->container['Config']
+ $this->config
->expects($this->once())
->method('deleteUserValue')
->with('ValidTokenUser', 'owncloud', 'lostpassword');
- $this->container['TimeFactory']
+ $this->timeFactory
->expects($this->once())
->method('getTime')
->will($this->returnValue(12348));
}
public function testSetPasswordExpiredToken() {
- $this->container['Config']
+ $this->config
->expects($this->once())
->method('getUserValue')
->with('ValidTokenUser', 'owncloud', 'lostpassword', null)
->will($this->returnValue('12345:TheOnlyAndOnlyOneTokenToResetThePassword'));
$user = $this->getMockBuilder('\OCP\IUser')
->disableOriginalConstructor()->getMock();
- $this->container['UserManager']
+ $this->userManager
->expects($this->once())
->method('get')
->with('ValidTokenUser')
->will($this->returnValue($user));
- $this->container['TimeFactory']
+ $this->timeFactory
->expects($this->once())
->method('getTime')
->will($this->returnValue(55546));
}
public function testSetPasswordInvalidDataInDb() {
- $this->container['Config']
+ $this->config
->expects($this->once())
->method('getUserValue')
->with('ValidTokenUser', 'owncloud', 'lostpassword', null)
->will($this->returnValue('TheOnlyAndOnlyOneTokenToResetThePassword'));
$user = $this->getMockBuilder('\OCP\IUser')
->disableOriginalConstructor()->getMock();
- $this->container['UserManager']
+ $this->userManager
->expects($this->once())
->method('get')
->with('ValidTokenUser')
}
public function testSetPasswordExpiredTokenDueToLogin() {
- $this->container['Config']
+ $this->config
->expects($this->once())
->method('getUserValue')
->with('ValidTokenUser', 'owncloud', 'lostpassword', null)
->expects($this->once())
->method('getLastLogin')
->will($this->returnValue(12346));
- $this->container['UserManager']
+ $this->userManager
->expects($this->once())
->method('get')
->with('ValidTokenUser')
->will($this->returnValue($user));
- $this->container['TimeFactory']
+ $this->timeFactory
->expects($this->once())
->method('getTime')
->will($this->returnValue(12345));
}
public function testIsSetPasswordWithoutTokenFailing() {
- $this->container['Config']
+ $this->config
->expects($this->once())
->method('getUserValue')
->with('ValidTokenUser', 'owncloud', 'lostpassword', null)
use OC\Share\MailNotifications;
use OCP\IConfig;
use OCP\IL10N;
+use OCP\IUser;
use OCP\Mail\IMailer;
use OCP\ILogger;
use OCP\Defaults;
* Class MailNotificationsTest
*/
class MailNotificationsTest extends \Test\TestCase {
- /** @var IConfig */
- private $config;
/** @var IL10N */
private $l10n;
- /** @var IMailer */
+ /** @var IMailer | PHPUnit_Framework_MockObject_MockObject */
private $mailer;
/** @var ILogger */
private $logger;
- /** @var Defaults */
+ /** @var Defaults | PHPUnit_Framework_MockObject_MockObject */
private $defaults;
+ /** @var IUser | PHPUnit_Framework_MockObject_MockObject */
+ private $user;
public function setUp() {
parent::setUp();
- $this->config = $this->getMockBuilder('\OCP\IConfig')
- ->disableOriginalConstructor()->getMock();
$this->l10n = $this->getMockBuilder('\OCP\IL10N')
->disableOriginalConstructor()->getMock();
$this->mailer = $this->getMockBuilder('\OCP\Mail\IMailer')
$this->logger = $this->getMockBuilder('\OCP\ILogger')
->disableOriginalConstructor()->getMock();
$this->defaults = $this->getMockBuilder('\OCP\Defaults')
- ->disableOriginalConstructor()->getMock();
+ ->disableOriginalConstructor()->getMock();
+ $this->user = $this->getMockBuilder('\OCP\IUser')
+ ->disableOriginalConstructor()->getMock();
$this->l10n->expects($this->any())
->method('t')
->will($this->returnCallback(function($text, $parameters = array()) {
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() {
->with($message)
->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(
- 'TestUser',
- $this->config,
+ $this->user,
$this->l10n,
$this->mailer,
$this->logger,
->with($message)
->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(
- 'TestUser',
- $this->config,
+ $this->user,
$this->l10n,
$this->mailer,
$this->logger,
->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('sharer@owncloud.com'));
-
$mailNotifications = new MailNotifications(
- 'TestUser',
- $this->config,
+ $this->user,
$this->l10n,
$this->mailer,
$this->logger,
use OCP\AppFramework\Http\DataResponse;
/**
+ * @group DB
+ *
* @package OC\Settings\Controller
*/
class UsersControllerTest extends \Test\TestCase {
$foo = $this->getMockBuilder('\OC\User\User')
->disableOriginalConstructor()->getMock();
$foo
- ->expects($this->exactly(3))
+ ->expects($this->exactly(2))
->method('getUID')
->will($this->returnValue('foo'));
$foo
->expects($this->once())
->method('getDisplayName')
->will($this->returnValue('M. Foo'));
+ $foo
+ ->expects($this->once())
+ ->method('getEMailAddress')
+ ->will($this->returnValue('foo@bar.com'));
$foo
->method('getLastLogin')
->will($this->returnValue(500));
$admin = $this->getMockBuilder('\OC\User\User')
->disableOriginalConstructor()->getMock();
$admin
- ->expects($this->exactly(3))
+ ->expects($this->exactly(2))
->method('getUID')
->will($this->returnValue('admin'));
$admin
->expects($this->once())
->method('getDisplayName')
->will($this->returnValue('S. Admin'));
+ $admin
+ ->expects($this->once())
+ ->method('getEMailAddress')
+ ->will($this->returnValue('admin@bar.com'));
$admin
->expects($this->once())
->method('getLastLogin')
$bar = $this->getMockBuilder('\OC\User\User')
->disableOriginalConstructor()->getMock();
$bar
- ->expects($this->exactly(3))
+ ->expects($this->exactly(2))
->method('getUID')
->will($this->returnValue('bar'));
$bar
->expects($this->once())
->method('getDisplayName')
->will($this->returnValue('B. Ar'));
+ $bar
+ ->expects($this->once())
+ ->method('getEMailAddress')
+ ->will($this->returnValue('bar@dummy.com'));
$bar
->method('getLastLogin')
->will($this->returnValue(3999));
->with('bar')
->will($this->returnValue($bar));
$this->container['Config']
- ->expects($this->exactly(6))
+ ->expects($this->exactly(3))
->method('getUserValue')
- ->will($this->onConsecutiveCalls(1024, 'foo@bar.com',
- 404, 'admin@bar.com',
- 2323, 'bar@dummy.com'));
+ ->will($this->onConsecutiveCalls(1024,
+ 404,
+ 2323));
$subadmin = $this->getMockBuilder('\OC\SubAdmin')
->disableOriginalConstructor()
$foo = $this->getMockBuilder('\OC\User\User')
->disableOriginalConstructor()->getMock();
$foo
- ->expects($this->exactly(3))
+ ->expects($this->exactly(2))
->method('getUID')
->will($this->returnValue('foo'));
$foo
->expects($this->once())
->method('getDisplayName')
->will($this->returnValue('M. Foo'));
+ $foo
+ ->expects($this->once())
+ ->method('getEMailAddress')
+ ->will($this->returnValue('foo@bar.com'));
$foo
->method('getLastLogin')
->will($this->returnValue(500));
$admin = $this->getMockBuilder('\OC\User\User')
->disableOriginalConstructor()->getMock();
$admin
- ->expects($this->exactly(3))
+ ->expects($this->exactly(2))
->method('getUID')
->will($this->returnValue('admin'));
$admin
->expects($this->once())
->method('getDisplayName')
->will($this->returnValue('S. Admin'));
+ $admin
+ ->expects($this->once())
+ ->method('getEMailAddress')
+ ->will($this->returnValue('admin@bar.com'));
$admin
->expects($this->once())
->method('getLastLogin')
$bar = $this->getMockBuilder('\OC\User\User')
->disableOriginalConstructor()->getMock();
$bar
- ->expects($this->exactly(3))
+ ->expects($this->exactly(2))
->method('getUID')
->will($this->returnValue('bar'));
$bar
->expects($this->once())
->method('getDisplayName')
->will($this->returnValue('B. Ar'));
+ $bar
+ ->expects($this->once())
+ ->method('getEMailAddress')
+ ->will($this->returnValue('bar@dummy.com'));
$bar
->method('getLastLogin')
->will($this->returnValue(3999));
->with('admin')
->will($this->returnValue($admin));
$this->container['Config']
- ->expects($this->exactly(6))
+ ->expects($this->exactly(3))
->method('getUserValue')
->will($this->onConsecutiveCalls(
- 2323, 'bar@dummy.com',
- 1024, 'foo@bar.com',
- 404, 'admin@bar.com'
+ 2323,
+ 1024,
+ 404
));
$subgroup1 = $this->getMockBuilder('\OCP\IGroup')
$foo = $this->getMockBuilder('\OC\User\User')
->disableOriginalConstructor()->getMock();
$foo
- ->expects($this->exactly(3))
+ ->expects($this->exactly(2))
->method('getUID')
->will($this->returnValue('foo'));
$foo
->expects($this->once())
->method('getDisplayName')
->will($this->returnValue('M. Foo'));
+ $foo
+ ->expects($this->once())
+ ->method('getEMailAddress')
+ ->will($this->returnValue('foo@bar.com'));
$foo
->method('getLastLogin')
->will($this->returnValue(500));
$admin = $this->getMockBuilder('\OC\User\User')
->disableOriginalConstructor()->getMock();
$admin
- ->expects($this->exactly(3))
+ ->expects($this->exactly(2))
->method('getUID')
->will($this->returnValue('admin'));
$admin
->expects($this->once())
->method('getDisplayName')
->will($this->returnValue('S. Admin'));
+ $admin
+ ->expects($this->once())
+ ->method('getEMailAddress')
+ ->will($this->returnValue('admin@bar.com'));
$admin
->expects($this->once())
->method('getLastLogin')
$bar = $this->getMockBuilder('\OC\User\User')
->disableOriginalConstructor()->getMock();
$bar
- ->expects($this->exactly(3))
+ ->expects($this->exactly(2))
->method('getUID')
->will($this->returnValue('bar'));
$bar
->expects($this->once())
->method('getDisplayName')
->will($this->returnValue('B. Ar'));
+ $bar
+ ->expects($this->once())
+ ->method('getEMailAddress')
+ ->will($this->returnValue('bar@dummy.com'));
$bar
->method('getLastLogin')
->will($this->returnValue(3999));
->method('getUserGroupIds')
->will($this->onConsecutiveCalls(array('Users', 'Support'), array('admins', 'Support'), array('External Users')));
$this->container['Config']
- ->expects($this->exactly(6))
+ ->expects($this->exactly(3))
->method('getUserValue')
- ->will($this->onConsecutiveCalls(1024, 'foo@bar.com',
- 404, 'admin@bar.com',
- 2323, 'bar@dummy.com'));
+ ->will($this->onConsecutiveCalls(1024, 404, 2323));
$subadmin = $this->getMockBuilder('\OC\SubAdmin')
->disableOriginalConstructor()
$user = $this->getMockBuilder('\OC\User\User')
->disableOriginalConstructor()->getMock();
$user
- ->expects($this->exactly(3))
+ ->expects($this->exactly(2))
->method('getUID')
->will($this->returnValue('foo'));
$user
->expects($this->once())
->method('getDisplayName')
->will($this->returnValue('M. Foo'));
+ $user
+ ->expects($this->once())
+ ->method('getEMailAddress')
+ ->will($this->returnValue(null));
$user
->method('getLastLogin')
->will($this->returnValue(500));