ftp.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * Copyright (c) 2012 Robin Appelman <icewind@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\Files\Storage;
  9. class FTP extends Storage {
  10. private $config;
  11. protected function setUp() {
  12. parent::setUp();
  13. $id = $this->getUniqueID();
  14. $this->config = include('files_external/tests/config.php');
  15. if ( ! is_array($this->config) or ! isset($this->config['ftp']) or ! $this->config['ftp']['run']) {
  16. $this->markTestSkipped('FTP backend not configured');
  17. }
  18. $this->config['ftp']['root'] .= '/' . $id; //make sure we have an new empty folder to work in
  19. $this->instance = new \OC\Files\Storage\FTP($this->config['ftp']);
  20. $this->instance->mkdir('/');
  21. }
  22. protected function tearDown() {
  23. if ($this->instance) {
  24. \OCP\Files::rmdirr($this->instance->constructUrl(''));
  25. }
  26. parent::tearDown();
  27. }
  28. public function testConstructUrl(){
  29. $config = array ( 'host' => 'localhost',
  30. 'user' => 'ftp',
  31. 'password' => 'ftp',
  32. 'root' => '/',
  33. 'secure' => false );
  34. $instance = new \OC\Files\Storage\FTP($config);
  35. $this->assertEquals('ftp://ftp:ftp@localhost/', $instance->constructUrl(''));
  36. $config['secure'] = true;
  37. $instance = new \OC\Files\Storage\FTP($config);
  38. $this->assertEquals('ftps://ftp:ftp@localhost/', $instance->constructUrl(''));
  39. $config['secure'] = 'false';
  40. $instance = new \OC\Files\Storage\FTP($config);
  41. $this->assertEquals('ftp://ftp:ftp@localhost/', $instance->constructUrl(''));
  42. $config['secure'] = 'true';
  43. $instance = new \OC\Files\Storage\FTP($config);
  44. $this->assertEquals('ftps://ftp:ftp@localhost/', $instance->constructUrl(''));
  45. $config['root'] = '';
  46. $instance = new \OC\Files\Storage\FTP($config);
  47. $this->assertEquals('ftps://ftp:ftp@localhost/somefile.txt', $instance->constructUrl('somefile.txt'));
  48. $config['root'] = '/abc';
  49. $instance = new \OC\Files\Storage\FTP($config);
  50. $this->assertEquals('ftps://ftp:ftp@localhost/abc/somefile.txt', $instance->constructUrl('somefile.txt'));
  51. $config['root'] = '/abc/';
  52. $instance = new \OC\Files\Storage\FTP($config);
  53. $this->assertEquals('ftps://ftp:ftp@localhost/abc/somefile.txt', $instance->constructUrl('somefile.txt'));
  54. }
  55. }