diff options
author | Lukas Reschke <lukas@owncloud.com> | 2015-02-12 13:53:27 +0100 |
---|---|---|
committer | Lukas Reschke <lukas@owncloud.com> | 2015-03-16 12:47:05 +0100 |
commit | 13486a5ada62e4355473ca01e07371c162951e84 (patch) | |
tree | c079e9c53691ca14e5e1898c40a93322d6e727f5 /tests/settings | |
parent | 0d9f149dd93997085b85e2b174f5989a1b996263 (diff) | |
download | nextcloud-server-13486a5ada62e4355473ca01e07371c162951e84.tar.gz nextcloud-server-13486a5ada62e4355473ca01e07371c162951e84.zip |
Migrate to SwiftMail
Replaces the OC_Mail and phpmailer with SwiftMail allowing us to mock it properly.
Fixes the unit test execution on master on local machines and https://github.com/owncloud/core/issues/12014
Conflicts:
3rdparty
lib/private/server.php
lib/public/iservercontainer.php
tests/lib/mail.php
tests/settings/controller/mailsettingscontrollertest.php
Conflicts:
3rdparty
lib/private/mail.php
lib/private/server.php
lib/public/iservercontainer.php
settings/ajax/lostpassword.php
settings/application.php
Diffstat (limited to 'tests/settings')
-rw-r--r-- | tests/settings/controller/mailsettingscontrollertest.php | 8 | ||||
-rw-r--r-- | tests/settings/controller/userscontrollertest.php | 116 |
2 files changed, 75 insertions, 49 deletions
diff --git a/tests/settings/controller/mailsettingscontrollertest.php b/tests/settings/controller/mailsettingscontrollertest.php index ed33d7fbe49..84432f656bf 100644 --- a/tests/settings/controller/mailsettingscontrollertest.php +++ b/tests/settings/controller/mailsettingscontrollertest.php @@ -30,7 +30,7 @@ class MailSettingsControllerTest extends \Test\TestCase { $this->container['AppName'] = 'settings'; $this->container['UserSession'] = $this->getMockBuilder('\OC\User\Session') ->disableOriginalConstructor()->getMock(); - $this->container['Mail'] = $this->getMockBuilder('\OC_Mail') + $this->container['MailMessage'] = $this->getMockBuilder('\OCP\Mail\IMessage') ->disableOriginalConstructor()->getMock(); $this->container['Defaults'] = $this->getMockBuilder('\OC_Defaults') ->disableOriginalConstructor()->getMock(); @@ -152,12 +152,6 @@ class MailSettingsControllerTest extends \Test\TestCase { } public function testSendTestMail() { - /** - * FIXME: Disabled due to missing DI on mail class. - * TODO: Re-enable when https://github.com/owncloud/core/pull/12085 is merged. - */ - $this->markTestSkipped('Disable test until OC_Mail is rewritten.'); - $user = $this->getMockBuilder('\OC\User\User') ->disableOriginalConstructor() ->getMock(); diff --git a/tests/settings/controller/userscontrollertest.php b/tests/settings/controller/userscontrollertest.php index b813da038a3..3f69d1e7d18 100644 --- a/tests/settings/controller/userscontrollertest.php +++ b/tests/settings/controller/userscontrollertest.php @@ -45,7 +45,7 @@ class UsersControllerTest extends \Test\TestCase { })); $this->container['Defaults'] = $this->getMockBuilder('\OC_Defaults') ->disableOriginalConstructor()->getMock(); - $this->container['Mail'] = $this->getMockBuilder('\OC_Mail') + $this->container['Mailer'] = $this->getMockBuilder('\OCP\Mail\IMailer') ->disableOriginalConstructor()->getMock(); $this->container['DefaultMailAddress'] = 'no-reply@owncloud.com'; $this->container['Logger'] = $this->getMockBuilder('\OCP\ILogger') @@ -1151,24 +1151,12 @@ class UsersControllerTest extends \Test\TestCase { public function testCreateUnsuccessfulWithInvalidEmailAdmin() { $this->container['IsAdmin'] = true; - /** - * FIXME: Disabled due to missing DI on mail class. - * TODO: Re-enable when https://github.com/owncloud/core/pull/12085 is merged. - */ - $this->markTestSkipped('Disable test until OC_Mail is rewritten.'); - - $this->container['Mail'] - ->expects($this->once()) - ->method('validateAddress') - ->will($this->returnValue(false)); - - $expectedResponse = new DataResponse( - array( - 'message' => 'Invalid mail address' - ), + $expectedResponse = new DataResponse([ + 'message' => 'Invalid mail address', + ], Http::STATUS_UNPROCESSABLE_ENTITY ); - $response = $this->container['UsersController']->create('foo', 'password', array(), 'invalidMailAdress'); + $response = $this->container['UsersController']->create('foo', 'password', [], 'invalidMailAdress'); $this->assertEquals($expectedResponse, $response); } @@ -1177,35 +1165,79 @@ class UsersControllerTest extends \Test\TestCase { */ public function testCreateSuccessfulWithValidEmailAdmin() { $this->container['IsAdmin'] = true; + $message = $this->getMockBuilder('\OC\Mail\Message') + ->disableOriginalConstructor()->getMock(); + $message + ->expects($this->at(0)) + ->method('setTo') + ->with(['validMail@Adre.ss' => 'foo']); + $message + ->expects($this->at(1)) + ->method('setSubject') + ->with('Your account was created'); + $htmlBody = new Http\TemplateResponse( + 'settings', + 'email.new_user', + [ + 'username' => 'foo', + 'url' => '', + ], + 'blank' + ); + $message + ->expects($this->at(2)) + ->method('setHtmlBody') + ->with($htmlBody->render()); + $plainBody = new Http\TemplateResponse( + 'settings', + 'email.new_user_plain_text', + [ + 'username' => 'foo', + 'url' => '', + ], + 'blank' + ); + $message + ->expects($this->at(3)) + ->method('setPlainBody') + ->with($plainBody->render()); + $message + ->expects($this->at(4)) + ->method('setFrom') + ->with(['no-reply@owncloud.com' => null]); + + $this->container['Mailer'] + ->expects($this->at(0)) + ->method('createMessage') + ->will($this->returnValue($message)); + $this->container['Mailer'] + ->expects($this->at(1)) + ->method('send') + ->with($message); - /** - * FIXME: Disabled due to missing DI on mail class. - * TODO: Re-enable when https://github.com/owncloud/core/pull/12085 is merged. - */ - $this->markTestSkipped('Disable test until OC_Mail is rewritten.'); - - $this->container['Mail'] + $user = $this->getMockBuilder('\OC\User\User') + ->disableOriginalConstructor()->getMock(); + $user + ->method('getHome') + ->will($this->returnValue('/home/user')); + $user + ->method('getHome') + ->will($this->returnValue('/home/user')); + $user + ->method('getUID') + ->will($this->returnValue('foo')); + $user ->expects($this->once()) - ->method('validateAddress') - ->will($this->returnValue(true)); - $this->container['Mail'] + ->method('getBackendClassName') + ->will($this->returnValue('bar')); + + $this->container['UserManager'] ->expects($this->once()) - ->method('send') - ->with( - $this->equalTo('validMail@Adre.ss'), - $this->equalTo('foo'), - $this->anything(), - $this->anything(), - $this->anything(), - $this->equalTo('no-reply@owncloud.com'), - $this->equalTo(1), - $this->anything() - ); - $this->container['Logger'] - ->expects($this->never()) - ->method('error'); + ->method('createUser') + ->will($this->onConsecutiveCalls($user)); + - $response = $this->container['UsersController']->create('foo', 'password', array(), 'validMail@Adre.ss'); + $response = $this->container['UsersController']->create('foo', 'password', [], 'validMail@Adre.ss'); $this->assertEquals(Http::STATUS_CREATED, $response->getStatus()); } |