1
0

FileChunkingTest.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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;
  8. use OCP\ICache;
  9. class FileChunkingTest extends \Test\TestCase {
  10. public function dataIsComplete() {
  11. return [
  12. [1, [], false],
  13. [1, [0], true],
  14. [2, [], false],
  15. [2, [0], false],
  16. [2, [1], false],
  17. [2, [0,1], true],
  18. [10, [], false],
  19. [10, [0,1,2,3,4,5,6,7,8], false],
  20. [10, [1,2,3,4,5,6,7,8,9], false],
  21. [10, [0,1,2,3,5,6,7,8,9], false],
  22. [10, [0,1,2,3,4,5,6,7,8,9], true],
  23. ];
  24. }
  25. /**
  26. * @dataProvider dataIsComplete
  27. * @param $total
  28. * @param array $present
  29. * @param $expected
  30. */
  31. public function testIsComplete($total, array $present, $expected) {
  32. $fileChunking = $this->getMockBuilder(\OC_FileChunking::class)
  33. ->setMethods(['getCache'])
  34. ->setConstructorArgs([[
  35. 'name' => 'file',
  36. 'transferid' => '42',
  37. 'chunkcount' => $total,
  38. ]])
  39. ->getMock();
  40. $cache = $this->createMock(ICache::class);
  41. $cache->expects($this->atLeastOnce())
  42. ->method('hasKey')
  43. ->willReturnCallback(function ($key) use ($present) {
  44. $data = explode('-', $key);
  45. return in_array($data[3], $present);
  46. });
  47. $fileChunking->method('getCache')->willReturn($cache);
  48. $this->assertEquals($expected, $fileChunking->isComplete());
  49. }
  50. }