summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorblizzz <blizzz@owncloud.com>2014-10-16 11:33:12 +0200
committerblizzz <blizzz@owncloud.com>2014-10-16 11:33:12 +0200
commit756f64d728ccb9ef9bc6ba2ca965064827003231 (patch)
tree2c6db6f6245c2303d8c90083fcf2e468e6db5c83 /tests
parent08582d145c628b4651fc83a62cdf890e4b40be4f (diff)
parent239bff5766c42e94e430dfdc4233ac4115c516ec (diff)
downloadnextcloud-server-756f64d728ccb9ef9bc6ba2ca965064827003231.tar.gz
nextcloud-server-756f64d728ccb9ef9bc6ba2ca965064827003231.zip
Merge pull request #11595 from owncloud/make_get_display_name_more_robust
strip whitespace from the beginning and end of the display name
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/user/user.php46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/lib/user/user.php b/tests/lib/user/user.php
index 3f90432c6b0..7a1db861c98 100644
--- a/tests/lib/user/user.php
+++ b/tests/lib/user/user.php
@@ -32,6 +32,28 @@ class User extends \PHPUnit_Framework_TestCase {
$this->assertEquals('Foo', $user->getDisplayName());
}
+ /**
+ * if the display name contain whitespaces only, we expect the uid as result
+ */
+ public function testDisplayNameEmpty() {
+ /**
+ * @var \OC_User_Backend | \PHPUnit_Framework_MockObject_MockObject $backend
+ */
+ $backend = $this->getMock('\OC_User_Backend');
+ $backend->expects($this->once())
+ ->method('getDisplayName')
+ ->with($this->equalTo('foo'))
+ ->will($this->returnValue(' '));
+
+ $backend->expects($this->any())
+ ->method('implementsActions')
+ ->with($this->equalTo(\OC_USER_BACKEND_GET_DISPLAYNAME))
+ ->will($this->returnValue(true));
+
+ $user = new \OC\User\User('foo', $backend);
+ $this->assertEquals('foo', $user->getDisplayName());
+ }
+
public function testDisplayNameNotSupported() {
/**
* @var \OC_User_Backend | \PHPUnit_Framework_MockObject_MockObject $backend
@@ -305,6 +327,30 @@ class User extends \PHPUnit_Framework_TestCase {
$this->assertEquals('Foo',$user->getDisplayName());
}
+ /**
+ * don't allow display names containing whitespaces only
+ */
+ public function testSetDisplayNameEmpty() {
+ /**
+ * @var \OC_User_Backend | \PHPUnit_Framework_MockObject_MockObject $backend
+ */
+ $backend = $this->getMock('\OC_User_Database');
+
+ $backend->expects($this->any())
+ ->method('implementsActions')
+ ->will($this->returnCallback(function ($actions) {
+ if ($actions === \OC_USER_BACKEND_SET_DISPLAYNAME) {
+ return true;
+ } else {
+ return false;
+ }
+ }));
+
+ $user = new \OC\User\User('foo', $backend);
+ $this->assertFalse($user->setDisplayName(' '));
+ $this->assertEquals('foo',$user->getDisplayName());
+ }
+
public function testSetDisplayNameNotSupported() {
/**
* @var \OC_User_Backend | \PHPUnit_Framework_MockObject_MockObject $backend