]> granicus.if.org Git - php/commitdiff
Test more functions of ftp
authorGabriel Caruso <carusogabriel34@gmail.com>
Sun, 18 Feb 2018 22:45:39 +0000 (19:45 -0300)
committerJoe Watkins <krakjoe@php.net>
Mon, 19 Feb 2018 07:27:37 +0000 (08:27 +0100)
ext/ftp/tests/ftp_delete.phpt [new file with mode: 0644]
ext/ftp/tests/ftp_fput.phpt [new file with mode: 0644]
ext/ftp/tests/ftp_get_option.phpt [new file with mode: 0644]
ext/ftp/tests/ftp_nb_fput.phpt [new file with mode: 0644]
ext/ftp/tests/ftp_nb_put.phpt [new file with mode: 0644]
ext/ftp/tests/ftp_pasv.phpt [new file with mode: 0644]
ext/ftp/tests/ftp_rawlist_basic1.phpt [new file with mode: 0644]
ext/ftp/tests/ftp_set_option.phpt [new file with mode: 0644]
ext/ftp/tests/ftp_set_option_errors.phpt [new file with mode: 0644]
ext/ftp/tests/server.inc

diff --git a/ext/ftp/tests/ftp_delete.phpt b/ext/ftp/tests/ftp_delete.phpt
new file mode 100644 (file)
index 0000000..2883aa5
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--
+Testing ftp_delete basic functionality
+--CREDITS--
+Gabriel Caruso (carusogabriel34@gmail.com)
+--SKIPIF--
+<?php require 'skipif.inc'; ?>
+--FILE--
+<?php
+require 'server.inc';
+
+$ftp = ftp_connect('127.0.0.1', $port);
+ftp_login($ftp, 'user', 'pass');
+$ftp or die("Couldn't connect to the server");
+
+var_dump(ftp_delete($ftp, 'file'));
+?>
+--EXPECT--
+bool(true)
diff --git a/ext/ftp/tests/ftp_fput.phpt b/ext/ftp/tests/ftp_fput.phpt
new file mode 100644 (file)
index 0000000..7d53283
--- /dev/null
@@ -0,0 +1,21 @@
+--TEST--
+Testing ftp_fput basic functionality
+--CREDITS--
+Gabriel Caruso (carusogabriel34@gmail.com)
+--SKIPIF--
+<?php require 'skipif.inc'; ?>
+--FILE--
+<?php
+require 'server.inc';
+
+$ftp = ftp_connect('127.0.0.1', $port);
+ftp_login($ftp, 'user', 'pass');
+$ftp or die("Couldn't connect to the server");
+
+$destination_file = basename(__FILE__);
+$source_file = fopen(__FILE__, 'r');
+
+var_dump(ftp_fput($ftp, $destination_file, $source_file, FTP_ASCII));
+?>
+--EXPECT--
+bool(true)
diff --git a/ext/ftp/tests/ftp_get_option.phpt b/ext/ftp/tests/ftp_get_option.phpt
new file mode 100644 (file)
index 0000000..06b34fc
--- /dev/null
@@ -0,0 +1,27 @@
+--TEST--
+Testing ftp_get_option basic functionality
+--CREDITS--
+Gabriel Caruso (carusogabriel34@gmail.com)
+--SKIPIF--
+<?php require 'skipif.inc'; ?>
+--FILE--
+<?php
+require 'server.inc';
+define('FOO_BAR', 10);
+
+$ftp = ftp_connect('127.0.0.1', $port);
+ftp_login($ftp, 'user', 'pass');
+$ftp or die("Couldn't connect to the server");
+
+var_dump(ftp_get_option($ftp, FTP_TIMEOUT_SEC));
+var_dump(ftp_get_option($ftp, FTP_AUTOSEEK));
+var_dump(ftp_get_option($ftp, FTP_USEPASVADDRESS));
+var_dump(ftp_get_option($ftp, FOO_BAR));
+?>
+--EXPECTF--
+int(%d)
+bool(true)
+bool(true)
+
+Warning: ftp_get_option(): Unknown option '10' in %s on line %d
+bool(false)
diff --git a/ext/ftp/tests/ftp_nb_fput.phpt b/ext/ftp/tests/ftp_nb_fput.phpt
new file mode 100644 (file)
index 0000000..1ec0928
--- /dev/null
@@ -0,0 +1,21 @@
+--TEST--
+Testing ftp_nb_fput basic functionality
+--CREDITS--
+Gabriel Caruso (carusogabriel34@gmail.com)
+--SKIPIF--
+<?php require 'skipif.inc'; ?>
+--FILE--
+<?php
+require 'server.inc';
+
+$ftp = ftp_connect('127.0.0.1', $port);
+ftp_login($ftp, 'user', 'pass');
+$ftp or die("Couldn't connect to the server");
+
+$destination_file = basename(__FILE__);
+$source_file = fopen(__FILE__, 'r');
+
+var_dump(ftp_nb_fput($ftp, $destination_file, $source_file, FTP_ASCII));
+?>
+--EXPECT--
+int(1)
diff --git a/ext/ftp/tests/ftp_nb_put.phpt b/ext/ftp/tests/ftp_nb_put.phpt
new file mode 100644 (file)
index 0000000..691c35a
--- /dev/null
@@ -0,0 +1,21 @@
+--TEST--
+Testing ftp_nb_put basic functionality
+--CREDITS--
+Gabriel Caruso (carusogabriel34@gmail.com)
+--SKIPIF--
+<?php require 'skipif.inc'; ?>
+--FILE--
+<?php
+require 'server.inc';
+
+$ftp = ftp_connect('127.0.0.1', $port);
+ftp_login($ftp, 'user', 'pass');
+$ftp or die("Couldn't connect to the server");
+
+$destination_file = basename(__FILE__);
+$source_file = __FILE__;
+
+var_dump(ftp_nb_put($ftp, $destination_file, $source_file, FTP_ASCII));
+?>
+--EXPECT--
+int(1)
diff --git a/ext/ftp/tests/ftp_pasv.phpt b/ext/ftp/tests/ftp_pasv.phpt
new file mode 100644 (file)
index 0000000..318f1ca
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--
+Testing ftp_pasv basic funcionality
+--CREDITS--
+Gabriel Caruso (carusogabriel34@gmail.com)
+--SKIPIF--
+<?php require 'skipif.inc'; ?>
+--FILE--
+<?php
+require 'server.inc';
+
+$ftp = ftp_connect('127.0.0.1', $port);
+ftp_login($ftp, 'user', 'pass');
+$ftp or die("Couldn't connect to the server");
+
+var_dump(ftp_pasv($ftp, false));
+?>
+--EXPECT--
+bool(true)
diff --git a/ext/ftp/tests/ftp_rawlist_basic1.phpt b/ext/ftp/tests/ftp_rawlist_basic1.phpt
new file mode 100644 (file)
index 0000000..5a706ad
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--
+Testing ftp_rawlist basic functionality
+--CREDITS--
+Gabriel Caruso (carusogabriel34@gmail.com)
+--SKIPIF--
+<?php require 'skipif.inc'; ?>
+--FILE--
+<?php
+require 'server.inc';
+
+$ftp = ftp_connect('127.0.0.1', $port);
+ftp_login($ftp, 'user', 'pass');
+$ftp or die("Couldn't connect to the server");
+
+var_dump(is_array(ftp_rawlist($ftp, 'www/')));
+?>
+--EXPECT--
+bool(true)
diff --git a/ext/ftp/tests/ftp_set_option.phpt b/ext/ftp/tests/ftp_set_option.phpt
new file mode 100644 (file)
index 0000000..675b400
--- /dev/null
@@ -0,0 +1,22 @@
+--TEST--
+Testing ftp_set_option basic functionality
+--CREDITS--
+Gabriel Caruso (carusogabriel34@gmail.com)
+--SKIPIF--
+<?php require 'skipif.inc'; ?>
+--FILE--
+<?php
+require 'server.inc';
+
+$ftp = ftp_connect('127.0.0.1', $port);
+ftp_login($ftp, 'user', 'pass');
+$ftp or die("Couldn't connect to the server");
+
+var_dump(ftp_set_option($ftp, FTP_TIMEOUT_SEC, 10));
+var_dump(ftp_set_option($ftp, FTP_AUTOSEEK, false));
+var_dump(ftp_set_option($ftp, FTP_USEPASVADDRESS, true));
+?>
+--EXPECT--
+bool(true)
+bool(true)
+bool(true)
diff --git a/ext/ftp/tests/ftp_set_option_errors.phpt b/ext/ftp/tests/ftp_set_option_errors.phpt
new file mode 100644 (file)
index 0000000..1ad8a07
--- /dev/null
@@ -0,0 +1,36 @@
+--TEST--
+Testing ftp_set_option erros while setting up
+--CREDITS--
+Gabriel Caruso (carusogabriel34@gmail.com)
+--SKIPIF--
+<?php require 'skipif.inc'; ?>
+--FILE--
+<?php
+require 'server.inc';
+define('FOO_BAR', 10);
+
+$ftp = ftp_connect('127.0.0.1', $port);
+ftp_login($ftp, 'user', 'pass');
+$ftp or die("Couldn't connect to the server");
+
+var_dump(ftp_set_option($ftp, FTP_TIMEOUT_SEC, 0));
+var_dump(ftp_set_option($ftp, FTP_TIMEOUT_SEC, '0'));
+var_dump(ftp_set_option($ftp, FTP_USEPASVADDRESS, ['1']));
+var_dump(ftp_set_option($ftp, FTP_AUTOSEEK, 'true'));
+var_dump(ftp_set_option($ftp, FOO_BAR, 1));
+?>
+--EXPECTF--
+Warning: ftp_set_option(): Timeout has to be greater than 0 in %s on line %d
+bool(false)
+
+Warning: ftp_set_option(): Option TIMEOUT_SEC expects value of type int, string given in %s on line %d
+bool(false)
+
+Warning: ftp_set_option(): Option USEPASVADDRESS expects value of type bool, array given in %s on line %d
+bool(false)
+
+Warning: ftp_set_option(): Option AUTOSEEK expects value of type bool, string given in %s on line %d
+bool(false)
+
+Warning: ftp_set_option(): Unknown option '10' in %s on line %d
+bool(false)
index d94844b218d9ac6dcc2d5392c892f79456d32c8f..fb9ff57225e2b625757b55c75ad83364a75903a0 100644 (file)
@@ -454,11 +454,13 @@ if ($pid) {
                } elseif (preg_match('/^SITE CHMOD/', $buf, $matches)) {
                        fputs($s, "200 OK\r\n");
 
+               } elseif (preg_match('/^DELE/', $buf, $matches)) {
+                       fputs($s, "250 OK\r\n");
+
                } elseif (preg_match('/^ALLO (\d+)/', $buf, $matches)) {
                        fputs($s, "200 " . $matches[1] . " bytes allocated\r\n");
 
                }elseif (preg_match('/^LIST www\//', $buf, $matches)) {
-                       fputs($s, "150 Opening ASCII mode data connection for file list\r\n");
                        fputs($s, "226 Transfer complete\r\n");
 
                }elseif (preg_match('/^LIST no_exists\//', $buf, $matches)) {