FtpdTests.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace League\Flysystem\Adapter;
  3. use League\Flysystem\Config;
  4. use PHPUnit\Framework\TestCase;
  5. class FtpdTests extends TestCase
  6. {
  7. protected $options = [
  8. 'host' => 'example.org',
  9. 'port' => 40,
  10. 'ssl' => true,
  11. 'timeout' => 35,
  12. 'root' => '/somewhere',
  13. 'permPublic' => 0777,
  14. 'permPrivate' => 0000,
  15. 'passive' => false,
  16. 'username' => 'user',
  17. 'password' => 'password',
  18. ];
  19. public function testInstantiable()
  20. {
  21. if ( ! defined('FTP_BINARY')) {
  22. $this->markTestSkipped('The FTP_BINARY constant is not defined');
  23. }
  24. $adapter = new Ftpd($this->options);
  25. $listing = $adapter->listContents('', true);
  26. $this->assertIsArray($listing);
  27. $this->assertFalse($adapter->has('syno.not.found'));
  28. $result = $adapter->getMimetype('something.txt');
  29. $this->assertEquals('text/plain', $result['mimetype']);
  30. $this->assertIsArray($adapter->write('syno.unknowndir/file.txt', 'contents', new Config(['visibility' => 'public'])));
  31. $this->assertIsArray($adapter->getTimestamp('some/file.ext'));
  32. }
  33. /**
  34. * @depends testInstantiable
  35. */
  36. public function testGetExistingDirMetadata()
  37. {
  38. $adapter = new Ftpd($this->options);
  39. $dirMetadata = $adapter->getMetadata('spaced.files');
  40. $this->assertSame(['type' => 'dir', 'path' => 'spaced.files'], $dirMetadata);
  41. }
  42. /**
  43. * @depends testInstantiable
  44. */
  45. public function testGetMissingDirMetadata()
  46. {
  47. $adapter = new Ftpd($this->options);
  48. $dirMetadata = $adapter->getMetadata('syno.not.found');
  49. $this->assertFalse($dirMetadata);
  50. }
  51. /**
  52. * @depends testInstantiable
  53. */
  54. public function testRawlistFail()
  55. {
  56. $adapter = new Ftpd($this->options);
  57. $result = $adapter->listContents('fail.rawlist');
  58. $this->assertEquals([], $result);
  59. }
  60. /**
  61. * @depends testInstantiable
  62. */
  63. public function testGetMetadata()
  64. {
  65. $adapter = new Ftpd($this->options);
  66. $result = $adapter->getMetadata('something.txt');
  67. $this->assertNotEmpty($result);
  68. }
  69. /**
  70. * @depends testInstantiable
  71. */
  72. public function testGetMetadataOnRoot()
  73. {
  74. $adapter = new Ftpd($this->options);
  75. $result = $adapter->getMetadata('');
  76. $this->assertNotEmpty($result);
  77. }
  78. /**
  79. * @depends testInstantiable
  80. */
  81. public function testSynologyFtpLegacyClassName()
  82. {
  83. $adapter = new SynologyFtp($this->options);
  84. $this->assertInstanceOf('League\Flysystem\Adapter\Ftpd', $adapter);
  85. }
  86. }