1
0

MapperTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace Test\Files\ObjectStore;
  8. use OC\Files\ObjectStore\Mapper;
  9. use OCP\IConfig;
  10. use OCP\IUser;
  11. class MapperTest extends \Test\TestCase {
  12. /** @var IUser|\PHPUnit\Framework\MockObject\MockObject */
  13. private $user;
  14. /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
  15. private $config;
  16. /** @var Mapper */
  17. private $mapper;
  18. protected function setUp(): void {
  19. parent::setUp();
  20. $this->user = $this->createMock(IUser::class);
  21. $this->config = $this->createMock(IConfig::class);
  22. $this->mapper = new Mapper($this->user, $this->config);
  23. }
  24. public function dataGetBucket() {
  25. return [
  26. ['user', 64, 0, '17'],
  27. ['USER', 64, 0, '0'],
  28. ['bc0e8b52-a66c-1035-90c6-d9663bda9e3f', 64, 0, '56'],
  29. ['user', 8, 0, '1'],
  30. ['user', 2, 0, '1'],
  31. ['USER', 2, 0, '0'],
  32. ['user', 128, 64, '81'],
  33. ];
  34. }
  35. /**
  36. * @dataProvider dataGetBucket
  37. * @param string $username
  38. * @param int $numBuckets
  39. * @param string $expectedBucket
  40. */
  41. public function testGetBucket($username, $numBuckets, $bucketShift, $expectedBucket): void {
  42. $this->user->expects($this->once())
  43. ->method('getUID')
  44. ->willReturn($username);
  45. $this->config->expects($this->once())
  46. ->method('getSystemValue')
  47. ->with('objectstore_multibucket')
  48. ->willReturn(['arguments' => ['min_bucket' => $bucketShift]]);
  49. $result = $this->mapper->getBucket($numBuckets);
  50. $this->assertEquals($expectedBucket, $result);
  51. }
  52. }