]> source.dussan.org Git - nextcloud-server.git/commitdiff
add unit tests for new user create mail
authorMorris Jobke <hey@morrisjobke.de>
Tue, 16 Dec 2014 16:54:30 +0000 (17:54 +0100)
committerMorris Jobke <hey@morrisjobke.de>
Tue, 16 Dec 2014 16:54:30 +0000 (17:54 +0100)
settings/application.php
tests/settings/controller/userscontrollertest.php

index b088c2f937b8ce8dbb61f7de378a1833d979c301..74d021c5bf3d7df6e5b251d79a392d4c42df7697 100644 (file)
@@ -84,11 +84,11 @@ class Application extends App {
                                $c->query('Config'),
                                $c->query('IsAdmin'),
                                $c->query('L10N'),
-                               $c->getServer()->getLogger(),
+                               $c->query('Logger'),
                                $c->query('Defaults'),
                                $c->query('Mail'),
                                $c->query('DefaultMailAddress'),
-                               $c->getServer()->getURLGenerator()
+                               $c->query('URLGenerator')
                        );
                });
 
@@ -139,5 +139,11 @@ class Application extends App {
                $container->registerService('DefaultMailAddress', function(IContainer $c) {
                        return Util::getDefaultEmailAddress('no-reply');
                });
+               $container->registerService('Logger', function(IContainer $c) {
+                       return $c->query('ServerContainer')->getLogger();
+               });
+               $container->registerService('URLGenerator', function(IContainer $c) {
+                       return $c->query('ServerContainer')->getURLGenerator();
+               });
        }
 }
index 0ac6d3f0c013da92283c794dcdec79d8faf35865..207943c4c87ef60bcd0b7285d92ec2dd65e2e3ad 100644 (file)
@@ -45,6 +45,16 @@ class UsersControllerTest extends \Test\TestCase {
                        ->will($this->returnCallback(function($text, $parameters = array()) {
                                return vsprintf($text, $parameters);
                        }));
+               $this->container['Defaults'] = $this->getMockBuilder('\OC_Defaults')
+                       ->disableOriginalConstructor()->getMock();
+               $this->container['Mail'] = $this->getMockBuilder('\OC_Mail')
+                       ->disableOriginalConstructor()->getMock();
+               $this->container['DefaultMailAddress'] = 'no-reply@owncloud.com';
+               $this->container['Logger'] = $this->getMockBuilder('\OCP\ILogger')
+                       ->disableOriginalConstructor()->getMock();
+               $this->container['URLGenerator'] = $this->getMockBuilder('\OCP\IURLGenerator')
+                       ->disableOriginalConstructor()->getMock();
+
                $this->usersController = $this->container['UsersController'];
 
        }
@@ -473,4 +483,64 @@ class UsersControllerTest extends \Test\TestCase {
                $this->assertEquals($expectedResponse, $response);
        }
 
+       /**
+        * test if an invalid mail result in a failure response
+        */
+       public function testCreateUnsuccessfulWithInvalidEMail() {
+               /**
+                * 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'
+                       ),
+                       Http::STATUS_UNPROCESSABLE_ENTITY
+               );
+               $response = $this->usersController->create('foo', 'password', array(), 'invalidMailAdress');
+               $this->assertEquals($expectedResponse, $response);
+       }
+
+       /**
+        * test if a valid mail result in a successful mail send
+        */
+       public function testCreateSuccessfulWithValidEMail() {
+               /**
+                * 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(true));
+               $this->container['Mail']
+                       ->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');
+
+               $response = $this->usersController->create('foo', 'password', array(), 'validMail@Adre.ss');
+               $this->assertEquals(Http::STATUS_CREATED, $response->getStatus());
+       }
+
 }