ftp.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * @author Joas Schilling <nickvergessen@owncloud.com>
  4. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  5. * @author Morris Jobke <hey@morrisjobke.de>
  6. * @author Robin Appelman <icewind@owncloud.com>
  7. * @author Thomas Müller <thomas.mueller@tmit.eu>
  8. * @author Vincent Petry <pvince81@owncloud.com>
  9. *
  10. * @copyright Copyright (c) 2016, ownCloud, Inc.
  11. * @license AGPL-3.0
  12. *
  13. * This code is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License, version 3,
  15. * as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License, version 3,
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>
  24. *
  25. */
  26. namespace Test\Files\Storage;
  27. /**
  28. * Class FTP
  29. *
  30. * @group DB
  31. *
  32. * @package Test\Files\Storage
  33. */
  34. class FTP extends Storage {
  35. private $config;
  36. protected function setUp() {
  37. parent::setUp();
  38. $id = $this->getUniqueID();
  39. $this->config = include('files_external/tests/config.ftp.php');
  40. if ( ! is_array($this->config) or ! $this->config['run']) {
  41. $this->markTestSkipped('FTP backend not configured');
  42. }
  43. $this->config['root'] .= '/' . $id; //make sure we have an new empty folder to work in
  44. $this->instance = new \OC\Files\Storage\FTP($this->config);
  45. $this->instance->mkdir('/');
  46. }
  47. protected function tearDown() {
  48. if ($this->instance) {
  49. \OCP\Files::rmdirr($this->instance->constructUrl(''));
  50. }
  51. parent::tearDown();
  52. }
  53. public function testConstructUrl(){
  54. $config = array ( 'host' => 'localhost',
  55. 'user' => 'ftp',
  56. 'password' => 'ftp',
  57. 'root' => '/',
  58. 'secure' => false );
  59. $instance = new \OC\Files\Storage\FTP($config);
  60. $this->assertEquals('ftp://ftp:ftp@localhost/', $instance->constructUrl(''));
  61. $config['secure'] = true;
  62. $instance = new \OC\Files\Storage\FTP($config);
  63. $this->assertEquals('ftps://ftp:ftp@localhost/', $instance->constructUrl(''));
  64. $config['secure'] = 'false';
  65. $instance = new \OC\Files\Storage\FTP($config);
  66. $this->assertEquals('ftp://ftp:ftp@localhost/', $instance->constructUrl(''));
  67. $config['secure'] = 'true';
  68. $instance = new \OC\Files\Storage\FTP($config);
  69. $this->assertEquals('ftps://ftp:ftp@localhost/', $instance->constructUrl(''));
  70. $config['root'] = '';
  71. $instance = new \OC\Files\Storage\FTP($config);
  72. $this->assertEquals('ftps://ftp:ftp@localhost/somefile.txt', $instance->constructUrl('somefile.txt'));
  73. $config['root'] = '/abc';
  74. $instance = new \OC\Files\Storage\FTP($config);
  75. $this->assertEquals('ftps://ftp:ftp@localhost/abc/somefile.txt', $instance->constructUrl('somefile.txt'));
  76. $config['root'] = '/abc/';
  77. $instance = new \OC\Files\Storage\FTP($config);
  78. $this->assertEquals('ftps://ftp:ftp@localhost/abc/somefile.txt', $instance->constructUrl('somefile.txt'));
  79. }
  80. }