summaryrefslogtreecommitdiff
path: root/ext/ftp/tests
diff options
context:
space:
mode:
authorGabriel Caruso <carusogabriel34@gmail.com>2018-02-18 19:45:39 -0300
committerJoe Watkins <krakjoe@php.net>2018-02-19 08:27:37 +0100
commit5153413ed467b10276e4ebeba741fa1aad086d07 (patch)
tree854c6adbf3af82b06842fbfdeb53d77e35405f19 /ext/ftp/tests
parent6d785a7a00729bdd046e7ab9d84bd5f2a71e9406 (diff)
downloadphp-git-5153413ed467b10276e4ebeba741fa1aad086d07.tar.gz
Test more functions of ftp
Diffstat (limited to 'ext/ftp/tests')
-rw-r--r--ext/ftp/tests/ftp_delete.phpt18
-rw-r--r--ext/ftp/tests/ftp_fput.phpt21
-rw-r--r--ext/ftp/tests/ftp_get_option.phpt27
-rw-r--r--ext/ftp/tests/ftp_nb_fput.phpt21
-rw-r--r--ext/ftp/tests/ftp_nb_put.phpt21
-rw-r--r--ext/ftp/tests/ftp_pasv.phpt18
-rw-r--r--ext/ftp/tests/ftp_rawlist_basic1.phpt18
-rw-r--r--ext/ftp/tests/ftp_set_option.phpt22
-rw-r--r--ext/ftp/tests/ftp_set_option_errors.phpt36
-rw-r--r--ext/ftp/tests/server.inc4
10 files changed, 205 insertions, 1 deletions
diff --git a/ext/ftp/tests/ftp_delete.phpt b/ext/ftp/tests/ftp_delete.phpt
new file mode 100644
index 0000000000..2883aa5341
--- /dev/null
+++ b/ext/ftp/tests/ftp_delete.phpt
@@ -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
index 0000000000..7d53283e3d
--- /dev/null
+++ b/ext/ftp/tests/ftp_fput.phpt
@@ -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
index 0000000000..06b34fc720
--- /dev/null
+++ b/ext/ftp/tests/ftp_get_option.phpt
@@ -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
index 0000000000..1ec09283dd
--- /dev/null
+++ b/ext/ftp/tests/ftp_nb_fput.phpt
@@ -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
index 0000000000..691c35aa46
--- /dev/null
+++ b/ext/ftp/tests/ftp_nb_put.phpt
@@ -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
index 0000000000..318f1ca72c
--- /dev/null
+++ b/ext/ftp/tests/ftp_pasv.phpt
@@ -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
index 0000000000..5a706ad710
--- /dev/null
+++ b/ext/ftp/tests/ftp_rawlist_basic1.phpt
@@ -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
index 0000000000..675b4008f5
--- /dev/null
+++ b/ext/ftp/tests/ftp_set_option.phpt
@@ -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
index 0000000000..1ad8a072c9
--- /dev/null
+++ b/ext/ftp/tests/ftp_set_option_errors.phpt
@@ -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)
diff --git a/ext/ftp/tests/server.inc b/ext/ftp/tests/server.inc
index d94844b218..fb9ff57225 100644
--- a/ext/ftp/tests/server.inc
+++ b/ext/ftp/tests/server.inc
@@ -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)) {