]> granicus.if.org Git - php/commitdiff
Fixed bug #65047 (Test skip on client / server version)
authorMatteo Beccati <mbeccati@php.net>
Wed, 19 Jun 2013 09:46:11 +0000 (11:46 +0200)
committerMatteo Beccati <mbeccati@php.net>
Wed, 19 Jun 2013 09:48:03 +0000 (11:48 +0200)
16 files changed:
ext/pdo_pgsql/tests/bug46274.phpt
ext/pdo_pgsql/tests/bug46274_2.phpt
ext/pgsql/tests/08escape.phpt
ext/pgsql/tests/10pg_convert.phpt
ext/pgsql/tests/10pg_convert_9.phpt [moved from ext/pgsql/tests/10pg_convert_85.phpt with 87% similarity]
ext/pgsql/tests/12pg_insert.phpt
ext/pgsql/tests/12pg_insert_9.phpt [moved from ext/pgsql/tests/12pg_insert_85.phpt with 88% similarity]
ext/pgsql/tests/13pg_select_9.phpt [moved from ext/pgsql/tests/13pg_select_85.phpt with 85% similarity]
ext/pgsql/tests/14pg_update.phpt
ext/pgsql/tests/14pg_update_9.phpt [moved from ext/pgsql/tests/14pg_update_85.phpt with 89% similarity]
ext/pgsql/tests/18pg_escape_bytea_before.phpt [new file with mode: 0644]
ext/pgsql/tests/18pg_escape_bytea_esc.phpt [moved from ext/pgsql/tests/18pg_escape_bytea.phpt with 84% similarity]
ext/pgsql/tests/18pg_escape_bytea_hex.phpt [new file with mode: 0644]
ext/pgsql/tests/bug37100.phpt
ext/pgsql/tests/bug37100_9.phpt [moved from ext/pgsql/tests/bug37100_85.phpt with 89% similarity]
ext/pgsql/tests/skipif.inc

index c34839ad430b8f3535383a861898f0b96687a4ba..8a85c9fe0c14ae83afc5bedf6c51b404e37311ed 100644 (file)
@@ -14,6 +14,11 @@ $db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
 
 $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
 
+try {
+       $db->query("SET bytea_output = 'escape'");
+} catch (Exception $e) {
+}
+
 $db->query('CREATE TABLE test_one_blob (id SERIAL NOT NULL, blob1 BYTEA)');
 
 $stmt = $db->prepare("INSERT INTO test_one_blob (blob1) VALUES (:foo)");
index eb675afe9e5f26540e05ac390d6c44b46049001a..317160c37a8d4c2d28bca702a509d72d84c54f41 100644 (file)
@@ -14,6 +14,11 @@ $db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
 
 $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
 
+try {
+        $db->query("SET bytea_output = 'escape'");
+} catch (Exception $e) {
+}
+
 $db->query('CREATE TABLE test_one_blob (id SERIAL NOT NULL, blob1 BYTEA)');
 
 $stmt = $db->prepare("INSERT INTO test_one_blob (blob1) VALUES (:foo)");
index 90b4ed8a9f5ead239974d27f73f5a5c5f9bbde42..1bea35bf14d2a55a555a031a4ca4b0b6845f38f8 100644 (file)
@@ -48,15 +48,24 @@ $sql = "INSERT INTO ".$table_name." (num, bin) VALUES (-9999, CAST ('".$escaped_
 pg_query($db, $sql);
 
 // Retrieve binary from DB
-$sql = "SELECT bin::bytea FROM ".$table_name." WHERE num = -9999";
-$result = pg_query($db, $sql);
-$row = pg_fetch_array($result, 0, PGSQL_ASSOC);
+for ($i = 0; $i < 2; $i++) {
+       $sql = "SELECT bin::bytea FROM ".$table_name." WHERE num = -9999";
+       $result = pg_query($db, $sql);
+       $row = pg_fetch_array($result, 0, PGSQL_ASSOC);
 
-if ($data === pg_unescape_bytea($row['bin'])) {
-       echo "pg_escape_bytea() actually works with database\n";
-}
-else {
-       echo "pg_escape_bytea() is broken\n";
+       if ($data === pg_unescape_bytea($row['bin'])) {
+               echo "pg_escape_bytea() actually works with database\n";
+               break;
+       }
+       elseif (!$i) {
+               // Force bytea escaping and retry
+               @pg_query($db, "SET bytea_output = 'escape'");
+       }
+       else {
+               $result = pg_query($db, $sql);
+               echo "pg_escape_bytea() is broken\n";
+               break;
+       }
 }
 
 // pg_escape_literal/pg_escape_identifier
@@ -92,4 +101,4 @@ pg_escape_string() is Ok
 pg_escape_bytea() is Ok
 pg_escape_bytea() actually works with database
 pg_escape_literal() is Ok
-pg_escape_identifier() is Ok
\ No newline at end of file
+pg_escape_identifier() is Ok
index 73bf2b64e8b90e362e2bd8f8b153e80827473928..fde4c67d3744c2d5bd717de2268be9cc5dcffefe 100644 (file)
@@ -3,7 +3,7 @@ PostgreSQL pg_convert()
 --SKIPIF--
 <?php
 include("skipif.inc");
-skip_server_version('8.5dev', '>=');
+skip_bytea_not_escape();
 ?>
 --FILE--
 <?php
similarity index 87%
rename from ext/pgsql/tests/10pg_convert_85.phpt
rename to ext/pgsql/tests/10pg_convert_9.phpt
index 8b1cc8f53883ff137501aed2aad9a7bfc202931d..bb2e7e6d2a317c182e2d3b4d8ba18a3bb66aeb32 100644 (file)
@@ -1,9 +1,9 @@
 --TEST--
-PostgreSQL pg_convert() (8.5+)
+PostgreSQL pg_convert() (9.0+)
 --SKIPIF--
 <?php
 include("skipif.inc");
-skip_server_version('8.5dev', '<');
+skip_bytea_not_hex();
 ?>
 --FILE--
 <?php
index f5cd868f81ca5b3de51bada4f866624ad548f00b..66304944b0870d26cd0f93c4b209b80e57298abd 100644 (file)
@@ -3,7 +3,7 @@ PostgreSQL pg_insert()
 --SKIPIF--
 <?php
 include("skipif.inc");
-skip_server_version('8.5dev', '>=');
+skip_bytea_not_escape();
 ?>
 --FILE--
 <?php
similarity index 88%
rename from ext/pgsql/tests/12pg_insert_85.phpt
rename to ext/pgsql/tests/12pg_insert_9.phpt
index 5fbbe4b7afc4bee430016e362a844085e5d1a8a0..8afae0df91d7ffc26a8f7961164f80164254aa4f 100644 (file)
@@ -1,9 +1,9 @@
 --TEST--
-PostgreSQL pg_insert() (8.5+)
+PostgreSQL pg_insert() (9.0+)
 --SKIPIF--
 <?php
 include("skipif.inc");
-skip_server_version('8.5dev', '<');
+skip_bytea_not_hex();
 ?>
 --FILE--
 <?php
similarity index 85%
rename from ext/pgsql/tests/13pg_select_85.phpt
rename to ext/pgsql/tests/13pg_select_9.phpt
index e6d86bd6f80913a50c1e43f26f15a61bc256503d..422c461b6096df03e4279c7886ccc4d96ccee985 100644 (file)
@@ -1,9 +1,9 @@
 --TEST--
-PostgreSQL pg_select() (8.5+)
+PostgreSQL pg_select() (9.0+)
 --SKIPIF--
 <?php
 include("skipif.inc");
-skip_server_version('8.5dev', '<');
+skip_server_version('9.0', '<');
 ?>
 --FILE--
 <?php
@@ -12,6 +12,8 @@ error_reporting(E_ALL);
 include 'config.inc';
 
 $db = pg_connect($conn_str);
+pg_query("SET bytea_output = 'hex'");
+
 $fields = array('num'=>'1234', 'str'=>'ABC', 'bin'=>'XYZ');
 $ids = array('num'=>'1234');
 
index b41dd1af84c368428609ffb286b2b785c60b7b67..3260f2b73e1e372b78eb758e02e351a8fdb4f863 100644 (file)
@@ -3,7 +3,7 @@ PostgreSQL pg_update()
 --SKIPIF--
 <?php
 include("skipif.inc");
-skip_server_version('8.5dev', '>=');
+skip_bytea_not_escape();
 ?>
 --FILE--
 <?php
similarity index 89%
rename from ext/pgsql/tests/14pg_update_85.phpt
rename to ext/pgsql/tests/14pg_update_9.phpt
index 06ca8c3de98b9b948f1fe22b0ee937354b975a7c..bc5cf673e327e89a10e00113486f4377c5f772df 100644 (file)
@@ -1,9 +1,9 @@
 --TEST--
-PostgreSQL pg_update() (8.5+)
+PostgreSQL pg_update() (9.0)
 --SKIPIF--
 <?php
 include("skipif.inc");
-skip_server_version('8.5dev', '<');
+skip_bytea_not_hex();
 ?>
 --FILE--
 <?php
diff --git a/ext/pgsql/tests/18pg_escape_bytea_before.phpt b/ext/pgsql/tests/18pg_escape_bytea_before.phpt
new file mode 100644 (file)
index 0000000..4925177
--- /dev/null
@@ -0,0 +1,30 @@
+--TEST--
+PostgreSQL pg_escape_bytea() functions (before connection)
+--SKIPIF--
+<?php include("skipif.inc"); ?>
+--FILE--
+<?php
+// optional functions
+
+include('config.inc');
+
+$image = file_get_contents(dirname(__FILE__) . '/php.gif');
+$esc_image = pg_escape_bytea($image);
+
+$db = pg_connect($conn_str);
+@pg_query($db, "SET bytea_output = 'escape'");
+
+pg_query($db, 'INSERT INTO '.$table_name.' (num, bin) VALUES (9876, E\''.$esc_image.'\');');
+$result = pg_query($db, 'SELECT * FROM '.$table_name.' WHERE num = 9876');
+$rows = pg_fetch_all($result);
+$unesc_image = pg_unescape_bytea($rows[0]['bin']);
+
+if ($unesc_image !== $image) {
+       echo "NG";
+}
+else {
+       echo "OK";
+}
+?>
+--EXPECT--
+OK
similarity index 84%
rename from ext/pgsql/tests/18pg_escape_bytea.phpt
rename to ext/pgsql/tests/18pg_escape_bytea_esc.phpt
index 5f52a17d9734a8df6942991f478c510bb1fcf91a..38e5777c3e0ac24bee119f7754235b8f98708d9f 100644 (file)
@@ -1,5 +1,5 @@
 --TEST--
-PostgreSQL pg_escape_bytea() functions
+PostgreSQL pg_escape_bytea() functions (escape format)
 --SKIPIF--
 <?php include("skipif.inc"); ?>
 --FILE--
@@ -9,6 +9,7 @@ PostgreSQL pg_escape_bytea() functions
 include('config.inc');
 
 $db = pg_connect($conn_str);
+@pg_query($db, "SET bytea_output = 'escape'");
 
 $image = file_get_contents(dirname(__FILE__) . '/php.gif');
 $esc_image = pg_escape_bytea($image);
diff --git a/ext/pgsql/tests/18pg_escape_bytea_hex.phpt b/ext/pgsql/tests/18pg_escape_bytea_hex.phpt
new file mode 100644 (file)
index 0000000..04630bb
--- /dev/null
@@ -0,0 +1,33 @@
+--TEST--
+PostgreSQL pg_escape_bytea() functions (hex format)
+--SKIPIF--
+<?php
+include("skipif.inc");
+skip_bytea_not_hex();
+?>
+--FILE--
+<?php
+// optional functions
+
+include('config.inc');
+
+$db = pg_connect($conn_str);
+@pg_query($db, "SET bytea_output = 'hex'");
+
+$image = file_get_contents(dirname(__FILE__) . '/php.gif');
+$esc_image = pg_escape_bytea($image);
+
+pg_query($db, 'INSERT INTO '.$table_name.' (num, bin) VALUES (9876, \''.$esc_image.'\');');
+$result = pg_query($db, 'SELECT * FROM '.$table_name.' WHERE num = 9876');
+$rows = pg_fetch_all($result);
+$unesc_image = pg_unescape_bytea($rows[0]['bin']);
+
+if ($unesc_image !== $image) {
+       echo "NG";
+}
+else {
+       echo "OK";
+}
+?>
+--EXPECT--
+OK
index fa6b9ba9e0ef92fb8e86bacac3299b972e87b15d..3faecc671c44bd72737138a65c071f322403e7ac 100644 (file)
@@ -3,7 +3,7 @@ Bug #37100 (data is returned truncated with BINARY CURSOR)
 --SKIPIF--
 <?php
 include("skipif.inc");
-skip_server_version('8.5dev', '>=');
+skip_bytea_not_escape();
 ?>
 --FILE--
 <?php
@@ -11,6 +11,7 @@ skip_server_version('8.5dev', '>=');
 include 'config.inc';
 
 $db = pg_connect($conn_str);
+@pg_query("SET bytea_output = 'escape'");
 
 @pg_query('DROP TABLE test_bug');
 
similarity index 89%
rename from ext/pgsql/tests/bug37100_85.phpt
rename to ext/pgsql/tests/bug37100_9.phpt
index aa2477626a0fa8898689f7a53065da61eb4a5401..9f4160d129dc087186c0939234dbf77a3559160b 100644 (file)
@@ -1,9 +1,9 @@
 --TEST--
-Bug #37100 (data is returned truncated with BINARY CURSOR) (8.5+)
+Bug #37100 (data is returned truncated with BINARY CURSOR) (9.0+)
 --SKIPIF--
 <?php
 include("skipif.inc");
-skip_server_version('8.5dev', '<');
+skip_bytea_not_hex();
 ?>
 --FILE--
 <?php
index 59bd5a3ea284e595662dc627d8498d734e96a896..83904af4f332d71514aaee39e28ba471e092590d 100644 (file)
@@ -23,6 +23,23 @@ function skip_server_version($version, $op = '<')
        if (version_compare($pg, $version, $op)) {
                die("skip Server version {$pg} is {$op} {$version}\n");
        }
+       return $pg;
+}
+
+function skip_bytea_not_hex()
+{
+       $out = pg_escape_bytea("\xFF");
+       if (strpos($out, '377') !== false) {
+               die("skip libpq or backend < 9.0\n");
+       }
+}
+
+function skip_bytea_not_escape()
+{
+       $out = pg_escape_bytea("\xFF");
+       if (strpos($out, '377') === false) {
+               die("skip libpq or backend >= 9.0\n");
+       }
 }
 
 ?>