Return null when requesting tags for null user

The TagManager->load() now returns null if the user is not authenticated
instead of failing with an error.
This commit is contained in:
Vincent Petry 2015-02-25 17:20:26 +01:00
parent 14c592fe86
commit 9ee37169a6
2 changed files with 15 additions and 0 deletions

View File

@ -65,6 +65,11 @@ class TagManager implements \OCP\ITagManager {
*/
public function load($type, $defaultTags = array(), $includeShared = false, $userId = null) {
if (is_null($userId)) {
$user = $this->userSession->getUser();
if ($user === null) {
// nothing we can do without a user
return null;
}
$userId = $this->userSession->getUser()->getUId();
}
return new Tags($this->mapper, $userId, $type, $defaultTags, $includeShared);

View File

@ -62,6 +62,16 @@ class Test_Tags extends \Test\TestCase {
parent::tearDown();
}
public function testTagManagerWithoutUserReturnsNull() {
$this->userSession = $this->getMock('\OCP\IUserSession');
$this->userSession
->expects($this->any())
->method('getUser')
->will($this->returnValue(null));
$this->tagMgr = new OC\TagManager($this->tagMapper, $this->userSession);
$this->assertNull($this->tagMgr->load($this->objectType));
}
public function testInstantiateWithDefaults() {
$defaultTags = array('Friends', 'Family', 'Work', 'Other');