1--TEST--
2openssl_x509_export() tests
3--SKIPIF--
4<?php if (!extension_loaded("openssl")) print "skip"; ?>
5--FILE--
6<?php
7$cert_file = dirname(__FILE__) . "/cert.crt";
8
9$a = file_get_contents($cert_file);
10$b = "file://" . $cert_file;
11$c = "invalid cert";
12$d = openssl_x509_read($a);
13$e = array();
14
15var_dump(openssl_x509_export($a, $output));  // read cert as a binary string
16var_dump(openssl_x509_export($b, $output2)); // read cert from a filename string
17var_dump(openssl_x509_export($c, $output3)); // read an invalid cert, fails
18var_dump(openssl_x509_export($d, $output4)); // read cert from a resource
19var_dump(openssl_x509_export($e, $output5)); // read an array, fails
20
21if (PHP_EOL !== "\n") {
22	$a = str_replace(PHP_EOL, "\n", $a);
23}
24
25var_dump(strcmp($output, $a));
26var_dump(strcmp($output, $output2));
27var_dump(strcmp($output, $output3));
28var_dump(strcmp($output, $output4)); // different
29var_dump(strcmp($output, $output5)); // different
30?>
31--EXPECTF--
32bool(true)
33bool(true)
34
35Warning: openssl_x509_export(): cannot get cert from parameter 1 in %s on line %d
36bool(false)
37bool(true)
38
39Warning: openssl_x509_export(): cannot get cert from parameter 1 in %s on line %d
40bool(false)
41int(0)
42int(0)
43int(%d)
44int(0)
45int(%d)
46