1
0

MapperTest.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * @author Roeland Jago Douma <rullzer@owncloud.com>
  4. *
  5. * @copyright Copyright (c) 2016, ownCloud, Inc.
  6. * @license AGPL-3.0
  7. *
  8. * This code is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License, version 3,
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License, version 3,
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>
  19. *
  20. */
  21. namespace Test\Files\ObjectStore;
  22. use OC\Files\ObjectStore\Mapper;
  23. use OCP\IConfig;
  24. use OCP\IUser;
  25. class MapperTest extends \Test\TestCase {
  26. /** @var IUser|\PHPUnit\Framework\MockObject\MockObject */
  27. private $user;
  28. /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
  29. private $config;
  30. /** @var Mapper */
  31. private $mapper;
  32. protected function setUp(): void {
  33. parent::setUp();
  34. $this->user = $this->createMock(IUser::class);
  35. $this->config = $this->createMock(IConfig::class);
  36. $this->mapper = new Mapper($this->user, $this->config);
  37. }
  38. public function dataGetBucket() {
  39. return [
  40. ['user', 64, 0, '17'],
  41. ['USER', 64, 0, '0'],
  42. ['bc0e8b52-a66c-1035-90c6-d9663bda9e3f', 64, 0, '56'],
  43. ['user', 8, 0, '1'],
  44. ['user', 2, 0, '1'],
  45. ['USER', 2, 0, '0'],
  46. ['user', 128, 64, '81'],
  47. ];
  48. }
  49. /**
  50. * @dataProvider dataGetBucket
  51. * @param string $username
  52. * @param int $numBuckets
  53. * @param string $expectedBucket
  54. */
  55. public function testGetBucket($username, $numBuckets, $bucketShift, $expectedBucket) {
  56. $this->user->expects($this->once())
  57. ->method('getUID')
  58. ->willReturn($username);
  59. $this->config->expects($this->once())
  60. ->method('getSystemValue')
  61. ->with('objectstore_multibucket')
  62. ->willReturn(['arguments' => ['min_bucket' => $bucketShift]]);
  63. $result = $this->mapper->getBucket($numBuckets);
  64. $this->assertEquals($expectedBucket, $result);
  65. }
  66. }