Fix tests

Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
This commit is contained in:
Lukas Reschke 2017-04-07 10:48:47 +02:00 committed by Morris Jobke
parent 0560e69913
commit 1be75e8db8
No known key found for this signature in database
GPG Key ID: 9CE5ED29E7FCD38A
2 changed files with 106 additions and 44 deletions

View File

@ -444,19 +444,17 @@ class UsersController extends Controller {
$link = $this->urlGenerator->getAbsoluteURL('/');
}
$emailTemplate = new EMailTemplate($this->defaults);
$emailTemplate->addHeader($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('', 'logo-mail-header.png')));
$displayname = $user->getDisplayName();
if ($displayname === $username) {
$displayName = $user->getDisplayName();
if ($displayName === $username) {
$emailTemplate->addHeading($this->l10n->t('Welcome aboard'));
} else {
$emailTemplate->addHeading($this->l10n->t('Welcome aboard %s', $displayname));
$emailTemplate->addHeading($this->l10n->t('Welcome aboard %s', [$displayName]));
}
$emailTemplate->addBodyText($this->l10n->t('You have now an Nextcloud account, you can add, protect, and share your data.'));
$emailTemplate->addBodyText($this->l10n->t('You have now an %s account, you can add, protect, and share your data.', [$this->defaults->getName()]));
$emailTemplate->addBodyText($this->l10n->t('Your username is: %s', [$username]));
if ($generatedPassword) {
@ -466,8 +464,10 @@ class UsersController extends Controller {
}
$emailTemplate->addBodyButtonGroup(
$leftButtonText, $link,
$this->l10n->t('Install Client'), 'https://nextcloud.com/install/#install-clients'
$leftButtonText,
$link,
$this->l10n->t('Install Client'),
'https://nextcloud.com/install/#install-clients'
);
$emailTemplate->addFooter(

View File

@ -129,7 +129,7 @@ class UsersControllerTest extends \Test\TestCase {
$this->logger,
$this->defaults,
$this->mailer,
'no-reply@owncloud.com',
'no-reply@nextcloud.com',
$this->urlGenerator,
$this->appManager,
$this->avatarManager,
@ -153,7 +153,7 @@ class UsersControllerTest extends \Test\TestCase {
$this->logger,
$this->defaults,
$this->mailer,
'no-reply@owncloud.com',
'no-reply@nextcloud.com',
$this->urlGenerator,
$this->appManager,
$this->avatarManager,
@ -1427,26 +1427,56 @@ class UsersControllerTest extends \Test\TestCase {
$message
->expects($this->at(1))
->method('setSubject')
->with('Your account was created');
->with('Your Nextcloud account was created');
$this->urlGenerator
->expects($this->at(0))
->method('getAbsoluteURL')
->with('/')
->willReturn('https://example.org/');
$this->urlGenerator
->expects($this->at(1))
->method('imagePath')
->with('', 'logo-mail-header.png')
->willReturn('/img/logo-mail-header.png');
$this->urlGenerator
->expects($this->at(2))
->method('getAbsoluteURL')
->with('/img/logo-mail-header.png')
->willReturn('https://example.org/img/logo-mail-header.png');
$this->urlGenerator
->expects($this->at(3))
->method('imagePath')
->with('', 'logo-mail-footer.png')
->willReturn('/img/logo-mail-footer.png');
$this->urlGenerator
->expects($this->at(4))
->method('getAbsoluteURL')
->with('/img/logo-mail-footer.png')
->willReturn('https://example.org/img/logo-mail-footer.png');
$this->defaults
->expects($this->any())
->method('getName')
->willReturn('Nextcloud');
$this->defaults
->expects($this->any())
->method('getSlogan')
->willReturn('A safe home for your data');
$emailTemplate = new EMailTemplate($this->defaults);
$emailTemplate->addHeader('https://example.org/img/logo-mail-header.png');
$emailTemplate->addHeading('Welcome aboard');
$emailTemplate->addBodyText('You have now an Nextcloud account, you can add, protect, and share your data.');
$emailTemplate->addBodyText('Your username is: foo');
$emailTemplate->addBodyButtonGroup(
'Go to Nextcloud', 'https://example.org/resetPassword/123',
'Go to Nextcloud', 'https://example.org/',
'Install Client', 'https://nextcloud.com/install/#install-clients'
);
$emailTemplate->addFooter(
'https://example.org/img/logo-mail-footer.png',
'TestCloud - A safe home for your data<br>This is an automatically generated email, please do not reply.'
'Nextcloud - A safe home for your data<br>This is an automatically generated email, please do not reply.'
);
$message
->expects($this->at(2))
->method('setHtmlBody')
@ -1458,7 +1488,7 @@ class UsersControllerTest extends \Test\TestCase {
$message
->expects($this->at(4))
->method('setFrom')
->with(['no-reply@owncloud.com' => null]);
->with(['no-reply@nextcloud.com' => 'Nextcloud']);
$this->mailer
->expects($this->at(0))
@ -1485,6 +1515,9 @@ class UsersControllerTest extends \Test\TestCase {
$user
->method('getUID')
->will($this->returnValue('foo'));
$user
->method('getDisplayName')
->will($this->returnValue('foo'));
$user
->expects($this->once())
->method('getBackendClassName')
@ -2264,20 +2297,24 @@ class UsersControllerTest extends \Test\TestCase {
public function testCreateSuccessfulWithoutPasswordAndWithEmail() {
$controller = $this->getController(true);
$user = $this->getMockBuilder('\OC\User\User')
->disableOriginalConstructor()->getMock();
$user
->method('getHome')
->will($this->returnValue('/home/user'));
->willReturn('/home/user');
$user
->method('getUID')
->will($this->returnValue('foo'));
->willReturn('foo');
$user
->method('getDisplayName')
->willReturn('John Doe');
$user
->method('getEmailAddress')
->willReturn('abc@example.org');
$user
->expects($this->once())
->method('getBackendClassName')
->will($this->returnValue('bar'));
->willReturn('bar');
$this->userManager
->expects($this->once())
@ -2310,11 +2347,6 @@ class UsersControllerTest extends \Test\TestCase {
ISecureRandom::CHAR_LOWER .
ISecureRandom::CHAR_UPPER)
->will($this->returnValue('mytoken'));
$this->urlGenerator
->expects($this->once())
->method('linkToRouteAbsolute')
->with('core.lost.resetform', ['userId' => 'foo', 'token' => 'mytoken'])
->will($this->returnValue('link-with-my-token'));
$controller = $this->getController(true);
$message = $this->getMockBuilder('\OC\Mail\Message')
@ -2326,26 +2358,56 @@ class UsersControllerTest extends \Test\TestCase {
$message
->expects($this->at(1))
->method('setSubject')
->with('Your account was created');
->with('Your Nextcloud account was created');
$this->urlGenerator
->expects($this->at(0))
->method('linkToRouteAbsolute')
->with('core.lost.resetform', ['userId' => 'foo', 'token' => 'mytoken'])
->will($this->returnValue('https://example.org/resetPassword/123'));
$this->urlGenerator
->expects($this->at(1))
->method('imagePath')
->with('', 'logo-mail-header.png')
->willReturn('/img/logo-mail-header.png');
$this->urlGenerator
->expects($this->at(2))
->method('getAbsoluteURL')
->with('/img/logo-mail-header.png')
->willReturn('https://example.org/img/logo-mail-header.png');
$this->urlGenerator
->expects($this->at(3))
->method('imagePath')
->with('', 'logo-mail-footer.png')
->willReturn('/img/logo-mail-footer.png');
$this->urlGenerator
->expects($this->at(4))
->method('getAbsoluteURL')
->with('/img/logo-mail-footer.png')
->willReturn('https://example.org/img/logo-mail-footer.png');
$this->defaults
->expects($this->any())
->method('getName')
->willReturn('Nextcloud');
$this->defaults
->expects($this->any())
->method('getSlogan')
->willReturn('A safe home for your data');
$emailTemplate = new EMailTemplate($this->defaults);
$emailTemplate->addHeader('https://example.org/img/logo-mail-header.png');
$emailTemplate->addHeading('Welcome aboard');
$emailTemplate->addHeading('Welcome aboard John Doe');
$emailTemplate->addBodyText('You have now an Nextcloud account, you can add, protect, and share your data.');
$emailTemplate->addBodyText('Your username is: foo');
$emailTemplate->addBodyButtonGroup(
'Go to Nextcloud', 'https://example.org/resetPassword/123',
'Set your password', 'https://example.org/resetPassword/123',
'Install Client', 'https://nextcloud.com/install/#install-clients'
);
$emailTemplate->addFooter(
'https://example.org/img/logo-mail-footer.png',
'TestCloud - A safe home for your data<br>This is an automatically generated email, please do not reply.'
'Nextcloud - A safe home for your data<br>This is an automatically generated email, please do not reply.'
);
$message
->expects($this->at(2))
->method('setHtmlBody')
@ -2357,7 +2419,7 @@ class UsersControllerTest extends \Test\TestCase {
$message
->expects($this->at(4))
->method('setFrom')
->with(['no-reply@owncloud.com' => null]);
->with(['no-reply@nextcloud.com' => 'Nextcloud']);
$this->mailer
->expects($this->at(0))
@ -2374,19 +2436,19 @@ class UsersControllerTest extends \Test\TestCase {
->with($message);
$expectedResponse = new DataResponse(
array(
[
'name' => 'foo',
'groups' => null,
'storageLocation' => '/home/user',
'backend' => 'bar',
'lastLogin' => null,
'displayname' => null,
'lastLogin' => 0,
'displayname' => 'John Doe',
'quota' => null,
'subadmin' => array(),
'email' => null,
'email' => 'abc@example.org',
'isRestoreDisabled' => false,
'isAvatarAvailable' => true,
),
],
Http::STATUS_CREATED
);
$response = $controller->create('foo', '', array(), 'abc@example.org');