LargeFileHelperGetFileSizeTest.php 2.0 KB

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