FtpTest.php 3.1 KB

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