diff options
author | Thomas Citharel <tcit@tcit.fr> | 2021-08-16 17:55:27 +0200 |
---|---|---|
committer | Thomas Citharel <tcit@tcit.fr> | 2021-08-16 19:03:00 +0200 |
commit | a7b9b398a35c914b39c8eb41f920612a5f21eb36 (patch) | |
tree | 696a300f8e7a33827653628464b15b0506f02035 /apps/dav/tests | |
parent | 5da42273805160f75436f53b829b17e7b4ed2054 (diff) | |
download | nextcloud-server-a7b9b398a35c914b39c8eb41f920612a5f21eb36.tar.gz nextcloud-server-a7b9b398a35c914b39c8eb41f920612a5f21eb36.zip |
Expose user language through DAV
Introduces the '{http://nextcloud.com/ns}language' prop that gives the
user's language
Closes #28449
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
Diffstat (limited to 'apps/dav/tests')
-rw-r--r-- | apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php | 2 | ||||
-rw-r--r-- | apps/dav/tests/unit/CardDAV/CardDavBackendTest.php | 2 | ||||
-rw-r--r-- | apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php | 29 |
3 files changed, 32 insertions, 1 deletions
diff --git a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php index 94e099f523e..c659e2ccc6d 100644 --- a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php +++ b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php @@ -37,6 +37,7 @@ use OCP\IGroupManager; use OCP\ILogger; use OCP\IUserManager; use OCP\IUserSession; +use OCP\L10N\IFactory; use OCP\Security\ISecureRandom; use OCP\Share\IManager as ShareManager; use Sabre\CalDAV\Xml\Property\SupportedCalendarComponentSet; @@ -94,6 +95,7 @@ abstract class AbstractCalDavBackend extends TestCase { $this->createMock(ProxyMapper::class), $this->createMock(KnownUserService::class), $this->createMock(IConfig::class), + $this->createMock(IFactory::class) ]) ->setMethods(['getPrincipalByPath', 'getGroupMembership']) ->getMock(); diff --git a/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php b/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php index fb9522519a5..7eda691d199 100644 --- a/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php +++ b/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php @@ -46,6 +46,7 @@ use OCP\IGroupManager; use OCP\IL10N; use OCP\IUserManager; use OCP\IUserSession; +use OCP\L10N\IFactory; use OCP\Share\IManager as ShareManager; use Sabre\DAV\Exception\BadRequest; use Sabre\DAV\PropPatch; @@ -141,6 +142,7 @@ class CardDavBackendTest extends TestCase { $this->createMock(ProxyMapper::class), $this->createMock(KnownUserService::class), $this->createMock(IConfig::class), + $this->createMock(IFactory::class) ]) ->setMethods(['getPrincipalByPath', 'getGroupMembership']) ->getMock(); diff --git a/apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php b/apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php index acaa82dca8b..ac504c37c74 100644 --- a/apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php @@ -40,6 +40,7 @@ use OCP\IGroupManager; use OCP\IUser; use OCP\IUserManager; use OCP\IUserSession; +use OCP\L10N\IFactory; use OCP\Share\IManager; use PHPUnit\Framework\MockObject\MockObject; use Sabre\DAV\PropPatch; @@ -72,6 +73,8 @@ class PrincipalTest extends TestCase { private $knownUserService; /** @var IConfig | \PHPUnit\Framework\MockObject\MockObject */ private $config; + /** @var IFactory|MockObject */ + private $languageFactory; protected function setUp(): void { $this->userManager = $this->createMock(IUserManager::class); @@ -82,6 +85,7 @@ class PrincipalTest extends TestCase { $this->proxyMapper = $this->createMock(ProxyMapper::class); $this->knownUserService = $this->createMock(KnownUserService::class); $this->config = $this->createMock(IConfig::class); + $this->languageFactory = $this->createMock(IFactory::class); $this->connector = new \OCA\DAV\Connector\Sabre\Principal( $this->userManager, @@ -91,7 +95,8 @@ class PrincipalTest extends TestCase { $this->appManager, $this->proxyMapper, $this->knownUserService, - $this->config + $this->config, + $this->languageFactory ); parent::setUp(); } @@ -130,16 +135,24 @@ class PrincipalTest extends TestCase { ->with('') ->willReturn([$fooUser, $barUser]); + $this->languageFactory + ->expects($this->exactly(2)) + ->method('getUserLanguage') + ->withConsecutive([$fooUser], [$barUser]) + ->willReturnOnConsecutiveCalls('de', 'en'); + $expectedResponse = [ 0 => [ 'uri' => 'principals/users/foo', '{DAV:}displayname' => 'Dr. Foo-Bar', '{urn:ietf:params:xml:ns:caldav}calendar-user-type' => 'INDIVIDUAL', + '{http://nextcloud.com/ns}language' => 'de', ], 1 => [ 'uri' => 'principals/users/bar', '{DAV:}displayname' => 'bar', '{urn:ietf:params:xml:ns:caldav}calendar-user-type' => 'INDIVIDUAL', + '{http://nextcloud.com/ns}language' => 'en', '{http://sabredav.org/ns}email-address' => 'bar@nextcloud.com', ] ]; @@ -170,10 +183,17 @@ class PrincipalTest extends TestCase { ->with('foo') ->willReturn($fooUser); + $this->languageFactory + ->expects($this->once()) + ->method('getUserLanguage') + ->with($fooUser) + ->willReturn('de'); + $expectedResponse = [ 'uri' => 'principals/users/foo', '{DAV:}displayname' => 'foo', '{urn:ietf:params:xml:ns:caldav}calendar-user-type' => 'INDIVIDUAL', + '{http://nextcloud.com/ns}language' => 'de' ]; $response = $this->connector->getPrincipalByPath('principals/users/foo'); $this->assertSame($expectedResponse, $response); @@ -195,10 +215,17 @@ class PrincipalTest extends TestCase { ->with('foo') ->willReturn($fooUser); + $this->languageFactory + ->expects($this->once()) + ->method('getUserLanguage') + ->with($fooUser) + ->willReturn('de'); + $expectedResponse = [ 'uri' => 'principals/users/foo', '{DAV:}displayname' => 'foo', '{urn:ietf:params:xml:ns:caldav}calendar-user-type' => 'INDIVIDUAL', + '{http://nextcloud.com/ns}language' => 'de', '{http://sabredav.org/ns}email-address' => 'foo@nextcloud.com', ]; $response = $this->connector->getPrincipalByPath('principals/users/foo'); |