diff options
author | Ulf Wendel <uw@php.net> | 2007-10-10 09:53:34 +0000 |
---|---|---|
committer | Ulf Wendel <uw@php.net> | 2007-10-10 09:53:34 +0000 |
commit | f01e360850b952ad94f984531db482c8bf429426 (patch) | |
tree | 5effcde20de845039819655aa4ace33d6e3b421c /ext/mysql | |
parent | dd9292e225dd92b1caef1bc97d0f740495d37aaf (diff) | |
download | php-git-f01e360850b952ad94f984531db482c8bf429426.tar.gz |
Next set of new tests - more to follow. Trying to find reasonable commit size...
Diffstat (limited to 'ext/mysql')
-rw-r--r-- | ext/mysql/tests/mysql_data_seek.phpt | 70 | ||||
-rw-r--r-- | ext/mysql/tests/mysql_db_name.phpt | 63 | ||||
-rw-r--r-- | ext/mysql/tests/mysql_db_query.phpt | 58 | ||||
-rw-r--r-- | ext/mysql/tests/mysql_drop_db.phpt | 43 | ||||
-rw-r--r-- | ext/mysql/tests/mysql_get_client_info.phpt | 23 | ||||
-rw-r--r-- | ext/mysql/tests/mysql_get_host_info.phpt | 40 | ||||
-rw-r--r-- | ext/mysql/tests/mysql_get_proto_info.phpt | 30 | ||||
-rw-r--r-- | ext/mysql/tests/mysql_get_server_info.phpt | 39 | ||||
-rw-r--r-- | ext/mysql/tests/mysql_info.phpt | 69 | ||||
-rw-r--r-- | ext/mysql/tests/mysql_insert_id.phpt | 66 |
10 files changed, 501 insertions, 0 deletions
diff --git a/ext/mysql/tests/mysql_data_seek.phpt b/ext/mysql/tests/mysql_data_seek.phpt new file mode 100644 index 0000000000..21ebad692b --- /dev/null +++ b/ext/mysql/tests/mysql_data_seek.phpt @@ -0,0 +1,70 @@ +--TEST-- +mysql_data_seek() +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php +include "connect.inc"; + +$tmp = NULL; +$link = NULL; + +if (NULL !== ($tmp = @mysql_data_seek())) + printf("[001] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); + +if (NULL !== ($tmp = @mysql_data_seek($link))) + printf("[002] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); + +if (false !== ($tmp = @mysql_data_seek($link, $link))) + printf("[003] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); + +require('table.inc'); +if (!$res = mysql_query('SELECT * FROM test ORDER BY id LIMIT 4', $link)) + printf("[004] [%d] %s\n", mysql_errno($link), mysql_error($link)); + +if (true !== ($tmp = mysql_data_seek($res, 3))) + printf("[005] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp); + +$row = mysql_fetch_assoc($res); +if (4 != $row['id']) + printf("[006] Expecting record 4/d, got record %s/%s\n", $row['id'], $row['label']); + +if (true !== ($tmp = mysql_data_seek($res, 0))) + printf("[007] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp); + +$row = mysql_fetch_assoc($res); +if (1 != $row['id']) + printf("[008] Expecting record 1/a, got record %s/%s\n", $row['id'], $row['label']); + +if (false !== ($tmp = mysql_data_seek($res, 4))) + printf("[009] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); + +if (false !== ($tmp = mysql_data_seek($res, -1))) + printf("[010] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); + +mysql_free_result($res); + +if (!$res = mysql_unbuffered_query('SELECT * FROM test ORDER BY id', $link)) + printf("[011] [%d] %s\n", mysql_errno($link), mysql_error($link)); + +if (false !== ($tmp = mysql_data_seek($res, 3))) + printf("[012] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); + +mysql_free_result($res); + +if (false !== ($tmp = mysql_data_seek($res, 1))) + printf("[013] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); + +mysql_close($link); + +print "done!\n"; +?> +--EXPECTF-- +Warning: mysql_data_seek(): Offset 4 is invalid for MySQL result index %d (or the query data is unbuffered) in %s on line %d + +Warning: mysql_data_seek(): Offset -1 is invalid for MySQL result index %d (or the query data is unbuffered) in %s on line %d + +Warning: mysql_data_seek(): Offset 3 is invalid for MySQL result index %d (or the query data is unbuffered) in %s on line %d + +Warning: mysql_data_seek(): %d is not a valid MySQL result resource in %s on line %d +done!
\ No newline at end of file diff --git a/ext/mysql/tests/mysql_db_name.phpt b/ext/mysql/tests/mysql_db_name.phpt new file mode 100644 index 0000000000..8e81c76e95 --- /dev/null +++ b/ext/mysql/tests/mysql_db_name.phpt @@ -0,0 +1,63 @@ +--TEST-- +mysql_db_name() +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php +include "connect.inc"; + +$tmp = NULL; +$link = NULL; + +if (NULL !== ($tmp = @mysql_db_name())) + printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + +if (false !== ($tmp = @mysql_db_name($link, $link))) + printf("[002] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); + +require('table.inc'); + +if (!$res = mysql_list_dbs($link)) + printf("[003] [%d] %s\n", mysql_errno($link), mysql_error($link)); + +if (!$num = mysql_num_rows($res)) + printf("[004] Empty database list? [%d] %s\n", mysql_errno($link), mysql_error($link)); + +if (false !== ($tmp = mysql_db_name($res, -1))) + printf("[005] Expecting boolean/false, got %s/%s. [%d] %s\n", + gettype($tmp), $tmp, mysql_errno($link), mysql_error($link)); + +if (false !== ($tmp = mysql_db_name($res, $num + 1))) + printf("[006] Expecting boolean/false, got %s/%s. [%d] %s\n", + gettype($tmp), $tmp, mysql_errno($link), mysql_error($link)); + +$unicode = (boolean)ini_get('unicode.semantics'); +for ($i = 0; $i < $num; $i++) { + if ('' === ($dbname = mysql_db_name($res, $i))) + printf("[%03d] Got empty database name! [%d] %s\n", + (($i * 2) + 1) + 6, mysql_errno($link), mysql_error($link)); + + if ($unicode && !is_unicode($dbname)) { + printf("[%03d] Expecting unicode string! [%d] %s\n", + (($i * 2) + 2) + 6, mysql_errno($link), mysql_error($link)); + var_inspect($dbname); + } +} + +mysql_free_result($res); + +if (false !== ($tmp = mysql_db_name($res, $num))) + printf("[999] Expecting boolean/false, got %s/%s. [%d] %s\n", + gettype($tmp), $tmp, mysql_errno($link), mysql_error($link)); + +mysql_close($link); + +print "done!\n"; +?> +--EXPECTF-- +Warning: mysql_db_name(): Unable to jump to row -1 on MySQL result index %d in %s on line %d + +Warning: mysql_db_name(): Unable to jump to row %d on MySQL result index %d in %s on line %d + +Warning: mysql_db_name(): %d is not a valid MySQL result resource in %s on line %d +done!
\ No newline at end of file diff --git a/ext/mysql/tests/mysql_db_query.phpt b/ext/mysql/tests/mysql_db_query.phpt new file mode 100644 index 0000000000..421e9f592d --- /dev/null +++ b/ext/mysql/tests/mysql_db_query.phpt @@ -0,0 +1,58 @@ +--TEST-- +mysql_db_query() +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php +include "connect.inc"; + +// NOTE: this function is deprecated. We do only the most necessary +// to test it. We don't test all aspects of the documented behaviour. + +$tmp = NULL; +$link = NULL; + +if (NULL !== ($tmp = @mysql_db_query())) + printf("[001] Expecting NULL/NULL, got %s/%s\n", gettype($tmp), $tmp); + +if (NULL !== ($tmp = @mysql_db_query($link))) + printf("[002] Expecting NULL/NULL, got %s/%s\n", gettype($tmp), $tmp); + +if (NULL !== ($tmp = @mysql_db_query($link))) + printf("[003] Expecting NULL/NULL, got %s/%s\n", gettype($tmp), $tmp); + +require('table.inc'); +if (!$res = mysql_db_query($db, 'SELECT id, label FROM test ORDER BY id LIMIT 1', $link)) + printf("[004] [%d] %s\n", mysql_errno($link), mysql_error($link)); + +$row = mysql_fetch_assoc($res); +if (1 != $row['id']) + printf("[005] Expecting record 1/a, got record %s/%s\n", $row['id'], $row['label']); + +if (ini_get('unicode.semantics') && !is_unicode($row['label'])) { + printf("[006] No unicode returned! [%d] %s\n", mysql_errno($link), mysql_error($link)); + var_inspect($row); +} + +mysql_free_result($res); + + +if (!$res = mysql_db_query($db, 'SELECT id, label FROM test ORDER BY id LIMIT 1')) + printf("[007] [%d] %s\n", mysql_errno(), mysql_error()); + +$row = mysql_fetch_assoc($res); +if (1 != $row['id']) + printf("[008] Expecting record 1/a, got record %s/%s\n", $row['id'], $row['label']); + +if (ini_get('unicode.semantics') && !is_unicode($row['label'])) { + printf("[009] No unicode returned! [%d] %s\n", mysql_errno(), mysql_error()); + var_inspect($row); +} + +mysql_free_result($res); +mysql_close($link); + +print "done!\n"; +?> +--EXPECTF-- +done!
\ No newline at end of file diff --git a/ext/mysql/tests/mysql_drop_db.phpt b/ext/mysql/tests/mysql_drop_db.phpt new file mode 100644 index 0000000000..fb42f7b22e --- /dev/null +++ b/ext/mysql/tests/mysql_drop_db.phpt @@ -0,0 +1,43 @@ +--TEST-- +mysql_drop_db() +--SKIPIF-- +<?php +require_once('skipif.inc'); +if (!function_exists('mysql_drop_db')) + die("Skip function is deprecated and not available"); +?> +--FILE-- +<?php +include_once "connect.inc"; + +$tmp = NULL; +$link = NULL; + +// NOTE: again this test does not test all of the behaviour of the function + +if (NULL !== ($tmp = mysql_drop_db())) + printf("[001] Expecting NULL/NULL, got %s/%s\n", gettype($tmp), $tmp); + +require('table.inc'); +if (!mysql_query('DROP DATABASE IF EXISTS mysqldropdb')) + printf("[004] [%d] %s\n", mysql_errno($link), mysql_error($link)); + +if (!mysql_query('CREATE DATABASE mysqldropdb')) + die(sprintf("[005] Skipping, can't create test database. [%d] %s\n", mysql_errno($link), mysql_error($link))); + +if (true !== ($tmp = mysql_drop_db('mysqldropdb', $link))) + printf("[006] Can't drop, got %s/%s. [%d] %s\n", + gettype($tmp), $tmp, + mysql_errno($link), mysql_error($link)); + +if (false !== ($tmp = mysql_drop_db('mysqldropdb', $link))) + printf("[007] Expecting boolean/false, got %s/%s. [%d] %s\n", + gettype($tmp), $tmp, + mysql_errno($link), mysql_error($link)); + +mysql_close($link); + +print "done!\n"; +?> +--EXPECTF-- +done!
\ No newline at end of file diff --git a/ext/mysql/tests/mysql_get_client_info.phpt b/ext/mysql/tests/mysql_get_client_info.phpt new file mode 100644 index 0000000000..2f8c62c916 --- /dev/null +++ b/ext/mysql/tests/mysql_get_client_info.phpt @@ -0,0 +1,23 @@ +--TEST-- +mysql_get_client_info() +--SKIPIF-- +<?php require_once('skipif.inc'); ?> +--FILE-- +<?php +include "connect.inc"; +if (!is_string($info = mysql_get_client_info()) || ('' === $info)) + printf("[001] Expecting string/any_non_empty, got %s/%s\n", gettype($info), $info); + +if (ini_get('unicode.semantics') && !is_unicode($info)) { + printf("[002] Expecting Unicode!\n"); + var_inspect($info); +} + +if (!is_null($tmp = @mysql_get_client_info("too many arguments"))) { + printf("[003] Expecting NULL/NULL got %s/%s\n", $tmp, gettype($tmp)); +} + +print "done!"; +?> +--EXPECTF-- +done!
\ No newline at end of file diff --git a/ext/mysql/tests/mysql_get_host_info.phpt b/ext/mysql/tests/mysql_get_host_info.phpt new file mode 100644 index 0000000000..213a792fd8 --- /dev/null +++ b/ext/mysql/tests/mysql_get_host_info.phpt @@ -0,0 +1,40 @@ +--TEST-- +mysql_get_host_info() +--SKIPIF-- +<?php +require_once('skipif.inc'); +require_once('skipifconnectfailure.inc'); +?> +--FILE-- +<?php +include_once "connect.inc"; + +if (false !== ($tmp = @mysql_get_host_info(NULL))) + printf("[001] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); + +require "table.inc"; +if (!is_string($info = mysql_get_host_info($link)) || ('' === $info)) + printf("[003] Expecting string/any_non_empty, got %s/%s\n", gettype($info), $info); + +$def_info = mysql_get_host_info(); +if ($def_info !== $info) { + printf("[004] Host info for the default link and the specified link differ, [%d] %s\n", + mysql_errno(), mysql_error()); + + var_dump($def_info); + var_dump($info); +} + +if (ini_get('unicode.semantics') && !is_unicode($info)) { + printf("[005] Expecting Unicode error message!\n"); + var_inspect($info); +} + +if (!is_null($tmp = @mysql_get_host_info($link, "too many arguments"))) { + printf("[006] Expecting NULL/NULL got %s/%s\n", $tmp, gettype($tmp)); +} + +print "done!"; +?> +--EXPECTF-- +done!
\ No newline at end of file diff --git a/ext/mysql/tests/mysql_get_proto_info.phpt b/ext/mysql/tests/mysql_get_proto_info.phpt new file mode 100644 index 0000000000..989141a47f --- /dev/null +++ b/ext/mysql/tests/mysql_get_proto_info.phpt @@ -0,0 +1,30 @@ +--TEST-- +mysql_get_proto_info() +--SKIPIF-- +<?php +require_once('skipif.inc'); +require_once('skipifconnectfailure.inc'); +?> +--FILE-- +<?php +include_once "connect.inc"; + +if (false !== ($tmp = @mysql_get_proto_info(NULL))) + printf("[002] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); + +require "table.inc"; +if (!is_int($info = mysql_get_proto_info($link)) || (0 === $info)) + printf("[003] Expecting int/any_non_empty, got %s/%s\n", gettype($info), $info); + +if (!is_int($info2 = mysql_get_proto_info()) || (0 === $info2)) + printf("[004] Expecting int/any_non_empty, got %s/%s\n", gettype($info2), $info2); + +assert($info === $info2); + +if (NULL !== ($tmp = @mysql_get_proto_info('too many', 'arguments'))) + printf("[005] Expecting NULL got %s/%s\n", gettype($tmp), $tmp); + +print "done!"; +?> +--EXPECTF-- +done! diff --git a/ext/mysql/tests/mysql_get_server_info.phpt b/ext/mysql/tests/mysql_get_server_info.phpt new file mode 100644 index 0000000000..b759f47f69 --- /dev/null +++ b/ext/mysql/tests/mysql_get_server_info.phpt @@ -0,0 +1,39 @@ +--TEST-- +mysql_get_server_info() +--SKIPIF-- +<?php +require_once('skipif.inc'); +require_once('skipifconnectfailure.inc'); +?> +--FILE-- +<?php +include "connect.inc"; + +if (false !== ($tmp = @mysql_get_server_info(NULL))) + printf("[002] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); + +require "table.inc"; +if (!is_string($info = mysql_get_server_info($link)) || ('' === $info)) + printf("[003] Expecting string/any_non_empty, got %s/%s\n", gettype($info), $info); + +$def_info = mysql_get_server_info(); +if ($def_info !== $info) { + printf("[004] Server info for the default link and the specified link differ, [%d] %s\n", + mysql_errno(), mysql_error()); + + var_dump($def_info); + var_dump($info); +} + +if (ini_get('unicode.semantics') && !is_unicode($info)) { + printf("[005] Expecting Unicode error message!\n"); + var_inspect($info); +} + +if (NULL !== ($tmp = @mysql_get_server_info('too many', 'just too many'))) + printf("[006] Expecting NULL got %s/%s\n", gettype($tmp), $tmp); + +print "done!"; +?> +--EXPECTF-- +done! diff --git a/ext/mysql/tests/mysql_info.phpt b/ext/mysql/tests/mysql_info.phpt new file mode 100644 index 0000000000..6cb058f181 --- /dev/null +++ b/ext/mysql/tests/mysql_info.phpt @@ -0,0 +1,69 @@ +--TEST-- +mysql_info() +--SKIPIF-- +<?php +require_once('skipif.inc'); +require_once('skipifconnectfailure.inc'); +?> +--FILE-- +<?php +include "connect.inc"; + +if (false !== ($tmp = @mysql_info())) + printf("[001] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); + +if (NULL !== ($tmp = @mysql_info(NULL))) + printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + +require "table.inc"; +if (!$res = mysql_query('INSERT INTO test(id, label) VALUES (100, "a")', $link)) + printf("[003] [%d] %s\n", mysql_errno($link), mysql_error($link)); + +if (false !== ($tmp = mysql_info($link))) + printf("[004] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); + +if (!$res = mysql_query('INSERT INTO test(id, label) VALUES (101, "a"), (102, "b")', $link)) + printf("[005] [%d] %s\n", mysql_errno($link), mysql_error($link)); + +if (!is_string($tmp = mysql_info($link)) || ('' == $tmp)) + printf("[006] Expecting string/any_non_empty, got %s/%s\n", gettype($tmp), $tmp); + +if (!$res = mysql_query('INSERT INTO test(id, label) SELECT id + 200, label FROM test', $link)) + printf("[007] [%d] %s\n", mysql_errno($link), mysql_error($link)); + +if (!is_string($tmp = mysql_info($link)) || ('' == $tmp)) + printf("[008] Expecting string/any_non_empty, got %s/%s\n", gettype($tmp), $tmp); + +if (!$res = mysql_query('ALTER TABLE test MODIFY label CHAR(2)', $link)) + printf("[009] [%d] %s\n", mysql_errno($link), mysql_error($link)); + +if (!is_string($tmp = mysql_info($link)) || ('' == $tmp)) + printf("[010] Expecting string/any_non_empty, got %s/%s\n", gettype($tmp), $tmp); + +if (!$res = mysql_query('UPDATE test SET label = "b" WHERE id >= 100', $link)) + printf("[011] [%d] %s\n", mysql_errno($link), mysql_error($link)); + +if (!is_string($tmp = mysql_info($link)) || ('' == $tmp)) + printf("[012] Expecting string/any_non_empty, got %s/%s\n", gettype($tmp), $tmp); + +if (ini_get('unicode.semantics') && !is_unicode($tmp)) { + printf("[013] Expecting Unicode!\n"); + var_inspect($info); +} + +if (!is_string($def_tmp = mysql_info()) || ('' == $def_tmp)) + printf("[014] Expecting string/any_non_empty, got %s/%s\n", gettype($def_tmp), $def_tmp); + +if ($def_tmp !== $tmp) { + printf("[015] Results differ for default link and specified link, [%d] %s\n", + mysql_errno(), mysql_error()); + var_inspect($tmp); + var_inspect($def_tmp); +} + +// NOTE: no LOAD DATA INFILE test + +print "done!"; +?> +--EXPECTF-- +done!
\ No newline at end of file diff --git a/ext/mysql/tests/mysql_insert_id.phpt b/ext/mysql/tests/mysql_insert_id.phpt new file mode 100644 index 0000000000..29ac78f243 --- /dev/null +++ b/ext/mysql/tests/mysql_insert_id.phpt @@ -0,0 +1,66 @@ +--TEST-- +mysql_insert_id() +--SKIPIF-- +<?php +require_once('skipif.inc'); +require_once('skipifconnectfailure.inc'); +?> +--FILE-- +<?php +include "connect.inc"; + +$tmp = NULL; +$link = NULL; + +if (false !== ($tmp = @mysql_insert_id())) + printf("[001] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); + +if (false !== ($tmp = @mysql_insert_id($link))) + printf("[002] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); + +if (!is_null($tmp = @mysql_insert_id($link, 'too many args'))) + printf("[002a] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + +require('table.inc'); + +if (0 !== ($tmp = mysql_insert_id($link))) + printf("[003] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp); + +if (!$res = mysql_query("SELECT id, label FROM test ORDER BY id LIMIT 1", $link)) { + printf("[004] [%d] %s\n", mysql_errno($link), mysql_error($link)); +} +if (0 !== ($tmp = mysql_insert_id($link))) + printf("[005] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp); +mysql_free_result($res); + +// no auto_increment column +if (!$res = mysql_query("INSERT INTO test(id, label) VALUES (100, 'a')", $link)) { + printf("[006] [%d] %s\n", mysql_errno($link), mysql_error($link)); +} +if (0 !== ($tmp = mysql_insert_id($link))) + printf("[007] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp); + +if (!$res = mysql_query("ALTER TABLE test MODIFY id INT NOT NULL AUTO_INCREMENT", $link)) { + printf("[008] [%d] %s\n", mysql_errno($link), mysql_error($link)); +} +if (!$res = mysql_query("INSERT INTO test(label) VALUES ('a')", $link)) { + printf("[009] [%d] %s\n", mysql_errno($link), mysql_error($link)); +} +if (0 === ($tmp = mysql_insert_id($link))) + printf("[010] Expecting int/not zero, got %s/%s\n", gettype($tmp), $tmp); + +if ($tmp !== ($tmp2 = mysql_insert_id())) + printf("[011] Expecting %s/%s, got %s/%s\n", + gettype($tmp), $tmp, + gettype($tmp2), $tmp2); + +mysql_close($link); + +var_dump(mysql_insert_id($link)); + +print "done!"; +?> +--EXPECTF-- +Warning: mysql_insert_id(): %d is not a valid MySQL-Link resource in %s on line %d +bool(false) +done!
\ No newline at end of file |