1
0

FileChunkingTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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;
  22. use OCP\ICache;
  23. class FileChunkingTest extends \Test\TestCase {
  24. public function dataIsComplete() {
  25. return [
  26. [1, [], false],
  27. [1, [0], true],
  28. [2, [], false],
  29. [2, [0], false],
  30. [2, [1], false],
  31. [2, [0,1], true],
  32. [10, [], false],
  33. [10, [0,1,2,3,4,5,6,7,8], false],
  34. [10, [1,2,3,4,5,6,7,8,9], false],
  35. [10, [0,1,2,3,5,6,7,8,9], false],
  36. [10, [0,1,2,3,4,5,6,7,8,9], true],
  37. ];
  38. }
  39. /**
  40. * @dataProvider dataIsComplete
  41. * @param $total
  42. * @param array $present
  43. * @param $expected
  44. */
  45. public function testIsComplete($total, array $present, $expected) {
  46. $fileChunking = $this->getMockBuilder('\OC_FileChunking')
  47. ->setMethods(['getCache'])
  48. ->setConstructorArgs([[
  49. 'name' => 'file',
  50. 'transferid' => '42',
  51. 'chunkcount' => $total,
  52. ]])
  53. ->getMock();
  54. $cache = $this->createMock(ICache::class);
  55. $cache->expects($this->atLeastOnce())
  56. ->method('hasKey')
  57. ->will($this->returnCallback(function ($key) use ($present) {
  58. $data = explode('-', $key);
  59. return in_array($data[3], $present);
  60. }));
  61. $fileChunking->method('getCache')->willReturn($cache);
  62. $this->assertEquals($expected, $fileChunking->isComplete());
  63. }
  64. }