1
0

LargeFileHelperGetFileSizeTest.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 (escapeshellarg('strängé') !== '\'strängé\'') {
  56. $this->markTestSkipped('Your escapeshell args removes accents');
  57. }
  58. if (!\OCP\Util::isFunctionEnabled('exec')) {
  59. $this->markTestSkipped(
  60. 'The exec() function needs to be enabled for this test.'
  61. );
  62. }
  63. $this->assertSame(
  64. $fileSize,
  65. $this->helper->getFileSizeViaExec($filename)
  66. );
  67. }
  68. /**
  69. * @dataProvider dataFileNameProvider
  70. */
  71. public function testGetFileSizeNative($filename, $fileSize) {
  72. $this->assertSame(
  73. $fileSize,
  74. $this->helper->getFileSizeNative($filename)
  75. );
  76. }
  77. }