FTPTest.php 4.1 KB

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