3 namespace Drupal\Tests\system\Functional\FileTransfer;
5 use Drupal\Core\FileTransfer\FileTransfer;
6 use Drupal\Core\FileTransfer\FileTransferException;
9 * Mock FileTransfer object for test case.
11 class TestFileTransfer extends FileTransfer {
12 protected $host = NULL;
13 protected $username = NULL;
14 protected $password = NULL;
15 protected $port = NULL;
18 * This is for testing the CopyRecursive logic.
22 public $shouldIsDirectoryReturnTrue = FALSE;
24 public function __construct($jail, $username, $password, $hostname = 'localhost', $port = 9999) {
25 parent::__construct($jail, $username, $password, $hostname, $port);
28 public static function factory($jail, $settings) {
29 return new TestFileTransfer($jail, $settings['username'], $settings['password'], $settings['hostname'], $settings['port']);
32 public function connect() {
33 $this->connection = new MockTestConnection();
34 $this->connection->connectionString = 'test://' . urlencode($this->username) . ':' . urlencode($this->password) . "@$this->host:$this->port/";
37 public function copyFileJailed($source, $destination) {
38 $this->connection->run("copyFile $source $destination");
41 protected function removeDirectoryJailed($directory) {
42 $this->connection->run("rmdir $directory");
45 public function createDirectoryJailed($directory) {
46 $this->connection->run("mkdir $directory");
49 public function removeFileJailed($destination) {
50 if (!ftp_delete($this->connection, $item)) {
51 throw new FileTransferException('Unable to remove the file @file.', NULL, ['@file' => $item]);
55 public function isDirectory($path) {
56 return $this->shouldIsDirectoryReturnTrue;
59 public function isFile($path) {
63 public function chmodJailed($path, $mode, $recursive) {