FtpTest.php 3.0 KB

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