aboutsummaryrefslogtreecommitdiffstats
path: root/tests/settings
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2014-12-16 17:54:30 +0100
committerMorris Jobke <hey@morrisjobke.de>2014-12-16 17:54:30 +0100
commit04e172c2ce9a43ea8884384b22efd5d07f027664 (patch)
tree98a8f27821428a04e8e742153c84beecdf9e1217 /tests/settings
parent3b61f76ca0eb9ad9487fa2ab64dda97e51f9df57 (diff)
downloadnextcloud-server-04e172c2ce9a43ea8884384b22efd5d07f027664.tar.gz
nextcloud-server-04e172c2ce9a43ea8884384b22efd5d07f027664.zip
add unit tests for new user create mail
Diffstat (limited to 'tests/settings')
-rw-r--r--tests/settings/controller/userscontrollertest.php70
1 files changed, 70 insertions, 0 deletions
diff --git a/tests/settings/controller/userscontrollertest.php b/tests/settings/controller/userscontrollertest.php
index 0ac6d3f0c01..207943c4c87 100644
--- a/tests/settings/controller/userscontrollertest.php
+++ b/tests/settings/controller/userscontrollertest.php
@@ -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());
+ }
+
}