Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / system / tests / src / Functional / FileTransfer / TestFileTransfer.php
1 <?php
2
3 namespace Drupal\Tests\system\Functional\FileTransfer;
4
5 use Drupal\Core\FileTransfer\FileTransfer;
6 use Drupal\Core\FileTransfer\FileTransferException;
7
8 /**
9  * Mock FileTransfer object for test case.
10  */
11 class TestFileTransfer extends FileTransfer {
12   protected $host = NULL;
13   protected $username = NULL;
14   protected $password = NULL;
15   protected $port = NULL;
16
17   /**
18    * This is for testing the CopyRecursive logic.
19    */
20   public $shouldIsDirectoryReturnTrue = FALSE;
21
22   public function __construct($jail, $username, $password, $hostname = 'localhost', $port = 9999) {
23     parent::__construct($jail, $username, $password, $hostname, $port);
24   }
25
26   public static function factory($jail, $settings) {
27     return new TestFileTransfer($jail, $settings['username'], $settings['password'], $settings['hostname'], $settings['port']);
28   }
29
30   public function connect() {
31     $this->connection = new MockTestConnection();
32     $this->connection->connectionString = 'test://' . urlencode($this->username) . ':' . urlencode($this->password) . "@$this->host:$this->port/";
33   }
34
35   public function copyFileJailed($source, $destination) {
36     $this->connection->run("copyFile $source $destination");
37   }
38
39   protected function removeDirectoryJailed($directory) {
40     $this->connection->run("rmdir $directory");
41   }
42
43   public function createDirectoryJailed($directory) {
44     $this->connection->run("mkdir $directory");
45   }
46
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]);
50     }
51   }
52
53   public function isDirectory($path) {
54     return $this->shouldIsDirectoryReturnTrue;
55   }
56
57   public function isFile($path) {
58     return FALSE;
59   }
60
61   public function chmodJailed($path, $mode, $recursive) {
62     return;
63   }
64
65 }