You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FileChunkingTest.php 1.9KB

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