FileTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Filesystem\Test\Unit\Driver;
  7. use Magento\Framework\Filesystem\Driver\File;
  8. class FileTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /** @var string Result of file_get_contents() function */
  11. public static $fileGetContents;
  12. /** @var bool Result of file_put_contents() function */
  13. public static $filePutContents;
  14. public function setUp()
  15. {
  16. self::$fileGetContents = '';
  17. self::$filePutContents = true;
  18. }
  19. /**
  20. * @dataProvider dataProviderForTestGetAbsolutePath
  21. */
  22. public function testGetAbsolutePath($basePath, $path, $expected)
  23. {
  24. $file = new File();
  25. $this->assertEquals($expected, $file->getAbsolutePath($basePath, $path));
  26. }
  27. /**
  28. * @return array
  29. */
  30. public function dataProviderForTestGetAbsolutePath()
  31. {
  32. return [
  33. ['/root/path/', 'sub', '/root/path/sub'],
  34. ['/root/path/', '/sub', '/root/path/sub'],
  35. ['/root/path/', '../sub', '/root/path/../sub'],
  36. ['/root/path/', '/root/path/sub', '/root/path/sub'],
  37. ];
  38. }
  39. /**
  40. * @dataProvider dataProviderForTestGetRelativePath
  41. */
  42. public function testGetRelativePath($basePath, $path, $expected)
  43. {
  44. $file = new File();
  45. $this->assertEquals($expected, $file->getRelativePath($basePath, $path));
  46. }
  47. /**
  48. * @return array
  49. */
  50. public function dataProviderForTestGetRelativePath()
  51. {
  52. return [
  53. ['/root/path/', 'sub', 'sub'],
  54. ['/root/path/', '/sub', '/sub'],
  55. ['/root/path/', '/root/path/sub', 'sub'],
  56. ['/root/path/sub', '/root/path/other', '/root/path/other'],
  57. ];
  58. }
  59. }