largefilehelpergetfilesize.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 LargeFileHelperGetFileSize 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. $filePaths = array(array($path . 'lorem.txt', 446));
  27. if (!\OC_Util::runningOnWindows()) {
  28. $filePaths[] = array($path . 'strängé filename (duplicate #2).txt', 446);
  29. }
  30. return $filePaths;
  31. }
  32. /**
  33. * @dataProvider dataFileNameProvider
  34. */
  35. public function testGetFileSizeViaCurl($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->getIniWrapper()->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 testGetFileSizeViaCOM($filename, $fileSize) {
  55. if (!extension_loaded('COM')) {
  56. $this->markTestSkipped(
  57. 'The PHP Windows COM extension is required for this test.'
  58. );
  59. }
  60. $this->assertSame(
  61. $fileSize,
  62. $this->helper->getFileSizeViaCOM($filename)
  63. );
  64. }
  65. /**
  66. * @dataProvider dataFileNameProvider
  67. */
  68. public function testGetFileSizeViaExec($filename, $fileSize) {
  69. if (!\OC_Helper::is_function_enabled('exec')) {
  70. $this->markTestSkipped(
  71. 'The exec() function needs to be enabled for this test.'
  72. );
  73. }
  74. $this->assertSame(
  75. $fileSize,
  76. $this->helper->getFileSizeViaExec($filename)
  77. );
  78. }
  79. /**
  80. * @dataProvider dataFileNameProvider
  81. */
  82. public function testGetFileSizeNative($filename, $fileSize) {
  83. $this->assertSame(
  84. $fileSize,
  85. $this->helper->getFileSizeNative($filename)
  86. );
  87. }
  88. }