1
0

LargeFileHelperGetFileSizeTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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-or-later
  6. */
  7. namespace Test;
  8. use bantu\IniGetWrapper\IniGetWrapper;
  9. /**
  10. * Tests whether LargeFileHelper is able to determine file size at all.
  11. * Large files are not considered yet.
  12. */
  13. class LargeFileHelperGetFileSizeTest extends TestCase {
  14. /** @var string */
  15. protected $filename;
  16. /** @var int */
  17. protected $fileSize;
  18. /** @var \OC\LargeFileHelper */
  19. protected $helper;
  20. protected function setUp(): void {
  21. parent::setUp();
  22. $this->helper = new \OC\LargeFileHelper();
  23. }
  24. public function dataFileNameProvider() {
  25. $path = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR;
  26. return [
  27. [ $path . 'lorem.txt', 446 ],
  28. [ $path . 'strängé filename (duplicate #2).txt', 446 ],
  29. ];
  30. }
  31. /**
  32. * @dataProvider dataFileNameProvider
  33. */
  34. public function XtestGetFileSizeViaCurl($filename, $fileSize) {
  35. if (!extension_loaded('curl')) {
  36. $this->markTestSkipped(
  37. 'The PHP curl extension is required for this test.'
  38. );
  39. }
  40. if (\OC::$server->get(IniGetWrapper::class)->getString('open_basedir') !== '') {
  41. $this->markTestSkipped(
  42. 'The PHP curl extension does not work with the file:// protocol when open_basedir is enabled.'
  43. );
  44. }
  45. $this->assertSame(
  46. $fileSize,
  47. $this->helper->getFileSizeViaCurl($filename)
  48. );
  49. }
  50. /**
  51. * @dataProvider dataFileNameProvider
  52. */
  53. public function testGetFileSizeViaExec($filename, $fileSize) {
  54. if (escapeshellarg('strängé') !== '\'strängé\'') {
  55. $this->markTestSkipped('Your escapeshell args removes accents');
  56. }
  57. if (!\OCP\Util::isFunctionEnabled('exec')) {
  58. $this->markTestSkipped(
  59. 'The exec() function needs to be enabled for this test.'
  60. );
  61. }
  62. $this->assertSame(
  63. $fileSize,
  64. $this->helper->getFileSizeViaExec($filename)
  65. );
  66. }
  67. /**
  68. * @dataProvider dataFileNameProvider
  69. */
  70. public function testGetFileSizeNative($filename, $fileSize) {
  71. $this->assertSame(
  72. $fileSize,
  73. $this->helper->getFileSizeNative($filename)
  74. );
  75. }
  76. }