Skip to content
This repository was archived by the owner on Aug 24, 2021. It is now read-only.

Add FTP delete basic tests #148

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions ext/ftp/tests/ftp_delete_basic.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
--TEST--
Testing ftp_delete basic
--CREDITS--
Ward Cappelle <[email protected]>
User Group: PHP-WVL & PHPGent #PHPTestFest
--SKIPIF--
<?php
require 'skipif.inc';
?>
--FILE--
<?php
require 'server.inc';

$ftp = ftp_connect('127.0.0.1', $port);
if (!$ftp) die("Couldn't connect to the server");
ftp_login($ftp, 'user', 'pass');

echo "Test case #1: removal of existing file from FTP, should return true:", PHP_EOL;
var_dump(ftp_delete($ftp, 'file1'));

echo "Test case #2: removal of non-existent file from FTP, should return false:", PHP_EOL;
var_dump(ftp_delete($ftp, 'false-file.boo'));

ftp_close($ftp);
?>
--EXPECTF--
Test case #1: removal of existing file from FTP, should return true:
bool(true)
Test case #2: removal of non-existent file from FTP, should return false:

Warning: ftp_delete(): No such file or directory in %s on line %d
bool(false)
6 changes: 6 additions & 0 deletions ext/ftp/tests/server.inc
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,12 @@ if ($pid) {
fputs($s, "550 No file named \"{$matches [1]}\"\r\n");
break;
}
} elseif (preg_match('/^DELE ([\w\h]+)/', $buf, $matches)) {
if (isset($matches[1]) && in_array($matches[1], ['file1', "file\nb0rk"])){
fputs($s, "250 Delete successful\r\n");
} else {
fputs($s, "550 No such file or directory\r\n");
}
}elseif (preg_match('/^RETR ([\w\h]+)/', $buf, $matches)) {
if(!empty($pasv)){
;
Expand Down