1
0

LargeFileHelperGetFileSizeTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. /**
  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() {
  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 testGetFileSizeViaCurl($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->getIniWrapper()->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 (!\OC_Helper::is_function_enabled('exec')) {
  55. $this->markTestSkipped(
  56. 'The exec() function needs to be enabled for this test.'
  57. );
  58. }
  59. $this->assertSame(
  60. $fileSize,
  61. $this->helper->getFileSizeViaExec($filename)
  62. );
  63. }
  64. /**
  65. * @dataProvider dataFileNameProvider
  66. */
  67. public function testGetFileSizeNative($filename, $fileSize) {
  68. $this->assertSame(
  69. $fileSize,
  70. $this->helper->getFileSizeNative($filename)
  71. );
  72. }
  73. }