largefilehelpergetfilesize.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. }