48e57845dd70b03b417b719b01027179835cff3e
[yaffs-website] / 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    * @var bool
21    */
22   public $shouldIsDirectoryReturnTrue = FALSE;
23
24   public function __construct($jail, $username, $password, $hostname = 'localhost', $port = 9999) {
25     parent::__construct($jail, $username, $password, $hostname, $port);
26   }
27
28   public static function factory($jail, $settings) {
29     return new TestFileTransfer($jail, $settings['username'], $settings['password'], $settings['hostname'], $settings['port']);
30   }
31
32   public function connect() {
33     $this->connection = new MockTestConnection();
34     $this->connection->connectionString = 'test://' . urlencode($this->username) . ':' . urlencode($this->password) . "@$this->host:$this->port/";
35   }
36
37   public function copyFileJailed($source, $destination) {
38     $this->connection->run("copyFile $source $destination");
39   }
40
41   protected function removeDirectoryJailed($directory) {
42     $this->connection->run("rmdir $directory");
43   }
44
45   public function createDirectoryJailed($directory) {
46     $this->connection->run("mkdir $directory");
47   }
48
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]);
52     }
53   }
54
55   public function isDirectory($path) {
56     return $this->shouldIsDirectoryReturnTrue;
57   }
58
59   public function isFile($path) {
60     return FALSE;
61   }
62
63   public function chmodJailed($path, $mode, $recursive) {
64     return;
65   }
66
67 }