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.
20 public $shouldIsDirectoryReturnTrue = FALSE;
22 public function __construct($jail, $username, $password, $hostname = 'localhost', $port = 9999) {
23 parent::__construct($jail, $username, $password, $hostname, $port);
26 public static function factory($jail, $settings) {
27 return new TestFileTransfer($jail, $settings['username'], $settings['password'], $settings['hostname'], $settings['port']);
30 public function connect() {
31 $this->connection = new MockTestConnection();
32 $this->connection->connectionString = 'test://' . urlencode($this->username) . ':' . urlencode($this->password) . "@$this->host:$this->port/";
35 public function copyFileJailed($source, $destination) {
36 $this->connection->run("copyFile $source $destination");
39 protected function removeDirectoryJailed($directory) {
40 $this->connection->run("rmdir $directory");
43 public function createDirectoryJailed($directory) {
44 $this->connection->run("mkdir $directory");
47 public function removeFileJailed($destination) {
48 if (!ftp_delete($this->connection, $item)) {
49 throw new FileTransferException('Unable to remove to file @file.', NULL, ['@file' => $item]);
53 public function isDirectory($path) {
54 return $this->shouldIsDirectoryReturnTrue;
57 public function isFile($path) {
61 public function chmodJailed($path, $mode, $recursive) {