1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
use Codeception\Util\Stub;
/**
* Module for testing remote ftp systems.
*
* ## Status
*
* Maintainer: **nathanmac**
* Stability: **stable**
* Contact: nathan.macnamara@outlook.com
*
*/
class FTPTest extends \PHPUnit\Framework\TestCase
{
protected $config = array(
'host' => '127.0.0.1',
'tmp' => 'temp',
'user' => 'user',
'password' => 'password'
);
/**
* @var \Codeception\Module\FTP
*/
protected $module = null;
public function setUp()
{
$this->module = new \Codeception\Module\FTP(make_container());
$this->module->_setConfig($this->config);
$this->module->_before(Stub::makeEmpty('\Codeception\Test\Test'));
}
/**
* Disabled Test - for travis testing, requires testing server
*/
public function flow()
{
// Check root directory
$this->assertEquals('/', $this->module->grabDirectory());
// Create directory
$this->module->makeDir('TESTING');
// Move to new directory
$this->module->amInPath('TESTING');
// Verify current directory
$this->assertEquals('/TESTING', $this->module->grabDirectory());
$files = $this->module->grabFileList();
// Create files on server
$this->module->writeToFile('test_ftp_123.txt', 'some data added here');
$this->module->writeToFile('test_ftp_567.txt', 'some data added here');
$this->module->writeToFile('test_ftp_678.txt', 'some data added here');
// Grab file list
$files = $this->module->grabFileList();
// Verify files are listed
$this->assertContains('test_ftp_123.txt', $files);
$this->assertContains('test_ftp_567.txt', $files);
$this->assertContains('test_ftp_678.txt', $files);
$this->module->seeFileFound('test_ftp_123.txt');
$this->module->dontSeeFileFound('test_ftp_321.txt');
$this->module->seeFileFoundMatches('/^test_ftp_([0-9]{3}).txt$/');
$this->module->dontSeeFileFoundMatches('/^test_([0-9]{3})_ftp.txt$/');
$this->assertGreaterThan(0, $this->module->grabFileCount());
$this->assertGreaterThan(0, $this->module->grabFileSize('test_ftp_678.txt'));
$this->assertGreaterThan(0, $this->module->grabFileModified('test_ftp_678.txt'));
$this->module->openFile('test_ftp_567.txt');
$this->module->deleteThisFile();
$this->module->dontSeeFileFound('test_ftp_567.txt');
// Open file (download local copy)
$this->module->openFile('test_ftp_123.txt');
$this->module->seeInThisFile('data');
$this->module->dontSeeInThisFile('banana');
$this->module->seeFileContentsEqual('some data added here');
$this->module->renameFile('test_ftp_678.txt', 'test_ftp_987.txt');
$files = $this->module->grabFileList();
// Verify old file is not listed
$this->assertNotContains('test_ftp_678.txt', $files);
// Verify renamed file is listed
$this->assertContains('test_ftp_987.txt', $files);
$this->module->deleteFile('test_ftp_123.txt');
$files = $this->module->grabFileList();
// Verify deleted file is not listed
$this->assertNotContains('test_ftp_123.txt', $files);
// Move to root directory
$this->module->amInPath('/');
$this->assertEquals('/', $this->module->grabDirectory());
$this->module->renameDir('TESTING', 'TESTING_NEW');
// Remove directory (with contents)
$this->module->deleteDir('TESTING_NEW');
// Test Clearing the Directory
$this->module->makeDir('TESTING');
$this->module->amInPath('TESTING');
$this->module->writeToFile('test_ftp_123.txt', 'some data added here');
$this->module->amInPath('/');
$this->assertGreaterThan(0, $this->module->grabFileCount('TESTING'));
$this->module->cleanDir('TESTING');
$this->assertEquals(0, $this->module->grabFileCount('TESTING'));
$this->module->deleteDir('TESTING');
}
public function tearDown()
{
$this->module->_after(Stub::makeEmpty('\Codeception\Test\Test'));
}
}