diff options
| author | Sean Finney <seanius@debian.org> | 2009-04-10 14:09:48 +0200 |
|---|---|---|
| committer | Sean Finney <seanius@debian.org> | 2009-04-10 14:09:48 +0200 |
| commit | cd0b49c72aee33b3e44a9c589fcd93b9e1c7a64f (patch) | |
| tree | 1315c623bb7d9dfa8d366fa9cd2c6834ceeb5da5 /tests | |
| parent | 9ea47aab740772adf0c69d8c94b208a464e599ea (diff) | |
| download | php-cd0b49c72aee33b3e44a9c589fcd93b9e1c7a64f.tar.gz | |
Imported Upstream version 5.2.9.dfsg.1upstream/5.2.9.dfsg.1
Diffstat (limited to 'tests')
145 files changed, 6998 insertions, 79 deletions
diff --git a/tests/basic/021.phpt b/tests/basic/021.phpt index d8f7c1c0e..3010a1b62 100644 --- a/tests/basic/021.phpt +++ b/tests/basic/021.phpt @@ -1,5 +1,7 @@ --TEST-- Bug #37276 (problems witch $_POST array) +--INI-- +file_upload=1 --SKIPIF-- <?php if (php_sapi_name()=='cli') die('skip'); ?> --POST_RAW-- diff --git a/tests/basic/bug20539.phpt b/tests/basic/bug20539.phpt index 372285bfa..813e129c4 100644 --- a/tests/basic/bug20539.phpt +++ b/tests/basic/bug20539.phpt @@ -1,11 +1,15 @@ --TEST-- Bug #20539 (PHP CLI Segmentation Fault) +--SKIPIF-- +<?php if (!extension_loaded("session")) die("skip session extension not available"); ?> --INI-- session.auto_start=1 session.save_handler=files +session.save_path=./tests/basic/ --FILE-- <?php print "good :)\n"; + unlink(dirname(__FILE__) . '/sess_' . session_id()); ?> --EXPECT-- good :) diff --git a/tests/basic/bug46313-win.phpt b/tests/basic/bug46313-win.phpt new file mode 100644 index 000000000..276efe196 --- /dev/null +++ b/tests/basic/bug46313-win.phpt @@ -0,0 +1,62 @@ +--TEST-- +Bug #46313 (Magic quotes broke $_FILES) +--SKIPIF-- +<?php if(substr(PHP_OS, 0, 3) != "WIN") die("skip Windows-only test"); ?> +--INI-- +magic_quotes_gpc=1 +file_uploads=1 +register_globals=1 +--POST_RAW-- +Content-Type: multipart/form-data; boundary=---------------------------20896060251896012921717172737 +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="o1'file"; filename="o1'file.png" +Content-Type: text/plain-file1 + +1 +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="o2'file"; filename="o2'file2.txt" +Content-Type: text/plain-file2 + +2 +-----------------------------20896060251896012921717172737-- +--FILE-- +<?php +var_dump($_FILES); +var_dump($GLOBALS["o1\'file_name"]); +var_dump($GLOBALS["o1\'file_name"] === $_FILES["o1\'file"]["name"]); +var_dump($GLOBALS["o1\'file"]); +var_dump($GLOBALS["o1\'file"] === $_FILES["o1\'file"]["tmp_name"]); +?> +--EXPECTF-- +array(2) { + ["o1\'file"]=> + array(5) { + ["name"]=> + string(12) "o1" + ["type"]=> + string(16) "text/plain-file1" + ["tmp_name"]=> + string(14) "%s" + ["error"]=> + int(0) + ["size"]=> + int(1) + } + ["o2\'file"]=> + array(5) { + ["name"]=> + string(13) "o2" + ["type"]=> + string(16) "text/plain-file2" + ["tmp_name"]=> + string(14) "%s" + ["error"]=> + int(0) + ["size"]=> + int(1) + } +} +string(12) "o1" +bool(true) +string(%d) "%s" +bool(true) diff --git a/tests/basic/bug46313.phpt b/tests/basic/bug46313.phpt new file mode 100644 index 000000000..275b26796 --- /dev/null +++ b/tests/basic/bug46313.phpt @@ -0,0 +1,62 @@ +--TEST-- +Bug #46313 (Magic quotes broke $_FILES) +--SKIPIF-- +<?php if(substr(PHP_OS, 0, 3) == "WIN") die("skip non-Windows test"); ?> +--INI-- +magic_quotes_gpc=1 +file_uploads=1 +register_globals=1 +--POST_RAW-- +Content-Type: multipart/form-data; boundary=---------------------------20896060251896012921717172737 +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="o1'file"; filename="o1'file.png" +Content-Type: text/plain-file1 + +1 +-----------------------------20896060251896012921717172737 +Content-Disposition: form-data; name="o2'file"; filename="o2'file2.txt" +Content-Type: text/plain-file2 + +2 +-----------------------------20896060251896012921717172737-- +--FILE-- +<?php +var_dump($_FILES); +var_dump($GLOBALS["o1\'file_name"]); +var_dump($GLOBALS["o1\'file_name"] === $_FILES["o1\'file"]["name"]); +var_dump($GLOBALS["o1\'file"]); +var_dump($GLOBALS["o1\'file"] === $_FILES["o1\'file"]["tmp_name"]); +?> +--EXPECTF-- +array(2) { + ["o1\'file"]=> + array(5) { + ["name"]=> + string(12) "o1\'file.png" + ["type"]=> + string(16) "text/plain-file1" + ["tmp_name"]=> + string(%d) "%s" + ["error"]=> + int(0) + ["size"]=> + int(1) + } + ["o2\'file"]=> + array(5) { + ["name"]=> + string(13) "o2\'file2.txt" + ["type"]=> + string(16) "text/plain-file2" + ["tmp_name"]=> + string(%d) "%s" + ["error"]=> + int(0) + ["size"]=> + int(1) + } +} +string(12) "o1\'file.png" +bool(true) +string(%d) "%s" +bool(true) diff --git a/tests/basic/bug46759.phpt b/tests/basic/bug46759.phpt new file mode 100644 index 000000000..fdbd59554 --- /dev/null +++ b/tests/basic/bug46759.phpt @@ -0,0 +1,21 @@ +--TEST-- +Testing magic_quotes_gpc +--SKIPIF-- +<?php if (php_sapi_name()=='cli') echo 'skip'; ?> +--INI-- +magic_quotes_gpc=1 +--GET-- +a='&b="&c=\" +--FILE-- +<?php + +foreach ($_GET AS $key => $value) +{ + echo $key . ": " . $value . "\n"; +} + +?> +--EXPECT-- +a: \' +b: \" +c: \\\" diff --git a/tests/classes/__call_006.phpt b/tests/classes/__call_006.phpt new file mode 100644 index 000000000..a65fafb82 --- /dev/null +++ b/tests/classes/__call_006.phpt @@ -0,0 +1,77 @@ +--TEST-- +Ensure exceptions are handled properly when thrown in __call. +--FILE-- +<?php +class A { + function __call($strMethod, $arrArgs) { + var_dump($this); + throw new Exception; + echo "You should not see this"; + } + function test() { + A::unknownCalledWithSRO(1,2,3); + } +} + +class B extends A { + function test() { + B::unknownCalledWithSROFromChild(1,2,3); + } +} + +$a = new A(); + +echo "---> Invoke __call via simple method call.\n"; +try { + $a->unknown(); +} catch (Exception $e) { + echo "Exception caught OK; continuing.\n"; +} + +echo "\n\n---> Invoke __call via scope resolution operator within instance.\n"; +try { + $a->test(); +} catch (Exception $e) { + echo "Exception caught OK; continuing.\n"; +} + +echo "\n\n---> Invoke __call via scope resolution operator within child instance.\n"; +$b = new B(); +try { + $b->test(); +} catch (Exception $e) { + echo "Exception caught OK; continuing.\n"; +} + +echo "\n\n---> Invoke __call via callback.\n"; +try { + call_user_func(array($b, 'unknownCallback'), 1,2,3); +} catch (Exception $e) { + echo "Exception caught OK; continuing.\n"; +} +?> +==DONE== +--EXPECTF-- +---> Invoke __call via simple method call. +object(A)#%d (0) { +} +Exception caught OK; continuing. + + +---> Invoke __call via scope resolution operator within instance. +object(A)#%d (0) { +} +Exception caught OK; continuing. + + +---> Invoke __call via scope resolution operator within child instance. +object(B)#%d (0) { +} +Exception caught OK; continuing. + + +---> Invoke __call via callback. +object(B)#%d (0) { +} +Exception caught OK; continuing. +==DONE==
\ No newline at end of file diff --git a/tests/classes/__call_007.phpt b/tests/classes/__call_007.phpt new file mode 100644 index 000000000..12e4df1c0 --- /dev/null +++ b/tests/classes/__call_007.phpt @@ -0,0 +1,73 @@ +--TEST-- +Ensure exceptions are handled properly when thrown in a statically declared __call. +--FILE-- +<?php +class A { + static function __call($strMethod, $arrArgs) { + @var_dump($this); + throw new Exception; + echo "You should not see this"; + } + function test() { + A::unknownCalledWithSRO(1,2,3); + } +} + +class B extends A { + function test() { + B::unknownCalledWithSROFromChild(1,2,3); + } +} + +$a = new A(); + +echo "---> Invoke __call via simple method call.\n"; +try { + $a->unknown(); +} catch (Exception $e) { + echo "Exception caught OK; continuing.\n"; +} + +echo "\n\n---> Invoke __call via scope resolution operator within instance.\n"; +try { + $a->test(); +} catch (Exception $e) { + echo "Exception caught OK; continuing.\n"; +} + +echo "\n\n---> Invoke __call via scope resolution operator within child instance.\n"; +$b = new B(); +try { + $b->test(); +} catch (Exception $e) { + echo "Exception caught OK; continuing.\n"; +} + +echo "\n\n---> Invoke __call via callback.\n"; +try { + call_user_func(array($b, 'unknownCallback'), 1,2,3); +} catch (Exception $e) { + echo "Exception caught OK; continuing.\n"; +} +?> +==DONE== +--EXPECTF-- +---> Invoke __call via simple method call. +NULL +Exception caught OK; continuing. + + +---> Invoke __call via scope resolution operator within instance. +NULL +Exception caught OK; continuing. + + +---> Invoke __call via scope resolution operator within child instance. +NULL +Exception caught OK; continuing. + + +---> Invoke __call via callback. +NULL +Exception caught OK; continuing. +==DONE==
\ No newline at end of file diff --git a/tests/classes/implicit_instantiation_001.phpt b/tests/classes/implicit_instantiation_001.phpt new file mode 100644 index 000000000..460cdc97f --- /dev/null +++ b/tests/classes/implicit_instantiation_001.phpt @@ -0,0 +1,146 @@ +--TEST-- +Implicit object instantiation when accessing properties of non-object. +--FILE-- +<?php +class C { + // These values get implicitly converted to objects + public $boolFalse = false; + public $emptyString = ''; + public $null = null; + + // These values do not get implicitly converted to objects + public $boolTrue = true; + public $nonEmptyString = 'hello'; + public $intZero = 0; +} + +$c = new C; +foreach($c as $name => $value) { + echo "\n\n---( \$c->$name )---"; + echo "\n --> Attempting implicit conversion to object using increment...\n"; + $c->$name->prop++; + $c->$name = $value; // reset value in case implicit conversion was successful + + echo "\n --> Attempting implicit conversion to object using assignment...\n"; + $c->$name->prop = "Implicit instantiation!"; + $c->$name = $value; // reset value in case implicit conversion was successful + + echo "\n --> Attempting implicit conversion to object using combined assignment...\n"; + $c->$name->prop .= " Implicit instantiation!"; +} + +echo "\n\n\n --> Resulting object:"; +var_dump($c); + +?> +--EXPECTF-- + + +---( $c->boolFalse )--- + --> Attempting implicit conversion to object using increment... + +Strict Standards: Creating default object from empty value in %s on line 18 + + --> Attempting implicit conversion to object using assignment... + +Strict Standards: Creating default object from empty value in %s on line 22 + + --> Attempting implicit conversion to object using combined assignment... + +Strict Standards: Creating default object from empty value in %s on line 26 + + +---( $c->emptyString )--- + --> Attempting implicit conversion to object using increment... + +Strict Standards: Creating default object from empty value in %s on line 18 + + --> Attempting implicit conversion to object using assignment... + +Strict Standards: Creating default object from empty value in %s on line 22 + + --> Attempting implicit conversion to object using combined assignment... + +Strict Standards: Creating default object from empty value in %s on line 26 + + +---( $c->null )--- + --> Attempting implicit conversion to object using increment... + +Strict Standards: Creating default object from empty value in %s on line 18 + + --> Attempting implicit conversion to object using assignment... + +Strict Standards: Creating default object from empty value in %s on line 22 + + --> Attempting implicit conversion to object using combined assignment... + +Strict Standards: Creating default object from empty value in %s on line 26 + + +---( $c->boolTrue )--- + --> Attempting implicit conversion to object using increment... + +Warning: Attempt to %s property of non-object in %s on line 18 + + --> Attempting implicit conversion to object using assignment... + +Warning: Attempt to assign property of non-object in %s on line 22 + + --> Attempting implicit conversion to object using combined assignment... + +Warning: Attempt to assign property of non-object in %s on line 26 + + +---( $c->nonEmptyString )--- + --> Attempting implicit conversion to object using increment... + +Warning: Attempt to %s property of non-object in %s on line 18 + + --> Attempting implicit conversion to object using assignment... + +Warning: Attempt to assign property of non-object in %s on line 22 + + --> Attempting implicit conversion to object using combined assignment... + +Warning: Attempt to assign property of non-object in %s on line 26 + + +---( $c->intZero )--- + --> Attempting implicit conversion to object using increment... + +Warning: Attempt to %s property of non-object in %s on line 18 + + --> Attempting implicit conversion to object using assignment... + +Warning: Attempt to assign property of non-object in %s on line 22 + + --> Attempting implicit conversion to object using combined assignment... + +Warning: Attempt to assign property of non-object in %s on line 26 + + + + --> Resulting object:object(C)#%d (6) { + [%u|b%"boolFalse"]=> + object(stdClass)#%d (1) { + [%u|b%"prop"]=> + %unicode|string%(24) " Implicit instantiation!" + } + [%u|b%"emptyString"]=> + object(stdClass)#%d (1) { + [%u|b%"prop"]=> + %unicode|string%(24) " Implicit instantiation!" + } + [%u|b%"null"]=> + object(stdClass)#%d (1) { + [%u|b%"prop"]=> + %unicode|string%(24) " Implicit instantiation!" + } + [%u|b%"boolTrue"]=> + bool(true) + [%u|b%"nonEmptyString"]=> + %unicode|string%(5) "hello" + [%u|b%"intZero"]=> + int(0) +}
\ No newline at end of file diff --git a/tests/classes/inheritance_006.phpt b/tests/classes/inheritance_006.phpt new file mode 100644 index 000000000..7376ce1a8 --- /dev/null +++ b/tests/classes/inheritance_006.phpt @@ -0,0 +1,24 @@ +--TEST-- +Private property inheritance check +--FILE-- +<?php +Class A { + private $c; +} + +Class B extends A { + private $c; +} + +Class C extends B { +} + +var_dump(new C); +?> +--EXPECTF-- +object(C)#%d (2) { + ["c:private"]=> + NULL + ["c:private"]=> + NULL +}
\ No newline at end of file diff --git a/tests/classes/inheritance_007.phpt b/tests/classes/inheritance_007.phpt new file mode 100644 index 000000000..df6b96a55 --- /dev/null +++ b/tests/classes/inheritance_007.phpt @@ -0,0 +1,39 @@ +--TEST-- +Ensure inherited old-style constructor doesn't block other methods. +--FILE-- +<?php +class A { + public function B () { echo "In " . __METHOD__ . "\n"; } + public function A () { echo "In " . __METHOD__ . "\n"; } +} +class B extends A { } + +$rc = new ReflectionClass('B'); +var_dump($rc->getMethods()); + + +$b = new B(); +$b->a(); +$b->b(); + +?> +--EXPECTF-- +array(2) { + [0]=> + &object(ReflectionMethod)#%d (2) { + [%u|b%"name"]=> + %string|unicode%(1) "B" + [%u|b%"class"]=> + %string|unicode%(1) "B" + } + [1]=> + &object(ReflectionMethod)#%d (2) { + [%u|b%"name"]=> + %string|unicode%(1) "A" + [%u|b%"class"]=> + %string|unicode%(1) "B" + } +} +In A::A +In A::A +In A::B
\ No newline at end of file diff --git a/tests/classes/property_recreate_private.phpt b/tests/classes/property_recreate_private.phpt new file mode 100644 index 000000000..a43e78202 --- /dev/null +++ b/tests/classes/property_recreate_private.phpt @@ -0,0 +1,81 @@ +--TEST-- +Unsetting and recreating private properties. +--FILE-- +<?php +class C { + private $p = 'test'; + function unsetPrivate() { + unset($this->p); + } + function setPrivate() { + $this->p = 'changed'; + } +} + +class D extends C { + function setP() { + $this->p = 'changed in D'; + } +} + +echo "Unset and recreate a superclass's private property:\n"; +$d = new D; +$d->unsetPrivate(); +$d->setPrivate(); +var_dump($d); + +echo "\nUnset superclass's private property, and recreate it as public in subclass:\n"; +$d = new D; +$d->unsetPrivate(); +$d->setP(); +var_dump($d); + +echo "\nUnset superclass's private property, and recreate it as public at global scope:\n"; +$d = new D; +$d->unsetPrivate(); +$d->p = 'this will create a public property'; +var_dump($d); + + +echo "\n\nUnset and recreate a private property:\n"; +$c = new C; +$c->unsetPrivate(); +$c->setPrivate(); +var_dump($c); + +echo "\nUnset a private property, and attempt to recreate at global scope (expecting failure):\n"; +$c = new C; +$c->unsetPrivate(); +$c->p = 'this will fail'; +var_dump($c); +?> +==Done== +--EXPECTF-- +Unset and recreate a superclass's private property: +object(D)#%d (1) { + ["p:private"]=> + string(7) "changed" +} + +Unset superclass's private property, and recreate it as public in subclass: +object(D)#%d (1) { + ["p"]=> + string(12) "changed in D" +} + +Unset superclass's private property, and recreate it as public at global scope: +object(D)#%d (1) { + ["p"]=> + string(34) "this will create a public property" +} + + +Unset and recreate a private property: +object(C)#%d (1) { + ["p:private"]=> + string(7) "changed" +} + +Unset a private property, and attempt to recreate at global scope (expecting failure): + +Fatal error: Cannot access private property C::$p in %s on line 46
\ No newline at end of file diff --git a/tests/classes/property_recreate_protected.phpt b/tests/classes/property_recreate_protected.phpt new file mode 100644 index 000000000..dbb24ecd0 --- /dev/null +++ b/tests/classes/property_recreate_protected.phpt @@ -0,0 +1,53 @@ +--TEST-- +Unsetting and recreating protected properties. +--FILE-- +<?php +class C { + protected $p = 'test'; + function unsetProtected() { + unset($this->p); + } + function setProtected() { + $this->p = 'changed'; + } +} + +class D extends C { + function setP() { + $this->p = 'changed in D'; + } +} + +$d = new D; +echo "Unset and recreate a protected property from property's declaring class scope:\n"; +$d->unsetProtected(); +$d->setProtected(); +var_dump($d); + +echo "\nUnset and recreate a protected property from subclass:\n"; +$d = new D; +$d->unsetProtected(); +$d->setP(); +var_dump($d); + +echo "\nUnset a protected property, and attempt to recreate it outside of scope (expected failure):\n"; +$d->unsetProtected(); +$d->p = 'this will fail'; +var_dump($d); +?> +--EXPECTF-- +Unset and recreate a protected property from property's declaring class scope: +object(D)#%d (1) { + ["p:protected"]=> + string(7) "changed" +} + +Unset and recreate a protected property from subclass: +object(D)#%d (1) { + ["p:protected"]=> + string(12) "changed in D" +} + +Unset a protected property, and attempt to recreate it outside of scope (expected failure): + +Fatal error: Cannot access protected property %s::$p in %s on line 32
\ No newline at end of file diff --git a/tests/classes/serialize_001.phpt b/tests/classes/serialize_001.phpt index b7182aca6..142fc50fc 100755 --- a/tests/classes/serialize_001.phpt +++ b/tests/classes/serialize_001.phpt @@ -1,79 +1,79 @@ ---TEST--
-ZE2 Serializable
---FILE--
-<?php
-
-class Test implements Serializable
-{
- public $data;
-
- function __construct($data)
- {
- echo __METHOD__ . "($data)\n";
- $this->data = $data;
- }
-
- function serialize()
- {
- echo __METHOD__ . "({$this->data})\n";
- return $this->data;
- }
-
- function unserialize($serialized)
- {
- echo __METHOD__ . "($serialized)\n";
- $this->data = $serialized;
- var_dump($this);
- }
-}
-
-$tests = array('String', NULL, 42, false);
-
-foreach($tests as $data)
-{
- try
- {
- echo "==========\n";
- var_dump($data);
- $ser = serialize(new Test($data));
- var_dump(unserialize($ser));
- }
- catch(Exception $e)
- {
- echo 'Exception: ' . $e->getMessage() . "\n";
- }
-}
-
-?>
-===DONE===
-<?php exit(0); ?>
---EXPECT--
-==========
-string(6) "String"
-Test::__construct(String)
-Test::serialize(String)
-Test::unserialize(String)
-object(Test)#1 (1) {
- ["data"]=>
- string(6) "String"
-}
-object(Test)#1 (1) {
- ["data"]=>
- string(6) "String"
-}
-==========
-NULL
-Test::__construct()
-Test::serialize()
-NULL
-==========
-int(42)
-Test::__construct(42)
-Test::serialize(42)
-Exception: Test::serialize() must return a string or NULL
-==========
-bool(false)
-Test::__construct()
-Test::serialize()
-Exception: Test::serialize() must return a string or NULL
-===DONE===
+--TEST-- +ZE2 Serializable +--FILE-- +<?php + +class Test implements Serializable +{ + public $data; + + function __construct($data) + { + echo __METHOD__ . "($data)\n"; + $this->data = $data; + } + + function serialize() + { + echo __METHOD__ . "({$this->data})\n"; + return $this->data; + } + + function unserialize($serialized) + { + echo __METHOD__ . "($serialized)\n"; + $this->data = $serialized; + var_dump($this); + } +} + +$tests = array('String', NULL, 42, false); + +foreach($tests as $data) +{ + try + { + echo "==========\n"; + var_dump($data); + $ser = serialize(new Test($data)); + var_dump(unserialize($ser)); + } + catch(Exception $e) + { + echo 'Exception: ' . $e->getMessage() . "\n"; + } +} + +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +========== +%unicode|string%(6) "String" +Test::__construct(String) +Test::serialize(String) +Test::unserialize(String) +object(Test)#%d (1) { + [%u|b%"data"]=> + %unicode|string%(6) "String" +} +object(Test)#%d (1) { + [%u|b%"data"]=> + %unicode|string%(6) "String" +} +========== +NULL +Test::__construct() +Test::serialize() +NULL +========== +int(42) +Test::__construct(42) +Test::serialize(42) +Exception: Test::serialize() must return a string or NULL +========== +bool(false) +Test::__construct() +Test::serialize() +Exception: Test::serialize() must return a string or NULL +===DONE=== diff --git a/tests/classes/static_properties_003.phpt b/tests/classes/static_properties_003.phpt new file mode 100644 index 000000000..2441e4157 --- /dev/null +++ b/tests/classes/static_properties_003.phpt @@ -0,0 +1,49 @@ +--TEST-- +Attempting to access static properties using instance property syntax +--FILE-- +<?php +class C { + public static $x = 'C::$x'; + protected static $y = 'C::$y'; +} + +$c = new C; + +echo "\n--> Access visible static prop like instance prop:\n"; +var_dump(isset($c->x)); +unset($c->x); +echo $c->x; +$c->x = 1; +$ref = 'ref'; +$c->x =& $ref; +var_dump($c->x, C::$x); + +echo "\n--> Access non-visible static prop like instance prop:\n"; +var_dump(isset($c->y)); +//unset($c->y); // Fatal error, tested in static_properties_003_error1.phpt +//echo $c->y; // Fatal error, tested in static_properties_003_error2.phpt +//$c->y = 1; // Fatal error, tested in static_properties_003_error3.phpt +//$c->y =& $ref; // Fatal error, tested in static_properties_003_error4.phpt +?> +==Done== +--EXPECTF-- +--> Access visible static prop like instance prop: +bool(false) + +Strict Standards: Accessing static property C::$x as non static in %s on line 11 + +Strict Standards: Accessing static property C::$x as non static in %s on line 12 + +Notice: Undefined property: C::$x in %s on line 12 + +Strict Standards: Accessing static property C::$x as non static in %s on line 13 + +Strict Standards: Accessing static property C::$x as non static in %s on line 15 + +Strict Standards: Accessing static property C::$x as non static in %s on line 16 +%unicode|string%(3) "ref" +%unicode|string%(5) "C::$x" + +--> Access non-visible static prop like instance prop: +bool(false) +==Done==
\ No newline at end of file diff --git a/tests/classes/static_properties_003_error1.phpt b/tests/classes/static_properties_003_error1.phpt new file mode 100644 index 000000000..7a5e3d931 --- /dev/null +++ b/tests/classes/static_properties_003_error1.phpt @@ -0,0 +1,18 @@ +--TEST-- +Attempting to access static properties using instance property syntax +--FILE-- +<?php +class C { + protected static $y = 'C::$y'; +} +$c = new C; + +echo "\n--> Access non-visible static prop like instance prop:\n"; +unset($c->y); +?> +==Done== +--EXPECTF-- + +--> Access non-visible static prop like instance prop: + +Fatal error: Cannot access protected property C::$y in %s on line 8 diff --git a/tests/classes/static_properties_003_error2.phpt b/tests/classes/static_properties_003_error2.phpt new file mode 100644 index 000000000..589cc6909 --- /dev/null +++ b/tests/classes/static_properties_003_error2.phpt @@ -0,0 +1,18 @@ +--TEST-- +Attempting to access static properties using instance property syntax +--FILE-- +<?php +class C { + protected static $y = 'C::$y'; +} +$c = new C; + +echo "\n--> Access non-visible static prop like instance prop:\n"; +echo $c->y; +?> +==Done== +--EXPECTF-- + +--> Access non-visible static prop like instance prop: + +Fatal error: Cannot access protected property C::$y in %s on line 8 diff --git a/tests/classes/static_properties_003_error3.phpt b/tests/classes/static_properties_003_error3.phpt new file mode 100644 index 000000000..3e01e0e42 --- /dev/null +++ b/tests/classes/static_properties_003_error3.phpt @@ -0,0 +1,18 @@ +--TEST-- +Attempting to access static properties using instance property syntax +--FILE-- +<?php +class C { + protected static $y = 'C::$y'; +} +$c = new C; + +echo "\n--> Access non-visible static prop like instance prop:\n"; +$c->y = 1; +?> +==Done== +--EXPECTF-- + +--> Access non-visible static prop like instance prop: + +Fatal error: Cannot access protected property C::$y in %s on line 8 diff --git a/tests/classes/static_properties_003_error4.phpt b/tests/classes/static_properties_003_error4.phpt new file mode 100644 index 000000000..fd69a9ffb --- /dev/null +++ b/tests/classes/static_properties_003_error4.phpt @@ -0,0 +1,18 @@ +--TEST-- +Attempting to access static properties using instance property syntax +--FILE-- +<?php +class C { + protected static $y = 'C::$y'; +} +$c = new C; + +echo "\n--> Access non-visible static prop like instance prop:\n"; +$c->y =& $ref; +?> +==Done== +--EXPECTF-- + +--> Access non-visible static prop like instance prop: + +Fatal error: Cannot access protected property C::$y in %s on line 8 diff --git a/tests/classes/static_properties_004.phpt b/tests/classes/static_properties_004.phpt new file mode 100644 index 000000000..ce1d19dcc --- /dev/null +++ b/tests/classes/static_properties_004.phpt @@ -0,0 +1,37 @@ +--TEST-- +Inherited static properties can be separated from their reference set. +--FILE-- +<?php +class C { public static $p = 'original'; } +class D extends C { } +class E extends D { } + +echo "\nInherited static properties refer to the same value accross classes:\n"; +var_dump(C::$p, D::$p, E::$p); + +echo "\nChanging one changes all the others:\n"; +D::$p = 'changed.all'; +var_dump(C::$p, D::$p, E::$p); + +echo "\nBut because this is implemented using PHP references, the reference set can easily be split:\n"; +$ref = 'changed.one'; +D::$p =& $ref; +var_dump(C::$p, D::$p, E::$p); +?> +==Done== +--EXPECTF-- +Inherited static properties refer to the same value accross classes: +%unicode|string%(8) "original" +%unicode|string%(8) "original" +%unicode|string%(8) "original" + +Changing one changes all the others: +%unicode|string%(11) "changed.all" +%unicode|string%(11) "changed.all" +%unicode|string%(11) "changed.all" + +But because this is implemented using PHP references, the reference set can easily be split: +%unicode|string%(11) "changed.all" +%unicode|string%(11) "changed.one" +%unicode|string%(11) "changed.all" +==Done==
\ No newline at end of file diff --git a/tests/classes/type_hinting_005a.phpt b/tests/classes/type_hinting_005a.phpt new file mode 100644 index 000000000..d487a4461 --- /dev/null +++ b/tests/classes/type_hinting_005a.phpt @@ -0,0 +1,18 @@ +--TEST-- +Check type hint compatibility in overrides with array hints. +--FILE-- +<?php +Class C { function f(array $a) {} } + +echo "Compatible hint.\n"; +Class D1 extends C { function f(array $a) {} } + +echo "Class hint, should be array.\n"; +Class D2 extends C { function f(SomeClass $a) {} } +?> +==DONE== +--EXPECTF-- +Strict Standards: Declaration of D2::f() should be compatible with that of C::f() in %s on line 8 +Compatible hint. +Class hint, should be array. +==DONE==
\ No newline at end of file diff --git a/tests/classes/type_hinting_005b.phpt b/tests/classes/type_hinting_005b.phpt new file mode 100644 index 000000000..bc0d7686b --- /dev/null +++ b/tests/classes/type_hinting_005b.phpt @@ -0,0 +1,14 @@ +--TEST-- +Check type hint compatibility in overrides with array hints. +--FILE-- +<?php +Class C { function f(array $a) {} } + +echo "No hint, should be array.\n"; +Class D extends C { function f($a) {} } +?> +==DONE== +--EXPECTF-- +Strict Standards: Declaration of D::f() should be compatible with that of C::f() in %s on line 5 +No hint, should be array. +==DONE==
\ No newline at end of file diff --git a/tests/classes/type_hinting_005c.phpt b/tests/classes/type_hinting_005c.phpt new file mode 100644 index 000000000..d3b72412c --- /dev/null +++ b/tests/classes/type_hinting_005c.phpt @@ -0,0 +1,14 @@ +--TEST-- +Check type hint compatibility in overrides with array hints. +--FILE-- +<?php +Class C { function f(SomeClass $a) {} } + +echo "Array hint, should be class.\n"; +Class D extends C { function f(array $a) {} } +?> +==DONE== +--EXPECTF-- +Strict Standards: Declaration of D::f() should be compatible with that of C::f() in %s on line 5 +Array hint, should be class. +==DONE==
\ No newline at end of file diff --git a/tests/classes/type_hinting_005d.phpt b/tests/classes/type_hinting_005d.phpt new file mode 100644 index 000000000..60dda0ff2 --- /dev/null +++ b/tests/classes/type_hinting_005d.phpt @@ -0,0 +1,14 @@ +--TEST-- +Check type hint compatibility in overrides with array hints. +--FILE-- +<?php +Class C { function f($a) {} } + +echo "Array hint, should be nothing.\n"; +Class D extends C { function f(array $a) {} } +?> +==DONE== +--EXPECTF-- +Strict Standards: Declaration of D::f() should be compatible with that of C::f() in %s on line 5 +Array hint, should be nothing. +==DONE==
\ No newline at end of file diff --git a/tests/lang/bug43958.phpt b/tests/lang/bug43958.phpt new file mode 100644 index 000000000..bc88bcda0 --- /dev/null +++ b/tests/lang/bug43958.phpt @@ -0,0 +1,17 @@ +--TEST-- +Bug #43958 (class name added into the error message) +--FILE-- +<?php +class MyClass +{ + static public function loadCode($p) { + return include $p; + } +} + +MyClass::loadCode('file-which-does-not-exist-on-purpose.php'); +--EXPECTF-- +Warning: include(file-which-does-not-exist-on-purpose.php): failed to open stream: No such file or directory in %sbug43958.php on line 5 + +Warning: include(): Failed opening 'file-which-does-not-exist-on-purpose.php' for inclusion (include_path='%s') in %sbug43958.php on line 5 + diff --git a/tests/lang/bug45392.phpt b/tests/lang/bug45392.phpt new file mode 100644 index 000000000..2fec5e4a5 --- /dev/null +++ b/tests/lang/bug45392.phpt @@ -0,0 +1,21 @@ +--TEST-- +Bug #45392 (ob_start()/ob_end_clean() and memory_limit) +--INI-- +display_errors=stderr +--FILE-- +<?php +echo __LINE__ . "\n"; +ini_set('memory_limit', 100); +ob_start(NULL, 10); +echo __LINE__ ."\n"; +ob_start(); +$i = 0; +while($i++ < 5000) { + echo str_repeat("may not be displayed ", 42); +} +ob_end_flush(); +ob_end_clean(); +?> +--EXPECTF-- +2 +Fatal error: Allowed memory size of %d bytes exhausted%s diff --git a/tests/lang/func_get_arg.001.phpt b/tests/lang/func_get_arg.001.phpt new file mode 100644 index 000000000..b1bbb1869 --- /dev/null +++ b/tests/lang/func_get_arg.001.phpt @@ -0,0 +1,15 @@ +--TEST-- +func_get_arg test +--FILE-- +<?php + +function foo($a) +{ + $a=5; + echo func_get_arg(0); +} +foo(2); +echo "\n"; +?> +--EXPECT-- +2
\ No newline at end of file diff --git a/tests/lang/func_get_arg.002.phpt b/tests/lang/func_get_arg.002.phpt new file mode 100644 index 000000000..6ab4f9571 --- /dev/null +++ b/tests/lang/func_get_arg.002.phpt @@ -0,0 +1,19 @@ +--TEST-- +func_get_arg with variable number of args +--FILE-- +<?php + +function foo($a) +{ + $b = func_get_arg(1); + var_dump($b); + $b++; + var_dump(func_get_arg(1)); + +} +foo(2, 3); +echo "\n"; +?> +--EXPECT-- +int(3) +int(3) diff --git a/tests/lang/func_get_arg.003.phpt b/tests/lang/func_get_arg.003.phpt new file mode 100644 index 000000000..4ef996767 --- /dev/null +++ b/tests/lang/func_get_arg.003.phpt @@ -0,0 +1,11 @@ +--TEST-- +func_get_arg outside of a function declaration +--FILE-- +<?php + +var_dump (func_get_arg(0)); + +?> +--EXPECTF-- +Warning: func_get_arg(): Called from the global scope - no function context in %s on line %d +bool(false) diff --git a/tests/lang/func_get_arg.004.phpt b/tests/lang/func_get_arg.004.phpt new file mode 100644 index 000000000..6931df04e --- /dev/null +++ b/tests/lang/func_get_arg.004.phpt @@ -0,0 +1,16 @@ +--TEST-- +func_get_arg on non-existent arg +--FILE-- +<?php + +function foo($a) +{ + var_dump(func_get_arg(2)); +} +foo(2, 3); +echo "\n"; + +?> +--EXPECTF-- +Warning: func_get_arg(): Argument 2 not passed to function in %s on line %d +bool(false)
\ No newline at end of file diff --git a/tests/lang/func_get_arg.005.phpt b/tests/lang/func_get_arg.005.phpt new file mode 100644 index 000000000..e1ae78e16 --- /dev/null +++ b/tests/lang/func_get_arg.005.phpt @@ -0,0 +1,19 @@ +--TEST-- +A variable, which is referenced by another variable, is passed by value. +During the call, the original variable is updated. This should not affect func_get_arg(). +--FILE-- +<?php +function refVal($x) { + global $a; + $a = 'changed.a'; + var_dump($x); + var_dump(func_get_arg(0)); +} + +$a = "original.a"; +$ref =& $a; +refVal($a); +?> +--EXPECTF-- +string(10) "original.a" +string(10) "original.a"
\ No newline at end of file diff --git a/tests/lang/func_get_arg_variation.phpt b/tests/lang/func_get_arg_variation.phpt new file mode 100644 index 000000000..4865f7560 --- /dev/null +++ b/tests/lang/func_get_arg_variation.phpt @@ -0,0 +1,23 @@ +--TEST-- +func_get_arg test +--FILE-- +<?php + +function foo($a) +{ + $a=5; + echo func_get_arg(); + echo func_get_arg(2,2); + echo func_get_arg("hello"); + echo func_get_arg(-1); + echo func_get_arg(2); +} +foo(2); +echo "\n"; +?> +--EXPECTF-- +2 +Warning: func_get_arg(): The argument number should be >= 0 in %s on line %d + +Warning: func_get_arg(): Argument 2 not passed to function in %s on line %d + diff --git a/tests/lang/func_get_args.001.phpt b/tests/lang/func_get_args.001.phpt new file mode 100644 index 000000000..740a0a216 --- /dev/null +++ b/tests/lang/func_get_args.001.phpt @@ -0,0 +1,15 @@ +--TEST-- +func_get_args with no args +--FILE-- +<?php + +function foo() +{ + var_dump(func_get_args()); +} +foo(); + +?> +--EXPECT-- +array(0) { +}
\ No newline at end of file diff --git a/tests/lang/func_get_args.002.phpt b/tests/lang/func_get_args.002.phpt new file mode 100644 index 000000000..0a886c2f0 --- /dev/null +++ b/tests/lang/func_get_args.002.phpt @@ -0,0 +1,22 @@ +--TEST-- +func_get_args with variable number of args +--FILE-- +<?php + +function foo($a) +{ + var_dump(func_get_args()); +} +foo(1, 2, 3); + +?> +--EXPECT-- +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} + diff --git a/tests/lang/func_get_args.003.phpt b/tests/lang/func_get_args.003.phpt new file mode 100644 index 000000000..44faf7ebf --- /dev/null +++ b/tests/lang/func_get_args.003.phpt @@ -0,0 +1,11 @@ +--TEST-- +func_get_args() outside of a function declaration +--FILE-- +<?php + +var_dump(func_get_args()); + +?> +--EXPECTREGEX-- +Warning\: func_get_args\(\)\: Called from the global scope - no function context in \S* on line 3 +bool\(false\) diff --git a/tests/lang/func_get_args.004.phpt b/tests/lang/func_get_args.004.phpt new file mode 100644 index 000000000..84e3ebe5a --- /dev/null +++ b/tests/lang/func_get_args.004.phpt @@ -0,0 +1,67 @@ +--TEST-- +Pass same variable by ref and by value. +--FILE-- +<?php +function valRef($x, &$y) { + var_dump($x, $y); + var_dump(func_get_args()); + $x = 'changed.x'; + $y = 'changed.y'; + var_dump(func_get_args()); +} + +function refVal(&$x, $y) { + var_dump($x, $y); + var_dump(func_get_args()); + $x = 'changed.x'; + $y = 'changed.y'; + var_dump(func_get_args()); +} + + +echo "\n\n-- Val, Ref --\n"; +$a = 'original.a'; +valRef($a, $a); +var_dump($a); + +echo "\n\n-- Ref, Val --\n"; +$b = 'original.b'; +refVal($b, $b); +var_dump($b); +?> +--EXPECTF-- + +-- Val, Ref -- +string(10) "original.a" +string(10) "original.a" +array(2) { + [0]=> + string(10) "original.a" + [1]=> + string(10) "original.a" +} +array(2) { + [0]=> + string(10) "original.a" + [1]=> + string(9) "changed.y" +} +string(9) "changed.y" + + +-- Ref, Val -- +string(10) "original.b" +string(10) "original.b" +array(2) { + [0]=> + string(10) "original.b" + [1]=> + string(10) "original.b" +} +array(2) { + [0]=> + string(9) "changed.x" + [1]=> + string(10) "original.b" +} +string(9) "changed.x"
\ No newline at end of file diff --git a/tests/lang/func_num_args.001.phpt b/tests/lang/func_num_args.001.phpt new file mode 100644 index 000000000..c281557fe --- /dev/null +++ b/tests/lang/func_num_args.001.phpt @@ -0,0 +1,14 @@ +--TEST-- +func_num_args with no args +--FILE-- +<?php + +function foo() +{ + var_dump(func_num_args()); +} +foo(); + +?> +--EXPECT-- +int(0)
\ No newline at end of file diff --git a/tests/lang/func_num_args.002.phpt b/tests/lang/func_num_args.002.phpt new file mode 100644 index 000000000..bfb8f7c70 --- /dev/null +++ b/tests/lang/func_num_args.002.phpt @@ -0,0 +1,14 @@ +--TEST-- +func_num_args with variable number of args +--FILE-- +<?php + +function foo($a) +{ + var_dump(func_num_args()); +} +foo(1, 2, 3); + +?> +--EXPECT-- +int(3)
\ No newline at end of file diff --git a/tests/lang/func_num_args.003.phpt b/tests/lang/func_num_args.003.phpt new file mode 100644 index 000000000..7cf1229bc --- /dev/null +++ b/tests/lang/func_num_args.003.phpt @@ -0,0 +1,12 @@ +--TEST-- +func_num_args() outside of a function declaration +--FILE-- +<?php + +var_dump(func_num_args()); + +?> +--EXPECTF-- + +Warning: func_num_args(): Called from the global scope - no function context in %s on line %d +int(-1)
\ No newline at end of file diff --git a/tests/lang/func_num_args.004.phpt b/tests/lang/func_num_args.004.phpt new file mode 100644 index 000000000..8bdc6f07f --- /dev/null +++ b/tests/lang/func_num_args.004.phpt @@ -0,0 +1,48 @@ +--TEST-- +Pass same variable by ref and by value. +--FILE-- +<?php +function valRef($x, &$y) { + var_dump($x, $y); + var_dump(func_num_args()); + $x = 'changed.x'; + $y = 'changed.y'; + var_dump(func_num_args()); +} + +function refVal(&$x, $y) { + var_dump($x, $y); + var_dump(func_num_args()); + $x = 'changed.x'; + $y = 'changed.y'; + var_dump(func_num_args()); +} + + +echo "\n\n-- Val, Ref --\n"; +$a = 'original.a'; +valRef($a, $a); +var_dump($a); + +echo "\n\n-- Ref, Val --\n"; +$b = 'original.b'; +refVal($b, $b); +var_dump($b); +?> +--EXPECTF-- + + +-- Val, Ref -- +string(10) "original.a" +string(10) "original.a" +int(2) +int(2) +string(9) "changed.y" + + +-- Ref, Val -- +string(10) "original.b" +string(10) "original.b" +int(2) +int(2) +string(9) "changed.x" diff --git a/tests/lang/passByReference_001.phpt b/tests/lang/passByReference_001.phpt new file mode 100644 index 000000000..c73eacc59 --- /dev/null +++ b/tests/lang/passByReference_001.phpt @@ -0,0 +1,37 @@ +--TEST-- +passing of function parameters by reference +--FILE-- +<?php +function f($arg1, &$arg2) +{ + var_dump($arg1++); + var_dump($arg2++); +} + +function g (&$arg1, &$arg2) +{ + var_dump($arg1); + var_dump($arg2); +} +$a = 7; +$b = 15; + +f($a, $b); + +var_dump($a); +var_dump($b); + +$c=array(1); +g($c,$c[0]); + +?> +--EXPECT-- +int(7) +int(15) +int(7) +int(16) +array(1) { + [0]=> + &int(1) +} +int(1)
\ No newline at end of file diff --git a/tests/lang/passByReference_002.phpt b/tests/lang/passByReference_002.phpt new file mode 100644 index 000000000..d1968a352 --- /dev/null +++ b/tests/lang/passByReference_002.phpt @@ -0,0 +1,15 @@ +--TEST-- +Attempt to pass a constant by reference +--FILE-- +<?php + +function f(&$arg1) +{ + var_dump($arg1++); +} + +f(2); + +?> +--EXPECTF-- +Fatal error: Only variables can be passed by reference in %s on line 8 diff --git a/tests/lang/passByReference_003.phpt b/tests/lang/passByReference_003.phpt new file mode 100644 index 000000000..bbbc56465 --- /dev/null +++ b/tests/lang/passByReference_003.phpt @@ -0,0 +1,48 @@ +--TEST-- +Implicit initialisation when passing by reference +--FILE-- +<?php +function passbyVal($val) { + echo "\nInside passbyVal call:\n"; + var_dump($val); +} + +function passbyRef(&$ref) { + echo "\nInside passbyRef call:\n"; + var_dump($ref); +} + +echo "\nPassing undefined by value\n"; +passbyVal($undef1[0]); +echo "\nAfter call\n"; +var_dump($undef1); + +echo "\nPassing undefined by reference\n"; +passbyRef($undef2[0]); +echo "\nAfter call\n"; +var_dump($undef2) +?> +--EXPECTF-- + +Passing undefined by value + +Notice: Undefined variable: undef1 in %s on line 13 + +Inside passbyVal call: +NULL + +After call + +Notice: Undefined variable: undef1 in %s on line 15 +NULL + +Passing undefined by reference + +Inside passbyRef call: +NULL + +After call +array(1) { + [0]=> + NULL +} diff --git a/tests/lang/passByReference_004.phpt b/tests/lang/passByReference_004.phpt new file mode 100644 index 000000000..e8a7963d2 --- /dev/null +++ b/tests/lang/passByReference_004.phpt @@ -0,0 +1,21 @@ +--TEST-- +passing the return value from a function by reference +--FILE-- +<?php + +function foo(&$ref) +{ + var_dump($ref); +} + +function bar($value) +{ + return $value; +} + +foo(bar(5)); + +?> +--EXPECTF-- +Strict Standards: Only variables should be passed by reference in %s on line 13 +int(5) diff --git a/tests/lang/passByReference_005.phpt b/tests/lang/passByReference_005.phpt new file mode 100644 index 000000000..52ddeebd1 --- /dev/null +++ b/tests/lang/passByReference_005.phpt @@ -0,0 +1,261 @@ +--TEST-- +Pass uninitialised variables by reference and by value to test implicit initialisation. +--FILE-- +<?php + +function v($val) { + $val = "Val changed"; +} + +function r(&$ref) { + $ref = "Ref changed"; +} + + +function vv($val1, $val2) { + $val1 = "Val1 changed"; + $val2 = "Val2 changed"; +} + +function vr($val, &$ref) { + $val = "Val changed"; + $ref = "Ref changed"; +} + +function rv(&$ref, $val) { + $val = "Val changed"; + $ref = "Ref changed"; +} + +function rr(&$ref1, &$ref2) { + $ref1 = "Ref1 changed"; + $ref2 = "Ref2 changed"; +} + + +class C { + + function __construct($val, &$ref) { + $val = "Val changed"; + $ref = "Ref changed"; + } + + function v($val) { + $val = "Val changed"; + } + + function r(&$ref) { + $ref = "Ref changed"; + } + + function vv($val1, $val2) { + $val1 = "Val1 changed"; + $val2 = "Val2 changed"; + } + + function vr($val, &$ref) { + $val = "Val changed"; + $ref = "Ref changed"; + } + + function rv(&$ref, $val) { + $val = "Val changed"; + $ref = "Ref changed"; + } + + function rr(&$ref1, &$ref2) { + $ref1 = "Ref1 changed"; + $ref2 = "Ref2 changed"; + } + +} + +echo "\n ---- Pass by ref / pass by val: functions ----\n"; +unset($u1, $u2); +v($u1); +r($u2); +var_dump($u1, $u2); + +unset($u1, $u2); +vv($u1, $u2); +var_dump($u1, $u2); + +unset($u1, $u2); +vr($u1, $u2); +var_dump($u1, $u2); + +unset($u1, $u2); +rv($u1, $u2); +var_dump($u1, $u2); + +unset($u1, $u2); +rr($u1, $u2); +var_dump($u1, $u2); + + +echo "\n\n ---- Pass by ref / pass by val: static method calls ----\n"; +unset($u1, $u2); +C::v($u1); +C::r($u2); +var_dump($u1, $u2); + +unset($u1, $u2); +C::vv($u1, $u2); +var_dump($u1, $u2); + +unset($u1, $u2); +C::vr($u1, $u2); +var_dump($u1, $u2); + +unset($u1, $u2); +C::rv($u1, $u2); +var_dump($u1, $u2); + +unset($u1, $u2); +C::rr($u1, $u2); +var_dump($u1, $u2); + +echo "\n\n ---- Pass by ref / pass by val: instance method calls ----\n"; +unset($u1, $u2); +$c = new C($u1, $u2); +var_dump($u1, $u2); + +unset($u1, $u2); +$c->v($u1); +$c->r($u2); +var_dump($u1, $u2); + +unset($u1, $u2); +$c->vv($u1, $u2); +var_dump($u1, $u2); + +unset($u1, $u2); +$c->vr($u1, $u2); +var_dump($u1, $u2); + +unset($u1, $u2); +$c->rv($u1, $u2); +var_dump($u1, $u2); + +unset($u1, $u2); +$c->rr($u1, $u2); +var_dump($u1, $u2); + +?> +--EXPECTF-- + + ---- Pass by ref / pass by val: functions ---- + +Notice: Undefined variable: u1 in %s on line 72 + +Notice: Undefined variable: u1 in %s on line 74 +NULL +string(11) "Ref changed" + +Notice: Undefined variable: u1 in %s on line 77 + +Notice: Undefined variable: u2 in %s on line 77 + +Notice: Undefined variable: u1 in %s on line 78 + +Notice: Undefined variable: u2 in %s on line 78 +NULL +NULL + +Notice: Undefined variable: u1 in %s on line 81 + +Notice: Undefined variable: u1 in %s on line 82 +NULL +string(11) "Ref changed" + +Notice: Undefined variable: u2 in %s on line 85 + +Notice: Undefined variable: u2 in %s on line 86 +string(11) "Ref changed" +NULL +string(12) "Ref1 changed" +string(12) "Ref2 changed" + + + ---- Pass by ref / pass by val: static method calls ---- + +Notice: Undefined variable: u1 in %s on line 95 + +Strict Standards: Non-static method C::v() should not be called statically in %s on line 95 + +Strict Standards: Non-static method C::r() should not be called statically in %s on line 96 + +Notice: Undefined variable: u1 in %s on line 97 +NULL +string(11) "Ref changed" + +Notice: Undefined variable: u1 in %s on line 100 + +Notice: Undefined variable: u2 in %s on line 100 + +Strict Standards: Non-static method C::vv() should not be called statically in %s on line 100 + +Notice: Undefined variable: u1 in %s on line 101 + +Notice: Undefined variable: u2 in %s on line 101 +NULL +NULL + +Notice: Undefined variable: u1 in %s on line 104 + +Strict Standards: Non-static method C::vr() should not be called statically in %s on line 104 + +Notice: Undefined variable: u1 in %s on line 105 +NULL +string(11) "Ref changed" + +Notice: Undefined variable: u2 in %s on line 108 + +Strict Standards: Non-static method C::rv() should not be called statically in %s on line 108 + +Notice: Undefined variable: u2 in %s on line 109 +string(11) "Ref changed" +NULL + +Strict Standards: Non-static method C::rr() should not be called statically in %s on line 112 +string(12) "Ref1 changed" +string(12) "Ref2 changed" + + + ---- Pass by ref / pass by val: instance method calls ---- + +Notice: Undefined variable: u1 in %s on line 117 + +Notice: Undefined variable: u1 in %s on line 118 +NULL +string(11) "Ref changed" + +Notice: Undefined variable: u1 in %s on line 121 + +Notice: Undefined variable: u1 in %s on line 123 +NULL +string(11) "Ref changed" + +Notice: Undefined variable: u1 in %s on line 126 + +Notice: Undefined variable: u2 in %s on line 126 + +Notice: Undefined variable: u1 in %s on line 127 + +Notice: Undefined variable: u2 in %s on line 127 +NULL +NULL + +Notice: Undefined variable: u1 in %s on line 130 + +Notice: Undefined variable: u1 in %s on line 131 +NULL +string(11) "Ref changed" + +Notice: Undefined variable: u2 in %s on line 134 + +Notice: Undefined variable: u2 in %s on line 135 +string(11) "Ref changed" +NULL +string(12) "Ref1 changed" +string(12) "Ref2 changed"
\ No newline at end of file diff --git a/tests/lang/passByReference_006.phpt b/tests/lang/passByReference_006.phpt new file mode 100644 index 000000000..248be88b4 --- /dev/null +++ b/tests/lang/passByReference_006.phpt @@ -0,0 +1,195 @@ +--TEST-- +Pass uninitialised objects and arrays by reference to test implicit initialisation. +--FILE-- +<?php + +function refs(&$ref1, &$ref2, &$ref3, &$ref4, &$ref5) { + $ref1 = "Ref1 changed"; + $ref2 = "Ref2 changed"; + $ref3 = "Ref3 changed"; + $ref4 = "Ref4 changed"; + $ref5 = "Ref5 changed"; +} + + +class C { + + function __construct(&$ref1, &$ref2, &$ref3, &$ref4, &$ref5) { + $ref1 = "Ref1 changed"; + $ref2 = "Ref2 changed"; + $ref3 = "Ref3 changed"; + $ref4 = "Ref4 changed"; + $ref5 = "Ref5 changed"; + } + + function refs(&$ref1, &$ref2, &$ref3, &$ref4, &$ref5) { + $ref1 = "Ref1 changed"; + $ref2 = "Ref2 changed"; + $ref3 = "Ref3 changed"; + $ref4 = "Ref4 changed"; + $ref5 = "Ref5 changed"; + } + +} + +echo "\n ---- Pass uninitialised array & object by ref: function call ---\n"; +unset($u1, $u2, $u3, $u4, $u5); +refs($u1[0], $u2[0][1], $u3->a, $u4->a->b, $u5->a->b->c); +var_dump($u1, $u2, $u3, $u4, $u5); + +echo "\n ---- Pass uninitialised arrays & objects by ref: static method call ---\n"; +unset($u1, $u2, $u3, $u4, $u5); +C::refs($u1[0], $u2[0][1], $u3->a, $u4->a->b, $u5->a->b->c); +var_dump($u1, $u2, $u3, $u4, $u5); + +echo "\n\n---- Pass uninitialised arrays & objects by ref: constructor ---\n"; +unset($u1, $u2, $u3, $u4, $u5); +$c = new C($u1[0], $u2[0][1], $u3->a, $u4->a->b, $u5->a->b->c); +var_dump($u1, $u2, $u3, $u4, $u5); + +echo "\n ---- Pass uninitialised arrays & objects by ref: instance method call ---\n"; +unset($u1, $u2, $u3, $u4, $u5); +$c->refs($u1[0], $u2[0][1], $u3->a, $u4->a->b, $u5->a->b->c); +var_dump($u1, $u2, $u3, $u4, $u5); + +?> +--EXPECTF-- + + ---- Pass uninitialised array & object by ref: function call --- +array(1) { + [0]=> + string(12) "Ref1 changed" +} +array(1) { + [0]=> + array(1) { + [1]=> + string(12) "Ref2 changed" + } +} +object(stdClass)#%d (1) { + ["a"]=> + string(12) "Ref3 changed" +} +object(stdClass)#%d (1) { + ["a"]=> + object(stdClass)#%d (1) { + ["b"]=> + string(12) "Ref4 changed" + } +} +object(stdClass)#%d (1) { + ["a"]=> + object(stdClass)#%d (1) { + ["b"]=> + object(stdClass)#%d (1) { + ["c"]=> + string(12) "Ref5 changed" + } + } +} + + ---- Pass uninitialised arrays & objects by ref: static method call --- + +Strict Standards: Non-static method C::refs() should not be called statically in %s on line 39 +array(1) { + [0]=> + string(12) "Ref1 changed" +} +array(1) { + [0]=> + array(1) { + [1]=> + string(12) "Ref2 changed" + } +} +object(stdClass)#%d (1) { + ["a"]=> + string(12) "Ref3 changed" +} +object(stdClass)#%d (1) { + ["a"]=> + object(stdClass)#%d (1) { + ["b"]=> + string(12) "Ref4 changed" + } +} +object(stdClass)#%d (1) { + ["a"]=> + object(stdClass)#%d (1) { + ["b"]=> + object(stdClass)#%d (1) { + ["c"]=> + string(12) "Ref5 changed" + } + } +} + + +---- Pass uninitialised arrays & objects by ref: constructor --- +array(1) { + [0]=> + string(12) "Ref1 changed" +} +array(1) { + [0]=> + array(1) { + [1]=> + string(12) "Ref2 changed" + } +} +object(stdClass)#%d (1) { + ["a"]=> + string(12) "Ref3 changed" +} +object(stdClass)#%d (1) { + ["a"]=> + object(stdClass)#%d (1) { + ["b"]=> + string(12) "Ref4 changed" + } +} +object(stdClass)#%d (1) { + ["a"]=> + object(stdClass)#%d (1) { + ["b"]=> + object(stdClass)#%d (1) { + ["c"]=> + string(12) "Ref5 changed" + } + } +} + + ---- Pass uninitialised arrays & objects by ref: instance method call --- +array(1) { + [0]=> + string(12) "Ref1 changed" +} +array(1) { + [0]=> + array(1) { + [1]=> + string(12) "Ref2 changed" + } +} +object(stdClass)#%d (1) { + ["a"]=> + string(12) "Ref3 changed" +} +object(stdClass)#%d (1) { + ["a"]=> + object(stdClass)#%d (1) { + ["b"]=> + string(12) "Ref4 changed" + } +} +object(stdClass)#%d (1) { + ["a"]=> + object(stdClass)#%d (1) { + ["b"]=> + object(stdClass)#%d (1) { + ["c"]=> + string(12) "Ref5 changed" + } + } +}
\ No newline at end of file diff --git a/tests/lang/passByReference_007.phpt b/tests/lang/passByReference_007.phpt new file mode 100644 index 000000000..558ceae27 --- /dev/null +++ b/tests/lang/passByReference_007.phpt @@ -0,0 +1,105 @@ +--TEST-- +Pass function and method calls by reference and by value. +--FILE-- +<?php +class C { + static function sreturnVal() { + global $a; + return $a; + } + + static function &sreturnReference() { + global $a; + return $a; + } + + function returnVal() { + global $a; + return $a; + } + + function &returnReference() { + global $a; + return $a; + } +} + +function returnVal() { + global $a; + return $a; +} + +function &returnReference() { + global $a; + return $a; +} + + + +function foo(&$ref) { + var_dump($ref); + $ref = "changed"; +} + + +echo "Pass a function call that returns a value:\n"; +$a = "original"; +foo(returnVal()); +var_dump($a); + +echo "Pass a function call that returns a reference:\n"; +$a = "original"; +foo(returnReference()); +var_dump($a); + + +echo "\nPass a static method call that returns a value:\n"; +$a = "original"; +foo(C::sreturnVal()); +var_dump($a); + +echo "Pass a static method call that returns a reference:\n"; +$a = "original"; +foo(C::sreturnReference()); +var_dump($a); + + +$myC = new C; +echo "\nPass a method call that returns a value:\n"; +$a = "original"; +foo($myC->returnVal()); +var_dump($a); + +echo "Pass a method call that returns a reference:\n"; +$a = "original"; +foo($myC->returnReference()); +var_dump($a); + +?> +--EXPECTF-- +Pass a function call that returns a value: + +Strict Standards: Only variables should be passed by reference in %s on line 44 +string(8) "original" +string(8) "original" +Pass a function call that returns a reference: +string(8) "original" +string(7) "changed" + +Pass a static method call that returns a value: + +Strict Standards: Only variables should be passed by reference in %s on line 55 +string(8) "original" +string(8) "original" +Pass a static method call that returns a reference: +string(8) "original" +string(7) "changed" + +Pass a method call that returns a value: + +Strict Standards: Only variables should be passed by reference in %s on line 67 +string(8) "original" +string(8) "original" +Pass a method call that returns a reference: +string(8) "original" +string(7) "changed"
\ No newline at end of file diff --git a/tests/lang/passByReference_008.phpt b/tests/lang/passByReference_008.phpt new file mode 100644 index 000000000..36852170b --- /dev/null +++ b/tests/lang/passByReference_008.phpt @@ -0,0 +1,40 @@ +--TEST-- +Pass same variable by ref and by value. +--FILE-- +<?php +function valRef($x, &$y) { + var_dump($x, $y); + $x = 'changed.x'; + $y = 'changed.y'; +} + +function refVal(&$x, $y) { + var_dump($x, $y); + $x = 'changed.x'; + $y = 'changed.y'; +} + + +echo "\n\n-- Val, Ref --\n"; +$a = 'original.a'; +valRef($a, $a); +var_dump($a); + +echo "\n\n-- Ref, Val --\n"; +$b = 'original.b'; +refVal($b, $b); +var_dump($b); +?> +--EXPECTF-- + + +-- Val, Ref -- +string(10) "original.a" +string(10) "original.a" +string(9) "changed.y" + + +-- Ref, Val -- +string(10) "original.b" +string(10) "original.b" +string(9) "changed.x"
\ No newline at end of file diff --git a/tests/lang/passByReference_009.phpt b/tests/lang/passByReference_009.phpt new file mode 100644 index 000000000..1cbd87d6c --- /dev/null +++ b/tests/lang/passByReference_009.phpt @@ -0,0 +1,24 @@ +--TEST-- +Assignement as argument +--FILE-- +<?php + function foo(&$x, &$y) { $x = 1; echo $y ; } + + $x = 0; + foo($x, $x); // prints 1 .. + + + function foo2($x, &$y, $z) + { + echo $x; // 0 + echo $y; // 1 + $y = 2; + } + + $x = 0; + + foo2($x, $x, $x = 1); + echo $x; // 2 +?> +--EXPECTF-- +1012
\ No newline at end of file diff --git a/tests/lang/passByReference_010.phpt b/tests/lang/passByReference_010.phpt new file mode 100644 index 000000000..0393cce2d --- /dev/null +++ b/tests/lang/passByReference_010.phpt @@ -0,0 +1,61 @@ +--TEST-- +Passing assignments by reference +--FILE-- +<?php + +function f(&$a) { + var_dump($a); + $a = "a.changed"; +} + +echo "\n\n---> Pass constant assignment by reference:\n"; +f($a="a.original"); +var_dump($a); + +echo "\n\n---> Pass variable assignment by reference:\n"; +unset($a); +$a = "a.original"; +f($b = $a); +var_dump($a); + +echo "\n\n---> Pass reference assignment by reference:\n"; +unset($a, $b); +$a = "a.original"; +f($b =& $a); +var_dump($a); + +echo "\n\n---> Pass concat assignment by reference:\n"; +unset($a, $b); +$b = "b.original"; +$a = "a.original"; +f($b .= $a); +var_dump($a); + +?> +--EXPECTF-- + + +---> Pass constant assignment by reference: + +Strict Standards: Only variables should be passed by reference in %s on line 9 +string(10) "a.original" +string(10) "a.original" + + +---> Pass variable assignment by reference: + +Strict Standards: Only variables should be passed by reference in %s on line 15 +string(10) "a.original" +string(10) "a.original" + + +---> Pass reference assignment by reference: +string(10) "a.original" +string(9) "a.changed" + + +---> Pass concat assignment by reference: + +Strict Standards: Only variables should be passed by reference in %s on line 28 +string(20) "b.originala.original" +string(10) "a.original" diff --git a/tests/lang/short_tags.001.phpt b/tests/lang/short_tags.001.phpt new file mode 100644 index 000000000..522018e30 --- /dev/null +++ b/tests/lang/short_tags.001.phpt @@ -0,0 +1,12 @@ +--TEST-- +short_open_tag: On +--INI-- +short_open_tag=on +--FILE-- +<? +echo "Used a short tag\n"; +?> +Finished +--EXPECT-- +Used a short tag +Finished diff --git a/tests/lang/short_tags.002.phpt b/tests/lang/short_tags.002.phpt new file mode 100644 index 000000000..6a3d5e099 --- /dev/null +++ b/tests/lang/short_tags.002.phpt @@ -0,0 +1,14 @@ +--TEST-- +short_open_tag: Off +--INI-- +short_open_tag=off +--FILE-- +<? +echo "Used a short tag\n"; +?> +Finished +--EXPECT-- +<? +echo "Used a short tag\n"; +?> +Finished diff --git a/tests/lang/short_tags.003.phpt b/tests/lang/short_tags.003.phpt new file mode 100644 index 000000000..8894bf502 --- /dev/null +++ b/tests/lang/short_tags.003.phpt @@ -0,0 +1,32 @@ +--TEST-- +short_open_tag: On, asp_tags: On +--INI-- +short_open_tag=on +asp_tags=on +--FILE-- +<?='this should get echoed'?> + +<%= 'so should this' %> + +<?php +$a = 'This gets echoed twice'; +?> + +<?= $a?> + +<%= $a%> + +<? $b=3; ?> + +<?php + echo "{$b}"; +?> +--EXPECT-- +this should get echoed +so should this + +This gets echoed twice +This gets echoed twice + +3 + diff --git a/tests/lang/short_tags.004.phpt b/tests/lang/short_tags.004.phpt new file mode 100644 index 000000000..d80e7481a --- /dev/null +++ b/tests/lang/short_tags.004.phpt @@ -0,0 +1,37 @@ +--TEST-- +short_open_tag: Off, asp_tags: Off +--INI-- +short_open_tag=off +asp_tags=off +--FILE-- +<?='this should get echoed'?> + +<%= 'so should this' %> + +<?php +$a = 'This gets echoed twice'; +?> + +<?= $a?> + +<%= $a%> + +<? $b=3; ?> + +<?php + echo "{$b}"; +?> +--EXPECTF-- +<?='this should get echoed'?> + +<%= 'so should this' %> + + +<?= $a?> + +<%= $a%> + +<? $b=3; ?> + + +Notice: Undefined variable: b in %s on line %d diff --git a/tests/lang/static_basic_001.phpt b/tests/lang/static_basic_001.phpt new file mode 100644 index 000000000..45fc1b2ab --- /dev/null +++ b/tests/lang/static_basic_001.phpt @@ -0,0 +1,84 @@ +--TEST-- +Static keyword - basic tests +--FILE-- +<?php + +echo "\nSame variable used as static and non static.\n"; +function staticNonStatic() { + echo "---------\n"; + $a=0; + echo "$a\n"; + static $a=10; + echo "$a\n"; + $a++; +} +staticNonStatic(); +staticNonStatic(); +staticNonStatic(); + +echo "\nLots of initialisations in the same statement.\n"; +function manyInits() { + static $counter=0; + echo "------------- Call $counter --------------\n"; + static $a, $b=10, $c=20, $d, $e=30; + echo "Unitialised : $a\n"; + echo "Initialised to 10: $b\n"; + echo "Initialised to 20: $c\n"; + echo "Unitialised : $d\n"; + echo "Initialised to 30: $e\n"; + $a++; + $b++; + $c++; + $d++; + $e++; + $counter++; +} +manyInits(); +manyInits(); +manyInits(); + +echo "\nUsing static keyword at global scope\n"; +for ($i=0; $i<3; $i++) { + static $s, $k=10; + echo "$s $k\n"; + $s++; + $k++; +} +?> +--EXPECT-- + +Same variable used as static and non static. +--------- +0 +10 +--------- +0 +11 +--------- +0 +12 + +Lots of initialisations in the same statement. +------------- Call 0 -------------- +Unitialised : +Initialised to 10: 10 +Initialised to 20: 20 +Unitialised : +Initialised to 30: 30 +------------- Call 1 -------------- +Unitialised : 1 +Initialised to 10: 11 +Initialised to 20: 21 +Unitialised : 1 +Initialised to 30: 31 +------------- Call 2 -------------- +Unitialised : 2 +Initialised to 10: 12 +Initialised to 20: 22 +Unitialised : 2 +Initialised to 30: 32 + +Using static keyword at global scope + 10 +1 11 +2 12
\ No newline at end of file diff --git a/tests/lang/static_basic_002.phpt b/tests/lang/static_basic_002.phpt new file mode 100644 index 000000000..06e2f724e --- /dev/null +++ b/tests/lang/static_basic_002.phpt @@ -0,0 +1,28 @@ +--TEST-- +Multiple declarations of the same static variable +--FILE-- +<?php + +$a = 5; + +var_dump($a); + +static $a = 10; +static $a = 11; + +var_dump($a); + +function foo() { + static $a = 13; + static $a = 14; + + var_dump($a); +} + +foo(); + +?> +--EXPECT-- +int(5) +int(11) +int(14) diff --git a/tests/lang/static_variation_001.phpt b/tests/lang/static_variation_001.phpt new file mode 100644 index 000000000..a27b9fadc --- /dev/null +++ b/tests/lang/static_variation_001.phpt @@ -0,0 +1,112 @@ +--TEST-- +Statics in nested functions & evals. +--FILE-- +<?php + +static $a = array(7,8,9); + +function f1() { + static $a = array(1,2,3); + + function g1() { + static $a = array(4,5,6); + var_dump($a); + } + + var_dump($a); + +} + +f1(); +g1(); +var_dump($a); + +eval(' static $b = array(10,11,12); '); + +function f2() { + eval(' static $b = array(1,2,3); '); + + function g2a() { + eval(' static $b = array(4,5,6); '); + var_dump($b); + } + + eval('function g2b() { static $b = array(7, 8, 9); var_dump($b); } '); + var_dump($b); +} + +f2(); +g2a(); +g2b(); +var_dump($b); + + +eval(' function f3() { static $c = array(1,2,3); var_dump($c); }'); +f3(); + +?> +--EXPECTF-- +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +array(3) { + [0]=> + int(4) + [1]=> + int(5) + [2]=> + int(6) +} +array(3) { + [0]=> + int(7) + [1]=> + int(8) + [2]=> + int(9) +} +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +array(3) { + [0]=> + int(4) + [1]=> + int(5) + [2]=> + int(6) +} +array(3) { + [0]=> + int(7) + [1]=> + int(8) + [2]=> + int(9) +} +array(3) { + [0]=> + int(10) + [1]=> + int(11) + [2]=> + int(12) +} +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +}
\ No newline at end of file diff --git a/tests/lang/static_variation_002.phpt b/tests/lang/static_variation_002.phpt new file mode 100644 index 000000000..b8933fd26 --- /dev/null +++ b/tests/lang/static_variation_002.phpt @@ -0,0 +1,84 @@ +--TEST-- +Static variables in methods & nested functions & evals. +--FILE-- +<?php + +Class C { + function f() { + static $a = array(1,2,3); + eval(' static $k = array(4,5,6); '); + + function cfg() { + static $a = array(7,8,9); + eval(' static $k = array(10,11,12); '); + var_dump($a, $k); + } + var_dump($a, $k); + } +} +$c = new C; +$c->f(); +cfg(); + +Class D { + static function f() { + eval('function dfg() { static $b = array(1,2,3); var_dump($b); } '); + } +} +D::f(); +dfg(); + +eval(' Class E { function f() { static $c = array(1,2,3); var_dump($c); } }'); +$e = new E; +$e->f(); + +?> +--EXPECTF-- +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +array(3) { + [0]=> + int(4) + [1]=> + int(5) + [2]=> + int(6) +} +array(3) { + [0]=> + int(7) + [1]=> + int(8) + [2]=> + int(9) +} +array(3) { + [0]=> + int(10) + [1]=> + int(11) + [2]=> + int(12) +} +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +}
\ No newline at end of file diff --git a/tests/output/flush_basic_001.phpt b/tests/output/flush_basic_001.phpt new file mode 100644 index 000000000..d9bb63979 --- /dev/null +++ b/tests/output/flush_basic_001.phpt @@ -0,0 +1,26 @@ +--TEST-- +Test basic functionality of flush() +--FILE-- +<?php +/* + * proto void flush(void) + * Function is implemented in ext/standard/basic_functions.c. + */ + +// Verify return type +var_dump(flush()); + +// Ensure user buffers are not flushed by flush() +ob_start(); +echo "Inside a user buffer\n"; +flush(); +ob_end_clean(); + +echo "Outside of any user buffers\n"; +var_dump(flush()); + +?> +--EXPECT-- +NULL +Outside of any user buffers +NULL
\ No newline at end of file diff --git a/tests/output/flush_error_001.phpt b/tests/output/flush_error_001.phpt new file mode 100644 index 000000000..720c0d503 --- /dev/null +++ b/tests/output/flush_error_001.phpt @@ -0,0 +1,16 @@ +--TEST-- +Test wrong number of arguments for flush() (no impact) +--FILE-- +<?php +/* + * proto void flush(void) + * Function is implemented in ext/standard/basic_functions.c. + */ + +$extra_arg = 1; +echo "\nToo many arguments\n"; +var_dump(flush($extra_arg)); +?> +--EXPECTF-- +Too many arguments +NULL
\ No newline at end of file diff --git a/tests/output/ob_clean_basic_001.phpt b/tests/output/ob_clean_basic_001.phpt new file mode 100644 index 000000000..c93bea358 --- /dev/null +++ b/tests/output/ob_clean_basic_001.phpt @@ -0,0 +1,36 @@ +--TEST-- +Test ob_clean() function : basic functionality +--FILE-- +<?php +/* Prototype : proto bool ob_clean(void) + * Description: Clean (delete) the current output buffer + * Source code: main/output.c + * Alias to functions: + */ + +echo "*** Testing ob_clean() : basic functionality ***\n"; + +// Zero arguments +echo "\n-- Testing ob_clean() function with Zero arguments --\n"; +var_dump( ob_clean() ); + +ob_start(); +echo "You should never see this."; +var_dump(ob_clean()); + +echo "Ensure the buffer is still active after the clean."; +$out = ob_get_clean(); +var_dump($out); + +echo "Done"; +?> +--EXPECTF-- +*** Testing ob_clean() : basic functionality *** + +-- Testing ob_clean() function with Zero arguments -- + +Notice: ob_clean(): failed to delete buffer. No buffer to delete. in %s on line 12 +bool(false) +string(61) "bool(true) +Ensure the buffer is still active after the clean." +Done
\ No newline at end of file diff --git a/tests/output/ob_clean_error_001.phpt b/tests/output/ob_clean_error_001.phpt new file mode 100644 index 000000000..7b74ff8f1 --- /dev/null +++ b/tests/output/ob_clean_error_001.phpt @@ -0,0 +1,27 @@ +--TEST-- +Test ob_clean() function : error conditions +--FILE-- +<?php +/* Prototype : proto bool ob_clean(void) + * Description: Clean (delete) the current output buffer + * Source code: main/output.c + * Alias to functions: + */ + +echo "*** Testing ob_clean() : error conditions ***\n"; + +// One argument +echo "\n-- Testing ob_clean() function with one argument --\n"; +$extra_arg = 10;; +var_dump( ob_clean($extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing ob_clean() : error conditions *** + +-- Testing ob_clean() function with one argument -- + +Warning: Wrong parameter count for ob_clean() in %s on line 13 +NULL +Done
\ No newline at end of file diff --git a/tests/output/ob_end_clean_basic_001.phpt b/tests/output/ob_end_clean_basic_001.phpt new file mode 100644 index 000000000..0b694e36c --- /dev/null +++ b/tests/output/ob_end_clean_basic_001.phpt @@ -0,0 +1,31 @@ +--TEST-- +Test return type and value, as well as basic behaviour, for ob_end_clean() +--FILE-- +<?php +/* + * proto bool ob_end_clean(void) + * Function is implemented in main/output.c +*/ + +var_dump(ob_end_clean()); + +ob_start(); +var_dump(ob_end_clean()); + +ob_start(); +echo "Hello"; +var_dump(ob_end_clean()); + +var_dump(ob_end_clean()); + +?> +--EXPECTF-- + +Notice: ob_end_clean(): failed to delete buffer. No buffer to delete. in %s on line 7 +bool(false) +bool(true) +bool(true) + +Notice: ob_end_clean(): failed to delete buffer. No buffer to delete. in %s on line 16 +bool(false) + diff --git a/tests/output/ob_end_clean_error_001.phpt b/tests/output/ob_end_clean_error_001.phpt new file mode 100644 index 000000000..f7b549e72 --- /dev/null +++ b/tests/output/ob_end_clean_error_001.phpt @@ -0,0 +1,22 @@ +--TEST-- +Test wrong number of arguments for ob_end_clean() +--FILE-- +<?php +/* + * proto bool ob_end_clean(void) + * Function is implemented in main/output.c +*/ + +$extra_arg = 1; + +echo "\nToo many arguments\n"; +var_dump(ob_end_clean($extra_arg)); + + +?> +--EXPECTF-- + +Too many arguments + +Warning: Wrong parameter count for ob_end_clean() in %s on line 10 +NULL diff --git a/tests/output/ob_end_flush_basic_001.phpt b/tests/output/ob_end_flush_basic_001.phpt new file mode 100644 index 000000000..7515face0 --- /dev/null +++ b/tests/output/ob_end_flush_basic_001.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test ob_end_flush() function : basic functionality +--FILE-- +<?php +/* Prototype : proto bool ob_end_flush(void) + * Description: Flush (send) the output buffer, and delete current output buffer + * Source code: main/output.c + * Alias to functions: + */ + +echo "*** Testing ob_end_flush() : basic functionality ***\n"; + +// Zero arguments +echo "\n-- Testing ob_end_flush() function with Zero arguments --\n"; +var_dump(ob_end_flush()); + +ob_start(); +var_dump(ob_end_flush()); + +ob_start(); +echo "Hello\n"; +var_dump(ob_end_flush()); + +var_dump(ob_end_flush()); + +echo "Done"; +?> +--EXPECTF-- +*** Testing ob_end_flush() : basic functionality *** + +-- Testing ob_end_flush() function with Zero arguments -- + +Notice: ob_end_flush(): failed to delete and flush buffer. No buffer to delete or flush. in %s on line 12 +bool(false) +bool(true) +Hello +bool(true) + +Notice: ob_end_flush(): failed to delete and flush buffer. No buffer to delete or flush. in %s on line 21 +bool(false) +Done
\ No newline at end of file diff --git a/tests/output/ob_end_flush_error_001.phpt b/tests/output/ob_end_flush_error_001.phpt new file mode 100644 index 000000000..f9e118a10 --- /dev/null +++ b/tests/output/ob_end_flush_error_001.phpt @@ -0,0 +1,27 @@ +--TEST-- +Test ob_end_flush() function : error conditions +--FILE-- +<?php +/* Prototype : proto bool ob_end_flush(void) + * Description: Flush (send) the output buffer, and delete current output buffer + * Source code: main/output.c + * Alias to functions: + */ + +echo "*** Testing ob_end_flush() : error conditions ***\n"; + +// One argument +echo "\n-- Testing ob_end_flush() function with one argument --\n"; +$extra_arg = 10;; +var_dump( ob_end_flush($extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing ob_end_flush() : error conditions *** + +-- Testing ob_end_flush() function with one argument -- + +Warning: Wrong parameter count for ob_end_flush() in %s on line 13 +NULL +Done diff --git a/tests/output/ob_flush_basic_001.phpt b/tests/output/ob_flush_basic_001.phpt new file mode 100644 index 000000000..91fb69526 --- /dev/null +++ b/tests/output/ob_flush_basic_001.phpt @@ -0,0 +1,39 @@ +--TEST-- +Test ob_flush() function : basic functionality +--FILE-- +<?php +/* Prototype : proto bool ob_flush(void) + * Description: Flush (send) contents of the output buffer. The last buffer content is sent to next buffer + * Source code: main/output.c + * Alias to functions: + */ + +echo "*** Testing ob_flush() : basic functionality ***\n"; + +// Zero arguments +echo "\n-- Testing ob_flush() function with Zero arguments --\n"; +var_dump(ob_flush()); + +ob_start(); +echo "This should get flushed.\n"; +var_dump(ob_flush()); + +echo "Ensure the buffer is still active after the flush.\n"; +$out = ob_flush(); +var_dump($out); + +echo "Done"; + +?> +--EXPECTF-- +*** Testing ob_flush() : basic functionality *** + +-- Testing ob_flush() function with Zero arguments -- + +Notice: ob_flush(): failed to flush buffer. No buffer to flush. in %s on line 12 +bool(false) +This should get flushed. +bool(true) +Ensure the buffer is still active after the flush. +bool(true) +Done
\ No newline at end of file diff --git a/tests/output/ob_flush_error_001.phpt b/tests/output/ob_flush_error_001.phpt new file mode 100644 index 000000000..44f51785e --- /dev/null +++ b/tests/output/ob_flush_error_001.phpt @@ -0,0 +1,27 @@ +--TEST-- +Test ob_flush() function : error conditions +--FILE-- +<?php +/* Prototype : proto bool ob_flush(void) + * Description: Flush (send) contents of the output buffer. The last buffer content is sent to next buffer + * Source code: main/output.c + * Alias to functions: + */ + +echo "*** Testing ob_flush() : error conditions ***\n"; + +// One argument +echo "\n-- Testing ob_flush() function with one argument --\n"; +$extra_arg = 10;; +var_dump( ob_flush($extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing ob_flush() : error conditions *** + +-- Testing ob_flush() function with one argument -- + +Warning: Wrong parameter count for ob_flush() in %s on line 13 +NULL +Done diff --git a/tests/output/ob_get_clean_basic_001.phpt b/tests/output/ob_get_clean_basic_001.phpt new file mode 100644 index 000000000..07673dfac --- /dev/null +++ b/tests/output/ob_get_clean_basic_001.phpt @@ -0,0 +1,18 @@ +--TEST-- +Test return type and value, as well as basic behaviour, of ob_get_clean() +--FILE-- +<?php +/* + * proto bool ob_get_clean(void) + * Function is implemented in main/output.c +*/ + +var_dump(ob_get_clean()); + +ob_start(); +echo "Hello World"; +var_dump(ob_get_clean()); +?> +--EXPECTF-- +bool(false) +string(11) "Hello World"
\ No newline at end of file diff --git a/tests/output/ob_get_clean_basic_002.phpt b/tests/output/ob_get_clean_basic_002.phpt new file mode 100644 index 000000000..a5992734c --- /dev/null +++ b/tests/output/ob_get_clean_basic_002.phpt @@ -0,0 +1,20 @@ +--TEST-- +Test basic behaviour of ob_get_clean() +--FILE-- +<?php +/* + * proto bool ob_get_clean(void) + * Function is implemented in main/output.c +*/ + +ob_start(); + +echo "Hello World"; + +$out = ob_get_clean(); +$out = strtolower($out); + +var_dump($out); +?> +--EXPECT-- +string(11) "hello world"
\ No newline at end of file diff --git a/tests/output/ob_get_clean_error_001.phpt b/tests/output/ob_get_clean_error_001.phpt new file mode 100644 index 000000000..25c775700 --- /dev/null +++ b/tests/output/ob_get_clean_error_001.phpt @@ -0,0 +1,22 @@ +--TEST-- +Test wrong number of arguments for ob_get_clean() +--FILE-- +<?php +/* + * proto bool ob_get_clean(void) + * Function is implemented in main/output.c +*/ + +$extra_arg = 1; + +echo "\nToo many arguments\n"; +var_dump(ob_get_clean($extra_arg)); + + +?> +--EXPECTF-- + +Too many arguments + +Warning: Wrong parameter count for ob_get_clean() in %s on line 10 +NULL
\ No newline at end of file diff --git a/tests/output/ob_get_contents_basic_001.phpt b/tests/output/ob_get_contents_basic_001.phpt new file mode 100644 index 000000000..a99024506 --- /dev/null +++ b/tests/output/ob_get_contents_basic_001.phpt @@ -0,0 +1,73 @@ +--TEST-- +Test ob_get_contents() function : basic functionality +--CREDITS-- +Iain Lewis <ilewis@php.net> +--FILE-- +<?php +/* Prototype : proto string ob_get_contents(void) + * Description: Return the contents of the output buffer + * Source code: main/output.c + * Alias to functions: + */ + + +echo "*** Testing ob_get_contents() : basic functionality ***\n"; + +// Zero arguments +echo "\n-- Testing ob_get_contents() function with Zero arguments --\n"; +/* Buffering not started yet, should return false */ +var_dump( ob_get_contents() ); + +ob_start(); +echo "Hello World\n"; +$hello = ob_get_contents(); +var_dump($hello); +ob_end_flush(); + + +echo "\ncheck that we dont have a reference\n"; +ob_start(); +echo "Hello World\n"; +$hello2 = ob_get_contents(); +$hello2 = "bob"; +var_dump(ob_get_contents()); +ob_end_flush(); + +echo "\ncheck that contents disappear after a flush\n"; +ob_start(); +echo "Hello World\n"; +ob_flush(); +var_dump(ob_get_contents()); +ob_end_flush(); + +echo "\ncheck that no contents found after an end\n"; +ob_start(); +echo "Hello World\n"; +ob_end_flush(); +var_dump(ob_get_contents()); + + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing ob_get_contents() : basic functionality *** + +-- Testing ob_get_contents() function with Zero arguments -- +bool(false) +Hello World +string(12) "Hello World +" + +check that we dont have a reference +Hello World +string(12) "Hello World +" + +check that contents disappear after a flush +Hello World +string(0) "" + +check that no contents found after an end +Hello World +bool(false) +Done
\ No newline at end of file diff --git a/tests/output/ob_get_contents_error_001.phpt b/tests/output/ob_get_contents_error_001.phpt new file mode 100644 index 000000000..10253c37a --- /dev/null +++ b/tests/output/ob_get_contents_error_001.phpt @@ -0,0 +1,32 @@ +--TEST-- +Test ob_get_contents() function : error cases +--CREDITS-- +Iain Lewis <ilewis@php.net> +--FILE-- +<?php +/* Prototype : proto string ob_get_contents(void) + * Description: Return the contents of the output buffer + * Source code: main/output.c + * Alias to functions: + */ + + +echo "*** Testing ob_get_contents() : error cases ***\n"; + +var_dump(ob_get_contents("bob")); + +ob_start(); + +var_dump(ob_get_contents("bob2",345)); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing ob_get_contents() : error cases *** + +Warning: Wrong parameter count for ob_get_contents() in %s on line 11 +NULL + +Warning: Wrong parameter count for ob_get_contents() in %s on line 15 +NULL +Done diff --git a/tests/output/ob_get_length_basic_001.phpt b/tests/output/ob_get_length_basic_001.phpt new file mode 100644 index 000000000..98469c258 --- /dev/null +++ b/tests/output/ob_get_length_basic_001.phpt @@ -0,0 +1,37 @@ +--TEST-- +Test return type and value, as well as basic behaviour, of ob_get_length() +--FILE-- +<?php +/* + * proto int ob_get_length(void) + * Function is implemented in main/output.c +*/ + +echo "No output buffers\n"; +var_dump(ob_get_length()); + +ob_start(); +var_dump(ob_get_length()); +echo "hello\n"; +var_dump(ob_get_length()); +ob_flush(); +$value = ob_get_length(); +echo "hello\n"; +ob_clean(); +var_dump(ob_get_length()); +var_dump($value); +ob_end_flush(); + +echo "No output buffers\n"; +var_dump(ob_get_length()); +?> +--EXPECTF-- +No output buffers +bool(false) +int(0) +hello +int(13) +int(0) +int(0) +No output buffers +bool(false)
\ No newline at end of file diff --git a/tests/output/ob_get_length_error_001.phpt b/tests/output/ob_get_length_error_001.phpt new file mode 100644 index 000000000..8b461a2c1 --- /dev/null +++ b/tests/output/ob_get_length_error_001.phpt @@ -0,0 +1,22 @@ +--TEST-- +Test wrong number of arguments for ob_get_length() +--FILE-- +<?php +/* + * proto int ob_get_length(void) + * Function is implemented in main/output.c +*/ + +$extra_arg = 1; + +echo "\nToo many arguments\n"; +var_dump(ob_get_length($extra_arg)); + + +?> +--EXPECTF-- + +Too many arguments + +Warning: Wrong parameter count for ob_get_length() in %s on line 10 +NULL
\ No newline at end of file diff --git a/tests/output/ob_get_level_basic_001.phpt b/tests/output/ob_get_level_basic_001.phpt new file mode 100644 index 000000000..78217e4a4 --- /dev/null +++ b/tests/output/ob_get_level_basic_001.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test ob_get_level() function : basic functionality +--FILE-- +<?php +/* Prototype : proto int ob_get_level(void) + * Description: Return the nesting level of the output buffer + * Source code: main/output.c + * Alias to functions: + */ + +echo "*** Testing ob_get_level() : basic functionality ***\n"; + +// Zero arguments +echo "\n-- Testing ob_get_level() function with Zero arguments --\n"; +var_dump(ob_get_level()); + +ob_start(); +var_dump(ob_get_level()); + +ob_start(); +var_dump(ob_get_level()); + +ob_end_flush(); +var_dump(ob_get_level()); + +ob_end_flush(); +var_dump(ob_get_level()); + +ob_end_flush(); +var_dump(ob_get_level()); + + +echo "Done"; +?> +--EXPECTF-- +*** Testing ob_get_level() : basic functionality *** + +-- Testing ob_get_level() function with Zero arguments -- +int(0) +int(1) +int(2) +int(1) +int(0) + +Notice: ob_end_flush(): failed to delete and flush buffer. No buffer to delete or flush. in %s on line 26 +int(0) +Done
\ No newline at end of file diff --git a/tests/output/ob_get_level_error_001.phpt b/tests/output/ob_get_level_error_001.phpt new file mode 100644 index 000000000..5f3e4e7ed --- /dev/null +++ b/tests/output/ob_get_level_error_001.phpt @@ -0,0 +1,27 @@ +--TEST-- +Test ob_get_level() function : error conditions +--FILE-- +<?php +/* Prototype : proto int ob_get_level(void) + * Description: Return the nesting level of the output buffer + * Source code: main/output.c + * Alias to functions: + */ + +echo "*** Testing ob_get_level() : error conditions ***\n"; + +// One argument +echo "\n-- Testing ob_get_level() function with one argument --\n"; +$extra_arg = 10;; +var_dump( ob_get_level($extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing ob_get_level() : error conditions *** + +-- Testing ob_get_level() function with one argument -- + +Warning: Wrong parameter count for ob_get_level() in %s on line 13 +NULL +Done
\ No newline at end of file diff --git a/tests/output/ob_implicit_flush_basic_001.phpt b/tests/output/ob_implicit_flush_basic_001.phpt new file mode 100644 index 000000000..ab6f6a7a6 --- /dev/null +++ b/tests/output/ob_implicit_flush_basic_001.phpt @@ -0,0 +1,24 @@ +--TEST-- +Test ob_implicit_flush() function : check return value (always null). +--FILE-- +<?php +/* Prototype : proto void ob_implicit_flush([int flag]) + * Description: Turn implicit flush on/off and is equivalent to calling flush() after every output call + * Source code: main/output.c + * Alias to functions: + */ + +echo "*** Testing ob_implicit_flush() : check return value ***\n"; + +var_dump(ob_implicit_flush()); +var_dump(ob_implicit_flush(true)); +var_dump(ob_implicit_flush(false)); + +echo "Done"; +?> +--EXPECTF-- +*** Testing ob_implicit_flush() : check return value *** +NULL +NULL +NULL +Done diff --git a/tests/output/ob_implicit_flush_basic_002.phpt b/tests/output/ob_implicit_flush_basic_002.phpt new file mode 100644 index 000000000..6b378a7f1 --- /dev/null +++ b/tests/output/ob_implicit_flush_basic_002.phpt @@ -0,0 +1,29 @@ +--TEST-- +Test ob_implicit_flush() function : ensure implicit flushing does not apply to user buffers. +--FILE-- +<?php +/* Prototype : proto void ob_implicit_flush([int flag]) + * Description: Turn implicit flush on/off and is equivalent to calling flush() after every output call + * Source code: main/output.c + * Alias to functions: + */ + +echo "*** Testing ob_implicit_flush() : ensure implicit flushing does not apply to user buffers. ***\n"; + +// Start a user buffer +ob_start(); +// Switch on implicit flushing. +ob_implicit_flush(1); + +echo "This is being written to a user buffer.\n"; +echo "Note that even though implicit flushing is on, you should never see this,\n"; +echo "because implicit flushing affects only the top level buffer, not user buffers.\n"; + +// Wipe the user buffer. Nothing should have been flushed. +ob_end_clean(); + +echo "Done"; +?> +--EXPECTF-- +*** Testing ob_implicit_flush() : ensure implicit flushing does not apply to user buffers. *** +Done
\ No newline at end of file diff --git a/tests/output/ob_implicit_flush_error_001.phpt b/tests/output/ob_implicit_flush_error_001.phpt new file mode 100644 index 000000000..d4d14c6fb --- /dev/null +++ b/tests/output/ob_implicit_flush_error_001.phpt @@ -0,0 +1,29 @@ +--TEST-- +Test ob_implicit_flush() function : wrong number of arguments +--FILE-- +<?php +/* Prototype : proto void ob_implicit_flush([int flag]) + * Description: Turn implicit flush on/off and is equivalent to calling flush() after every output call + * Source code: main/output.c + * Alias to functions: + */ + +echo "*** Testing ob_implicit_flush() : error conditions ***\n"; + + +//Test ob_implicit_flush with one more than the expected number of arguments +echo "\n-- Testing ob_implicit_flush() function with more than expected no. of arguments --\n"; +$flag = 10; +$extra_arg = 10; +var_dump( ob_implicit_flush($flag, $extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing ob_implicit_flush() : error conditions *** + +-- Testing ob_implicit_flush() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for ob_implicit_flush() in %s on line 15 +NULL +Done
\ No newline at end of file diff --git a/tests/output/ob_implicit_flush_variation_001.phpt b/tests/output/ob_implicit_flush_variation_001.phpt new file mode 100644 index 000000000..e10bd493e --- /dev/null +++ b/tests/output/ob_implicit_flush_variation_001.phpt @@ -0,0 +1,182 @@ +--TEST-- +Test ob_implicit_flush() function : usage variation +--FILE-- +<?php +/* Prototype : void ob_implicit_flush([int flag]) + * Description: Turn implicit flush on/off and is equivalent to calling flush() after every output call + * Source code: main/output.c + * Alias to functions: + */ + +echo "*** Testing ob_implicit_flush() : usage variation ***\n"; + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + +// Initialise function arguments not being substituted (if any) + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for flag + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( ob_implicit_flush($value) ); +}; + +?> +--EXPECTF-- +*** Testing ob_implicit_flush() : usage variation *** + +--float 10.5-- +NULL + +--float -10.5-- +NULL + +--float 12.3456789000e10-- +NULL + +--float -12.3456789000e10-- +NULL + +--float .5-- +NULL + +--empty array-- +NULL + +--int indexed array-- +NULL + +--associative array-- +NULL + +--nested arrays-- +NULL + +--uppercase NULL-- +NULL + +--lowercase null-- +NULL + +--lowercase true-- +NULL + +--lowercase false-- +NULL + +--uppercase TRUE-- +NULL + +--uppercase FALSE-- +NULL + +--empty string DQ-- +NULL + +--empty string SQ-- +NULL + +--string DQ-- +NULL + +--string SQ-- +NULL + +--mixed case string-- +NULL + +--heredoc-- +NULL + +--instance of classWithToString-- +Error: 8 - Object of class classWithToString could not be converted to int, %s(97) +NULL + +--instance of classWithoutToString-- +Error: 8 - Object of class classWithoutToString could not be converted to int, %s(97) +NULL + +--undefined var-- +NULL + +--unset var-- +NULL
\ No newline at end of file diff --git a/tests/output/ob_start_basic_001.phpt b/tests/output/ob_start_basic_001.phpt new file mode 100644 index 000000000..d93a7313b --- /dev/null +++ b/tests/output/ob_start_basic_001.phpt @@ -0,0 +1,14 @@ +--TEST-- +Test return type and value for ob_start() +--FILE-- +<?php +/* + * proto bool ob_start([ string|array user_function [, int chunk_size [, bool erase]]]) + * Function is implemented in main/output.c +*/ + +var_dump(ob_start()); + +?> +--EXPECT-- +bool(true)
\ No newline at end of file diff --git a/tests/output/ob_start_basic_002.phpt b/tests/output/ob_start_basic_002.phpt new file mode 100644 index 000000000..92d9069f3 --- /dev/null +++ b/tests/output/ob_start_basic_002.phpt @@ -0,0 +1,55 @@ +--TEST-- +ob_start(): Check behaviour with various callback return values. +--FILE-- +<?php +function return_empty_string($string) { + return ""; +} + +function return_false($string) { + return false; +} + +function return_null($string) { + return null; +} + +function return_string($string) { + return "I stole your output."; +} + +function return_zero($string) { + return 0; +} + +// Use each of the above functions as an output buffering callback: +$functions = get_defined_functions(); +$callbacks = $functions['user']; +sort($callbacks); +foreach ($callbacks as $callback) { + echo "--> Use callback '$callback':\n"; + ob_start($callback); + echo 'My output.'; + ob_end_flush(); + echo "\n\n"; +} + +?> +==DONE== +--EXPECTF-- +--> Use callback 'return_empty_string': + + +--> Use callback 'return_false': +My output. + +--> Use callback 'return_null': + + +--> Use callback 'return_string': +I stole your output. + +--> Use callback 'return_zero': +0 + +==DONE==
\ No newline at end of file diff --git a/tests/output/ob_start_basic_003.phpt b/tests/output/ob_start_basic_003.phpt new file mode 100644 index 000000000..ebd883af7 --- /dev/null +++ b/tests/output/ob_start_basic_003.phpt @@ -0,0 +1,18 @@ +--TEST-- +ob_start(): ensure even fatal error test is affected by output buffering. +--FILE-- +<?php + +function f() { + return "I have stolen your output"; +} + +ob_start('f'); +cause_fatal_error(); // call undefined function +ob_end_flush(); + +echo "done (you shouldn't see this)"; + +?> +--EXPECTF-- +I have stolen your output
\ No newline at end of file diff --git a/tests/output/ob_start_basic_004.phpt b/tests/output/ob_start_basic_004.phpt new file mode 100644 index 000000000..39d3aadc4 --- /dev/null +++ b/tests/output/ob_start_basic_004.phpt @@ -0,0 +1,122 @@ +--TEST-- +ob_start() chunk_size: confirm buffer is flushed after any output call that causes its length to equal or exceed chunk_size. +--FILE-- +<?php +/* + * proto bool ob_start([ string|array user_function [, int chunk_size [, bool erase]]]) + * Function is implemented in main/output.c +*/ + +function callback($string) { + global $callback_invocations; + $callback_invocations++; + $len = strlen($string); + return "f[call:$callback_invocations; len:$len]$string\n"; +} + +for ($cs=-1; $cs<10; $cs++) { + echo "\n----( chunk_size: $cs, output append size: 1 )----\n"; + $callback_invocations=0; + ob_start('callback', $cs); + echo '1'; echo '2'; echo '3'; echo '4'; echo '5'; echo '6'; echo '7'; echo '8'; + ob_end_flush(); +} + +for ($cs=-1; $cs<10; $cs++) { + echo "\n----( chunk_size: $cs, output append size: 4 )----\n"; + $callback_invocations=0; + ob_start('callback', $cs); + echo '1234'; echo '5678'; + ob_end_flush(); +} + +?> +--EXPECTF-- + +----( chunk_size: -1, output append size: 1 )---- +f[call:1; len:8]12345678 + +----( chunk_size: 0, output append size: 1 )---- +f[call:1; len:8]12345678 + +----( chunk_size: 1, output append size: 1 )---- +f[call:1; len:8]12345678 + +----( chunk_size: 2, output append size: 1 )---- +f[call:1; len:2]12 +f[call:2; len:2]34 +f[call:3; len:2]56 +f[call:4; len:2]78 +f[call:5; len:0] + +----( chunk_size: 3, output append size: 1 )---- +f[call:1; len:3]123 +f[call:2; len:3]456 +f[call:3; len:2]78 + +----( chunk_size: 4, output append size: 1 )---- +f[call:1; len:4]1234 +f[call:2; len:4]5678 +f[call:3; len:0] + +----( chunk_size: 5, output append size: 1 )---- +f[call:1; len:5]12345 +f[call:2; len:3]678 + +----( chunk_size: 6, output append size: 1 )---- +f[call:1; len:6]123456 +f[call:2; len:2]78 + +----( chunk_size: 7, output append size: 1 )---- +f[call:1; len:7]1234567 +f[call:2; len:1]8 + +----( chunk_size: 8, output append size: 1 )---- +f[call:1; len:8]12345678 +f[call:2; len:0] + +----( chunk_size: 9, output append size: 1 )---- +f[call:1; len:8]12345678 + +----( chunk_size: -1, output append size: 4 )---- +f[call:1; len:8]12345678 + +----( chunk_size: 0, output append size: 4 )---- +f[call:1; len:8]12345678 + +----( chunk_size: 1, output append size: 4 )---- +f[call:1; len:8]12345678 + +----( chunk_size: 2, output append size: 4 )---- +f[call:1; len:4]1234 +f[call:2; len:4]5678 +f[call:3; len:0] + +----( chunk_size: 3, output append size: 4 )---- +f[call:1; len:4]1234 +f[call:2; len:4]5678 +f[call:3; len:0] + +----( chunk_size: 4, output append size: 4 )---- +f[call:1; len:4]1234 +f[call:2; len:4]5678 +f[call:3; len:0] + +----( chunk_size: 5, output append size: 4 )---- +f[call:1; len:8]12345678 +f[call:2; len:0] + +----( chunk_size: 6, output append size: 4 )---- +f[call:1; len:8]12345678 +f[call:2; len:0] + +----( chunk_size: 7, output append size: 4 )---- +f[call:1; len:8]12345678 +f[call:2; len:0] + +----( chunk_size: 8, output append size: 4 )---- +f[call:1; len:8]12345678 +f[call:2; len:0] + +----( chunk_size: 9, output append size: 4 )---- +f[call:1; len:8]12345678
\ No newline at end of file diff --git a/tests/output/ob_start_basic_005.phpt b/tests/output/ob_start_basic_005.phpt new file mode 100644 index 000000000..e44950308 --- /dev/null +++ b/tests/output/ob_start_basic_005.phpt @@ -0,0 +1,31 @@ +--TEST-- +ob_start(): don't allow non-static functions as static callbacks. +--FILE-- +<?php +/* + * proto bool ob_start([ string|array user_function [, int chunk_size [, bool erase]]]) + * Function is implemented in main/output.c +*/ + +Class C { + function h($string) { + return $string; + } +} + +function checkAndClean() { + print_r(ob_list_handlers()); + while (ob_get_level()>0) { + ob_end_flush(); + } +} + +var_dump(ob_start('C::h')); +checkAndClean(); + +?> +--EXPECT-- +bool(false) +Array +( +)
\ No newline at end of file diff --git a/tests/output/ob_start_basic_006.phpt b/tests/output/ob_start_basic_006.phpt new file mode 100644 index 000000000..e24ebd61c --- /dev/null +++ b/tests/output/ob_start_basic_006.phpt @@ -0,0 +1,134 @@ +--TEST-- +ob_start(): multiple buffer initialization with a single call, using arrays. +--FILE-- +<?php +/* + * proto bool ob_start([ string|array user_function [, int chunk_size [, bool erase]]]) + * Function is implemented in main/output.c +*/ + +function f($string) { + static $i=0; + $i++; + $len = strlen($string); + return "f[call:$i; len:$len] - $string\n"; +} + +Class C { + public $id = 'none'; + + function __construct($id) { + $this->id = $id; + } + + static function g($string) { + static $i=0; + $i++; + $len = strlen($string); + return "C::g[call:$i; len:$len] - $string\n"; + } + + function h($string) { + static $i=0; + $i++; + $len = strlen($string); + return "C::h[call:$i; len:$len; id:$this->id] - $string\n"; + } +} + +function checkAndClean() { + print_r(ob_list_handlers()); + while (ob_get_level()>0) { + ob_end_flush(); + } +} + +echo "\n ---> Test arrays: \n"; +var_dump(ob_start(array("f"))); +checkAndClean(); + +var_dump(ob_start(array("f", "f"))); +checkAndClean(); + +var_dump(ob_start(array("f", "C::g", "f", "C::g"))); +checkAndClean(); + +var_dump(ob_start(array("f", "non_existent", "f"))); +checkAndClean(); + +var_dump(ob_start(array("f", "non_existent", "f", "f"))); +checkAndClean(); + +$c = new c('originalID'); +var_dump(ob_start(array($c, "h"))); +checkAndClean(); + +var_dump(ob_start(array($c, "h"))); +$c->id = 'changedID'; +checkAndClean(); + +$c->id = 'changedIDagain'; +var_dump(ob_start(array('f', 'C::g', array(array($c, "g"), array($c, "h"))))); +checkAndClean(); +?> +--EXPECTF-- + + ---> Test arrays: +f[call:1; len:34] - bool(true) +Array +( + [0] => f +) + +f[call:3; len:68] - f[call:2; len:47] - bool(true) +Array +( + [0] => f + [1] => f +) + + +f[call:5; len:150] - C::g[call:2; len:125] - f[call:4; len:103] - C::g[call:1; len:79] - bool(true) +Array +( + [0] => f + [1] => C::g + [2] => f + [3] => C::g +) + + + + +f[call:6; len:35] - bool(false) +Array +( + [0] => f +) + +f[call:7; len:35] - bool(false) +Array +( + [0] => f +) + +C::h[call:1; len:37; id:originalID] - bool(true) +Array +( + [0] => C::h +) + +C::h[call:2; len:37; id:changedID] - bool(true) +Array +( + [0] => C::h +) + +f[call:8; len:175] - C::g[call:4; len:150] - C::g[call:3; len:125] - C::h[call:3; len:82; id:changedIDagain] - bool(true) +Array +( + [0] => f + [1] => C::g + [2] => C::g + [3] => C::h +)
\ No newline at end of file diff --git a/tests/output/ob_start_basic_unerasable_001.phpt b/tests/output/ob_start_basic_unerasable_001.phpt new file mode 100644 index 000000000..8e7280edd --- /dev/null +++ b/tests/output/ob_start_basic_unerasable_001.phpt @@ -0,0 +1,22 @@ +--TEST-- +ob_start(): Ensure content of unerasable buffer can be accessed by ob_get_contents(). +--FILE-- +<?php +function callback($string) { + static $callback_invocations; + $callback_invocations++; + return "[callback:$callback_invocations]$string\n"; +} + +ob_start('callback', 0, false); + +echo "This call will obtain the content:\n"; +$str = ob_get_contents(); +var_dump($str); +?> +==DONE== +--EXPECTF-- +[callback:1]This call will obtain the content: +string(35) "This call will obtain the content: +" +==DONE==
\ No newline at end of file diff --git a/tests/output/ob_start_basic_unerasable_002.phpt b/tests/output/ob_start_basic_unerasable_002.phpt new file mode 100644 index 000000000..2ffcbb9dc --- /dev/null +++ b/tests/output/ob_start_basic_unerasable_002.phpt @@ -0,0 +1,33 @@ +--TEST-- +ob_start(): Ensure unerasable buffer cannot be erased by ob_clean(), ob_end_clean() or ob_end_flush(). +--FILE-- +<?php +function callback($string) { + static $callback_invocations; + $callback_invocations++; + return "[callback:$callback_invocations]$string\n"; +} + +ob_start('callback', 0, false); + +echo "All of the following calls will fail to clean/remove the topmost buffer:\n"; +var_dump(ob_clean()); +var_dump(ob_end_clean()); +var_dump(ob_end_flush()); + +echo "The OB nesting will still be 1 level deep:\n"; +var_dump(ob_get_level()); +?> +--EXPECTF-- +[callback:1]All of the following calls will fail to clean/remove the topmost buffer: + +Notice: ob_clean(): failed to delete buffer callback. in %s on line 11 +bool(false) + +Notice: ob_end_clean(): failed to delete buffer callback. in %s on line 12 +bool(false) + +Notice: ob_end_flush(): failed to delete buffer callback. in %s on line 13 +bool(false) +The OB nesting will still be 1 level deep: +int(1)
\ No newline at end of file diff --git a/tests/output/ob_start_basic_unerasable_003.phpt b/tests/output/ob_start_basic_unerasable_003.phpt new file mode 100644 index 000000000..d20141453 --- /dev/null +++ b/tests/output/ob_start_basic_unerasable_003.phpt @@ -0,0 +1,21 @@ +--TEST-- +ob_start(): Ensure unerasable buffer cannot be accessed or erased by ob_get_clean(). +--FILE-- +<?php +function callback($string) { + static $callback_invocations; + $callback_invocations++; + return "[callback:$callback_invocations]$string\n"; +} + +ob_start('callback', 0, false); + +echo "This call will fail to obtain the content, since it is also requesting a clean:\n"; +$str = ob_get_clean(); +var_dump($str); +?> +--EXPECTF-- +[callback:1]This call will fail to obtain the content, since it is also requesting a clean: + +Notice: ob_get_clean(): failed to delete buffer callback. in %s on line 11 +bool(false)
\ No newline at end of file diff --git a/tests/output/ob_start_basic_unerasable_004.phpt b/tests/output/ob_start_basic_unerasable_004.phpt new file mode 100644 index 000000000..88fdda5b3 --- /dev/null +++ b/tests/output/ob_start_basic_unerasable_004.phpt @@ -0,0 +1,21 @@ +--TEST-- +ob_start(): Ensure unerasable buffer cannot be accessed or flushed by ob_get_flush(). +--FILE-- +<?php +function callback($string) { + static $callback_invocations; + $callback_invocations++; + return "[callback:$callback_invocations]$string\n"; +} + +ob_start('callback', 0, false); + +echo "This call will fail to flush and fail to obtain the content:\n"; +$str = ob_get_flush(); +var_dump($str); +?> +--EXPECTF-- +[callback:1]This call will fail to flush and fail to obtain the content: + +Notice: ob_get_flush(): failed to delete buffer callback. in %s on line 11 +bool(false)
\ No newline at end of file diff --git a/tests/output/ob_start_basic_unerasable_005.phpt b/tests/output/ob_start_basic_unerasable_005.phpt new file mode 100644 index 000000000..48d611c9c --- /dev/null +++ b/tests/output/ob_start_basic_unerasable_005.phpt @@ -0,0 +1,27 @@ +--TEST-- +ob_start(): Ensure unerasable buffer cannot be flushed by ob_flush(). +--XFAIL-- +On PHP5, ob_flush() DOES clear the buffer. See bug: 46897 +--FILE-- +<?php +function callback($string) { + static $callback_invocations; + $callback_invocations++; + return "[callback:$callback_invocations]$string\n"; +} + +ob_start('callback', 0, false); + +echo "Attempt to flush unerasable buffer - should fail... "; +var_dump(ob_flush()); +// Check content of buffer after flush - if flush failed it should still contain the string above. +var_dump(ob_get_contents()); +?> +--EXPECTF-- +[callback:1]Attempt to flush unerasable buffer - should fail... +Notice: ob_flush(): failed to flush buffer callback in %s on line 11 +bool(false) +string(%d) "Attempt to flush unerasable buffer - should fail... +Notice: ob_flush(): failed to flush buffer callback in %s on line 11 +bool(false) +"
\ No newline at end of file diff --git a/tests/output/ob_start_error_001.phpt b/tests/output/ob_start_error_001.phpt new file mode 100644 index 000000000..b1a52e321 --- /dev/null +++ b/tests/output/ob_start_error_001.phpt @@ -0,0 +1,48 @@ +--TEST-- +Test wrong number of arguments and wrong arg types for ob_start() +--FILE-- +<?php +/* + * proto bool ob_start([ string|array user_function [, int chunk_size [, bool erase]]]) + * Function is implemented in main/output.c +*/ + +function justPrint($str) { + return $str; +} + +$arg_1 = "justPrint"; +$arg_2 = 0; +$arg_3 = false; +$extra_arg = 1; + +echo "\n- Too many arguments\n"; +var_dump(ob_start($arg_1, $arg_2, $arg_3, $extra_arg)); + +echo "\n- Arg 1 wrong type\n"; +var_dump(ob_start(1.5)); + +echo "\n- Arg 2 wrong type\n"; +var_dump(ob_start("justPrint", "this should be an int")); + +echo "\n- Arg 3 wrong type\n"; +var_dump(ob_start("justPrint", 0, "this should be a bool")); + +?> +--EXPECTF-- + +- Too many arguments + +Warning: ob_start() expects at most 3 parameters, 4 given in %s on line 17 +bool(false) + +- Arg 1 wrong type +bool(true) + +- Arg 2 wrong type + +Warning: ob_start() expects parameter 2 to be long, string given in %s on line 23 +bool(false) + +- Arg 3 wrong type +bool(true)
\ No newline at end of file diff --git a/tests/output/ob_start_error_002.phpt b/tests/output/ob_start_error_002.phpt new file mode 100644 index 000000000..aca2ad9d2 --- /dev/null +++ b/tests/output/ob_start_error_002.phpt @@ -0,0 +1,27 @@ +--TEST-- +Test wrong number of arguments and wrong arg types for ob_start() +--FILE-- +<?php +/* + * proto bool ob_start([ string|array user_function [, int chunk_size [, bool erase]]]) + * Function is implemented in main/output.c +*/ + +Class C { + static function f($str) { + return $str; + } +} + +var_dump(ob_start(array("nonExistent","f"))); +var_dump(ob_start(array("C","nonExistent"))); +var_dump(ob_start("C::no")); +var_dump(ob_start("no")); +echo "done" +?> +--EXPECTF-- +bool(false) +bool(false) +bool(false) +bool(false) +done
\ No newline at end of file diff --git a/tests/output/ob_start_error_003.phpt b/tests/output/ob_start_error_003.phpt new file mode 100644 index 000000000..d26e38b9d --- /dev/null +++ b/tests/output/ob_start_error_003.phpt @@ -0,0 +1,18 @@ +--TEST-- +Test ob_start() with object supplied but no method. +--FILE-- +<?php +/* + * proto bool ob_start([ string|array user_function [, int chunk_size [, bool erase]]]) + * Function is implemented in main/output.c +*/ + +Class C { +} + +$c = new C; +var_dump(ob_start(array($c))); +echo "done" +?> +--EXPECTF-- +Fatal error: ob_start(): No method name given: use ob_start(array($object,'method')) to specify instance $object and the name of a method of class C to use as output handler in %s on line 11
\ No newline at end of file diff --git a/tests/output/ob_start_error_004.phpt b/tests/output/ob_start_error_004.phpt new file mode 100644 index 000000000..274247602 --- /dev/null +++ b/tests/output/ob_start_error_004.phpt @@ -0,0 +1,18 @@ +--TEST-- +Test ob_start() with non existent callback method. +--FILE-- +<?php +/* + * proto bool ob_start([ string|array user_function [, int chunk_size [, bool erase]]]) + * Function is implemented in main/output.c +*/ + +Class C { +} + +$c = new C; +var_dump(ob_start(array($c, 'f'))); +echo "done" +?> +--EXPECTF-- +Fatal error: ob_start(): No method name given: use ob_start(array($object,'method')) to specify instance $object and the name of a method of class C to use as output handler in %s on line 11
\ No newline at end of file diff --git a/tests/output/ob_start_error_005.phpt b/tests/output/ob_start_error_005.phpt new file mode 100644 index 000000000..3e503c635 --- /dev/null +++ b/tests/output/ob_start_error_005.phpt @@ -0,0 +1,23 @@ +--TEST-- +ob_start(): ensure buffers can't be added from within callback. +--FILE-- +<?php + +/* + * proto bool ob_start([ string|array user_function [, int chunk_size [, bool erase]]]) + * Function is implemented in main/output.c +*/ + +function f($str) { + ob_start(); + echo "hello"; + ob_end_flush(); + return $str; +} + + +var_dump(ob_start('f')); +echo "done"; +?> +--EXPECTF-- +Fatal error: ob_start(): Cannot use output buffering in output buffering display handlers in %s on line 9
\ No newline at end of file diff --git a/tests/security/magic_quotes_gpc.phpt b/tests/security/magic_quotes_gpc.phpt new file mode 100644 index 000000000..eb5b84242 --- /dev/null +++ b/tests/security/magic_quotes_gpc.phpt @@ -0,0 +1,12 @@ +--TEST-- +Test if magic_quotes_gpc works as expected +--INI-- +magic_quotes_gpc=1 +--GET-- +a=abc'"%00123 +--FILE-- +<?php +echo $_GET['a'],"\n"; +?> +--EXPECT-- +abc\'\"\0123 diff --git a/tests/security/open_basedir.inc b/tests/security/open_basedir.inc new file mode 100644 index 000000000..c5de8ca11 --- /dev/null +++ b/tests/security/open_basedir.inc @@ -0,0 +1,139 @@ +<?php + +// This file contains helper functions for testing open_basedir configuration +// Care must be taken with where the directories are created because different +// SAPIs set the working directory differently. So simply creating a directory +// relative to the current working directory like this: mkdir("blah") might +// actually create it in several different places depending on the SAPI..! +// +// Note also depending on the version of php being tested, so the open_basedir +// configuration may or may not be changeable from a script (PHP_INI_SYSTEM). +// +// For this reason we set the open_basedir to . (current directory) and then +// move around to various directories for testing using chdir(). This is NOT +// recommended for production use as . bypasses all semblence of security..! +// +// Although safe mode has been removed in php 6.0, open_basedir is still valid. +// See http://www.php.net/features.safe-mode for more information + +function recursive_delete_directory($directory) { + + // Remove any trailing slash first + if (substr($directory, -1) == '/') { + $directory = substr($directory, 0, -1); + } + + // Make sure the directory is valid + if (is_dir($directory) == FALSE) { + return FALSE; + } + + // Check we can access the directory + if (is_readable($directory) == FALSE) { + return FALSE; + } + + $handle = opendir($directory); + + // Scan through the directory contents + while (FALSE !== ($item = readdir($handle))) { + if ($item != '.') { + if ($item != '..') { + $path = ($directory.'/'.$item); + if (is_dir($path) == TRUE) { + recursive_delete_directory($path); + } else { + @chmod($path, 0777); + unlink($path); + } + } + } + } + + closedir($handle); + @chmod($directory, 0777); + rmdir($directory); + + return TRUE; +} + +function create_directories() { + delete_directories(); + $directory = getcwd(); + + var_dump(mkdir($directory."/test")); + var_dump(mkdir($directory."/test/ok")); + var_dump(mkdir($directory."/test/bad")); + file_put_contents($directory."/test/ok/ok.txt", "Hello World!"); + file_put_contents($directory."/test/bad/bad.txt", "Hello World!"); +} + +function delete_directories() { + $directory = (getcwd()."/test"); + recursive_delete_directory($directory); +} + +function test_open_basedir_error($function) { + global $savedDirectory; + var_dump($function("../bad")); + var_dump($function("../bad/bad.txt")); + var_dump($function("..")); + var_dump($function("../")); + var_dump($function("/")); + var_dump($function("../bad/.")); + $directory = $savedDirectory; + var_dump($function($directory."/test/bad/bad.txt")); + var_dump($function($directory."/test/bad/../bad/bad.txt")); +} + +function test_open_basedir_before($function, $change = TRUE) { + global $savedDirectory; + echo "*** Testing open_basedir configuration [$function] ***\n"; + $directory = getcwd(); + $savedDirectory = $directory; + var_dump(chdir($directory)); + create_directories(); + + // Optionally change directory + if ($change == TRUE) { + var_dump(chdir($directory."/test/ok")); + } +} + +// Delete directories using a --CLEAN-- section! +function test_open_basedir_after($function) { + echo "*** Finished testing open_basedir configuration [$function] ***\n"; +} + +// This is used by functions that return an array on success +function test_open_basedir_array($function) { + global $savedDirectory; + + test_open_basedir_before($function); + test_open_basedir_error($function); + var_dump(is_array($function("./../."))); + var_dump(is_array($function("../ok"))); + var_dump(is_array($function("ok.txt"))); + var_dump(is_array($function("../ok/ok.txt"))); + $directory = $savedDirectory; + var_dump(is_array($function($directory."/test/ok/ok.txt"))); + var_dump(is_array($function($directory."/test/ok/../ok/ok.txt"))); + test_open_basedir_after($function); +} + +function test_open_basedir($function) { + global $savedDirectory; + test_open_basedir_before($function); + test_open_basedir_error($function); + var_dump($function("./../.")); + var_dump($function("../ok")); + var_dump($function("ok.txt")); + var_dump($function("../ok/ok.txt")); + $directory = $savedDirectory; + var_dump($function($directory."/test/ok/ok.txt")); + var_dump($function($directory."/test/ok/../ok/ok.txt")); + test_open_basedir_after($function); +} + +?> + diff --git a/tests/security/open_basedir_chdir.phpt b/tests/security/open_basedir_chdir.phpt new file mode 100644 index 000000000..aa8cef52d --- /dev/null +++ b/tests/security/open_basedir_chdir.phpt @@ -0,0 +1,50 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_before("chdir"); + +var_dump(chdir("../bad")); +var_dump(chdir("..")); +var_dump(chdir("../")); +var_dump(chdir("/")); +var_dump(chdir("../bad/.")); +var_dump(chdir("./../.")); + +test_open_basedir_after("chdir"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [chdir] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: chdir(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: chdir(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: chdir(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: chdir(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: chdir(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: chdir(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +*** Finished testing open_basedir configuration [chdir] *** + diff --git a/tests/security/open_basedir_chmod.phpt b/tests/security/open_basedir_chmod.phpt new file mode 100644 index 000000000..7256d6ed7 --- /dev/null +++ b/tests/security/open_basedir_chmod.phpt @@ -0,0 +1,72 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +$initdir = getcwd(); + +test_open_basedir_before("chmod"); + +var_dump(chmod("../bad", 0600)); +var_dump(chmod("../bad/bad.txt", 0600)); +var_dump(chmod("..", 0600)); +var_dump(chmod("../", 0600)); +var_dump(chmod("/", 0600)); +var_dump(chmod("../bad/.", 0600)); +var_dump(chmod("../bad/./bad.txt", 0600)); +var_dump(chmod("./../.", 0600)); + +var_dump(chmod($initdir."/test/ok/ok.txt", 0600)); +var_dump(chmod("./ok.txt", 0600)); +var_dump(chmod("ok.txt", 0600)); +var_dump(chmod("../ok/ok.txt", 0600)); +var_dump(chmod("../ok/./ok.txt", 0600)); +chmod($initdir."/test/ok/ok.txt", 0777); + +test_open_basedir_after("chmod"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [chmod] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: chmod(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: chmod(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: chmod(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: chmod(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: chmod(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: chmod(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: chmod(): open_basedir restriction in effect. File(../bad/./bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: chmod(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +*** Finished testing open_basedir configuration [chmod] *** + diff --git a/tests/security/open_basedir_copy.phpt b/tests/security/open_basedir_copy.phpt new file mode 100644 index 000000000..7cb902add --- /dev/null +++ b/tests/security/open_basedir_copy.phpt @@ -0,0 +1,78 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_before("copy"); + +var_dump(copy("ok.txt", "../bad")); +var_dump(copy("ok.txt", "../bad/bad.txt")); +var_dump(copy("ok.txt", "..")); +var_dump(copy("ok.txt", "../")); +var_dump(copy("ok.txt", "/")); +var_dump(copy("ok.txt", "../bad/.")); +var_dump(copy("ok.txt", "../bad/./bad.txt")); +var_dump(copy("ok.txt", "./../.")); + +var_dump(copy("ok.txt", "copy.txt")); +var_dump(unlink("copy.txt")); +test_open_basedir_after("copy"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [copy] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: copy(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d + +Warning: copy(../bad): failed to open stream: %s in %s on line %d +bool(false) + +Warning: copy(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: copy(../bad/bad.txt): failed to open stream: %s in %s on line %d +bool(false) + +Warning: copy(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d + +Warning: copy(..): failed to open stream: %s in %s on line %d +bool(false) + +Warning: copy(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d + +Warning: copy(../): failed to open stream: %s in %s on line %d +bool(false) + +Warning: copy(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d + +Warning: copy(/): failed to open stream: %s in %s on line %d +bool(false) + +Warning: copy(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d + +Warning: copy(../bad/.): failed to open stream: %s in %s on line %d +bool(false) + +Warning: copy(): open_basedir restriction in effect. File(../bad/./bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: copy(../bad/./bad.txt): failed to open stream: %s in %s on line %d +bool(false) + +Warning: copy(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d + +Warning: copy(./../.): failed to open stream: %s in %s on line %d +bool(false) +bool(true) +bool(true) +*** Finished testing open_basedir configuration [copy] *** + diff --git a/tests/security/open_basedir_copy_variation1.phpt b/tests/security/open_basedir_copy_variation1.phpt new file mode 100644 index 000000000..899b31da2 --- /dev/null +++ b/tests/security/open_basedir_copy_variation1.phpt @@ -0,0 +1,34 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_before("copy"); + +var_dump(copy("../bad/bad.txt", "copy.txt")); +var_dump(unlink("copy.txt")); + +test_open_basedir_after("copy"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [copy] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: copy(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: unlink(copy.txt): No such file or directory in %s on line %d +bool(false) +*** Finished testing open_basedir configuration [copy] *** + diff --git a/tests/security/open_basedir_dir.phpt b/tests/security/open_basedir_dir.phpt new file mode 100644 index 000000000..b1d6272bd --- /dev/null +++ b/tests/security/open_basedir_dir.phpt @@ -0,0 +1,89 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +$initdir = getcwd(); + +test_open_basedir_before("dir"); +test_open_basedir_error("dir"); + +var_dump(dir($initdir."/test/ok/")); +var_dump(dir($initdir."/test/ok")); +var_dump(dir($initdir."/test/ok/../ok")); + +test_open_basedir_after("dir");?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [dir] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: dir(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d + +Warning: dir(../bad): failed to open dir: %s in %s on line %d +bool(false) + +Warning: dir(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: dir(../bad/bad.txt): failed to open dir: %s in %s on line %d +bool(false) + +Warning: dir(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d + +Warning: dir(..): failed to open dir: %s in %s on line %d +bool(false) + +Warning: dir(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d + +Warning: dir(../): failed to open dir: %s in %s on line %d +bool(false) + +Warning: dir(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d + +Warning: dir(/): failed to open dir: %s in %s on line %d +bool(false) + +Warning: dir(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d + +Warning: dir(../bad/.): failed to open dir: %s in %s on line %d +bool(false) + +Warning: dir(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: dir(%s/test/bad/bad.txt): failed to open dir: %s in %s on line %d +bool(false) + +Warning: dir(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: dir(%s/test/bad/../bad/bad.txt): failed to open dir: %s in %s on line %d +bool(false) +object(Directory)#%d (2) { + ["path"]=> + string(%d) "%s/test/ok/" + ["handle"]=> + resource(%d) of type (stream) +} +object(Directory)#%d (2) { + ["path"]=> + string(%d) "%s/test/ok" + ["handle"]=> + resource(%d) of type (stream) +} +object(Directory)#%d (2) { + ["path"]=> + string(%d) "%s/test/ok/../ok" + ["handle"]=> + resource(%d) of type (stream) +} +*** Finished testing open_basedir configuration [dir] *** + diff --git a/tests/security/open_basedir_disk_free_space.phpt b/tests/security/open_basedir_disk_free_space.phpt new file mode 100644 index 000000000..365300ae6 --- /dev/null +++ b/tests/security/open_basedir_disk_free_space.phpt @@ -0,0 +1,52 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +$initdir = getcwd(); +test_open_basedir_before("disk_free_space"); +test_open_basedir_error("disk_free_space"); + +var_dump(disk_free_space($initdir."/test/ok")); +test_open_basedir_after("disk_free_space"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [disk_free_space] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: disk_free_space(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: disk_free_space(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: disk_free_space(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: disk_free_space(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: disk_free_space(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: disk_free_space(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: disk_free_space(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: disk_free_space(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) +float(%s) +*** Finished testing open_basedir configuration [disk_free_space] *** diff --git a/tests/security/open_basedir_error_log.phpt b/tests/security/open_basedir_error_log.phpt new file mode 100644 index 000000000..e89e19021 --- /dev/null +++ b/tests/security/open_basedir_error_log.phpt @@ -0,0 +1,45 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +error_log= +--FILE-- +<?php +require_once "open_basedir.inc"; +$initdir = getcwd(); +test_open_basedir_before("error_log"); + + +var_dump(ini_set("error_log", $initdir."/test/bad/bad.txt")); +var_dump(ini_set("error_log", $initdir."/test/bad.txt")); +var_dump(ini_set("error_log", $initdir."/bad.txt")); +var_dump(ini_set("error_log", $initdir."/test/ok/ok.txt")); +var_dump(ini_set("error_log", $initdir."/test/ok/ok.txt")); + +test_open_basedir_after("error_log"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [error_log] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: ini_set(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: ini_set(): open_basedir restriction in effect. File(%s/test/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: ini_set(): open_basedir restriction in effect. File(%s/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) +string(0) "" +string(%d) "%s/test/ok/ok.txt" +*** Finished testing open_basedir configuration [error_log] *** + diff --git a/tests/security/open_basedir_error_log_variation.phpt b/tests/security/open_basedir_error_log_variation.phpt new file mode 100644 index 000000000..ab182669a --- /dev/null +++ b/tests/security/open_basedir_error_log_variation.phpt @@ -0,0 +1,49 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +$initdir = getcwd(); +test_open_basedir_before("error_log"); + +define("DESTINATION_IS_FILE", 3); + +var_dump(error_log("Hello World!", DESTINATION_IS_FILE, $initdir."/test/bad/bad.txt")); +var_dump(error_log("Hello World!", DESTINATION_IS_FILE, $initdir."/test/bad.txt")); +var_dump(error_log("Hello World!", DESTINATION_IS_FILE, $initdir."/bad.txt")); +var_dump(error_log("Hello World!", DESTINATION_IS_FILE, $initdir."/test/ok/ok.txt")); + +test_open_basedir_after("error_log"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [error_log] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: error_log(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: error_log(%s/test/bad/bad.txt): failed to open stream: %s in %s on line %d +bool(false) + +Warning: error_log(): open_basedir restriction in effect. File(%s/test/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: error_log(%s/test/bad.txt): failed to open stream: %s in %s on line %d +bool(false) + +Warning: error_log(): open_basedir restriction in effect. File(%s/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: error_log(%s/bad.txt): failed to open stream: %s in %s on line %d +bool(false) +bool(true) +*** Finished testing open_basedir configuration [error_log] *** + diff --git a/tests/security/open_basedir_file.phpt b/tests/security/open_basedir_file.phpt new file mode 100644 index 000000000..ad222e894 --- /dev/null +++ b/tests/security/open_basedir_file.phpt @@ -0,0 +1,88 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +$initdir = getcwd(); +test_open_basedir_before("file"); +test_open_basedir_error("file"); + +var_dump(file("ok.txt")); +var_dump(file("../ok/ok.txt")); +var_dump(file($initdir."/test/ok/ok.txt")); +var_dump(file($initdir."/test/ok/../ok/ok.txt")); + +test_open_basedir_after("file"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [file] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: file(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d + +Warning: file(../bad): failed to open stream: %s in %s on line %d +bool(false) + +Warning: file(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: file(../bad/bad.txt): failed to open stream: %s in %s on line %d +bool(false) + +Warning: file(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d + +Warning: file(..): failed to open stream: %s in %s on line %d +bool(false) + +Warning: file(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d + +Warning: file(../): failed to open stream: %s in %s on line %d +bool(false) + +Warning: file(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d + +Warning: file(/): failed to open stream: %s in %s on line %d +bool(false) + +Warning: file(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d + +Warning: file(../bad/.): failed to open stream: %s in %s on line %d +bool(false) + +Warning: file(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: file(%s/test/bad/bad.txt): failed to open stream: %s in %s on line %d +bool(false) + +Warning: file(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: file(%s/test/bad/../bad/bad.txt): failed to open stream: %s in %s on line %d +bool(false) +array(1) { + [0]=> + string(12) "Hello World!" +} +array(1) { + [0]=> + string(12) "Hello World!" +} +array(1) { + [0]=> + string(12) "Hello World!" +} +array(1) { + [0]=> + string(12) "Hello World!" +} +*** Finished testing open_basedir configuration [file] *** + diff --git a/tests/security/open_basedir_file_exists.phpt b/tests/security/open_basedir_file_exists.phpt new file mode 100644 index 000000000..c249fc116 --- /dev/null +++ b/tests/security/open_basedir_file_exists.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("file_exists"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [file_exists] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: file_exists(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: file_exists(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: file_exists(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: file_exists(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: file_exists(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: file_exists(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: file_exists(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: file_exists(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: file_exists(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +*** Finished testing open_basedir configuration [file_exists] *** + diff --git a/tests/security/open_basedir_file_get_contents.phpt b/tests/security/open_basedir_file_get_contents.phpt new file mode 100644 index 000000000..8ee5ddb79 --- /dev/null +++ b/tests/security/open_basedir_file_get_contents.phpt @@ -0,0 +1,75 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +$initdir = getcwd(); +test_open_basedir_before("file_get_contents"); +test_open_basedir_error("file_get_contents"); + +var_dump(file_get_contents("ok.txt")); +var_dump(file_get_contents("../ok/ok.txt")); +var_dump(file_get_contents($initdir."/test/ok/ok.txt")); +var_dump(file_get_contents($initdir."/test/ok/../ok/ok.txt")); + +test_open_basedir_after("file_get_contents"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [file_get_contents] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: file_get_contents(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d + +Warning: file_get_contents(../bad): failed to open stream: %s in %s on line %d +bool(false) + +Warning: file_get_contents(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: file_get_contents(../bad/bad.txt): failed to open stream: %s in %s on line %d +bool(false) + +Warning: file_get_contents(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d + +Warning: file_get_contents(..): failed to open stream: %s in %s on line %d +bool(false) + +Warning: file_get_contents(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d + +Warning: file_get_contents(../): failed to open stream: %s in %s on line %d +bool(false) + +Warning: file_get_contents(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d + +Warning: file_get_contents(/): failed to open stream: %s in %s on line %d +bool(false) + +Warning: file_get_contents(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d + +Warning: file_get_contents(../bad/.): failed to open stream: %s in %s on line %d +bool(false) + +Warning: file_get_contents(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: file_get_contents(%s/test/bad/bad.txt): failed to open stream: %s in %s on line %d +bool(false) + +Warning: file_get_contents(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: file_get_contents(%s/test/bad/../bad/bad.txt): failed to open stream: %s in %s on line %d +bool(false) +string(12) "Hello World!" +string(12) "Hello World!" +string(12) "Hello World!" +string(12) "Hello World!" +*** Finished testing open_basedir configuration [file_get_contents] *** diff --git a/tests/security/open_basedir_file_put_contents.phpt b/tests/security/open_basedir_file_put_contents.phpt new file mode 100644 index 000000000..0235c509b --- /dev/null +++ b/tests/security/open_basedir_file_put_contents.phpt @@ -0,0 +1,57 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +$initdir = getcwd(); +test_open_basedir_before("file_put_contents"); + +var_dump(file_put_contents("../bad/bad.txt", "Hello World!")); +var_dump(file_put_contents(".././bad/bad.txt", "Hello World!")); +var_dump(file_put_contents("../bad/../bad/bad.txt", "Hello World!")); +var_dump(file_put_contents("./.././bad/bad.txt", "Hello World!")); +var_dump(file_put_contents($initdir."/test/bad/bad.txt", "Hello World!")); + +test_open_basedir_after("file_put_contents"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [file_put_contents] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: file_put_contents(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: file_put_contents(../bad/bad.txt): failed to open stream: %s in %s on line %d +bool(false) + +Warning: file_put_contents(): open_basedir restriction in effect. File(.././bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: file_put_contents(.././bad/bad.txt): failed to open stream: %s in %s on line %d +bool(false) + +Warning: file_put_contents(): open_basedir restriction in effect. File(../bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: file_put_contents(../bad/../bad/bad.txt): failed to open stream: %s in %s on line %d +bool(false) + +Warning: file_put_contents(): open_basedir restriction in effect. File(./.././bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: file_put_contents(./.././bad/bad.txt): failed to open stream: %s in %s on line %d +bool(false) + +Warning: file_put_contents(): open_basedir restriction in effect. File%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: file_put_contents%s/test/bad/bad.txt): failed to open stream: %s in %s on line %d +bool(false) +*** Finished testing open_basedir configuration [file_put_contents] *** + diff --git a/tests/security/open_basedir_fileatime.phpt b/tests/security/open_basedir_fileatime.phpt new file mode 100644 index 000000000..02cc94f83 --- /dev/null +++ b/tests/security/open_basedir_fileatime.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("fileatime"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [fileatime] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: fileatime(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileatime(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileatime(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileatime(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileatime(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileatime(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileatime(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileatime(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileatime(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +int(%d) +int(%d) +int(%d) +int(%d) +int(%d) +*** Finished testing open_basedir configuration [fileatime] *** + diff --git a/tests/security/open_basedir_filectime.phpt b/tests/security/open_basedir_filectime.phpt new file mode 100644 index 000000000..542c8423e --- /dev/null +++ b/tests/security/open_basedir_filectime.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("filectime"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [filectime] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: filectime(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filectime(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filectime(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filectime(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filectime(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filectime(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filectime(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filectime(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filectime(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +int(%d) +int(%d) +int(%d) +int(%d) +int(%d) +*** Finished testing open_basedir configuration [filectime] *** + diff --git a/tests/security/open_basedir_filegroup.phpt b/tests/security/open_basedir_filegroup.phpt new file mode 100644 index 000000000..5f6279aa8 --- /dev/null +++ b/tests/security/open_basedir_filegroup.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("filegroup"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [filegroup] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: filegroup(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filegroup(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filegroup(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filegroup(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filegroup(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filegroup(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filegroup(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filegroup(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filegroup(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +int(%d) +int(%d) +int(%d) +int(%d) +int(%d) +*** Finished testing open_basedir configuration [filegroup] *** + diff --git a/tests/security/open_basedir_fileinode.phpt b/tests/security/open_basedir_fileinode.phpt new file mode 100644 index 000000000..070c2c806 --- /dev/null +++ b/tests/security/open_basedir_fileinode.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("fileinode"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [fileinode] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: fileinode(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileinode(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileinode(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileinode(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileinode(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileinode(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileinode(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileinode(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileinode(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +int(%d) +int(%d) +int(%d) +int(%d) +int(%d) +*** Finished testing open_basedir configuration [fileinode] *** + diff --git a/tests/security/open_basedir_filemtime.phpt b/tests/security/open_basedir_filemtime.phpt new file mode 100644 index 000000000..7213ddb5b --- /dev/null +++ b/tests/security/open_basedir_filemtime.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("filemtime"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [filemtime] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: filemtime(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filemtime(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filemtime(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filemtime(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filemtime(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filemtime(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filemtime(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filemtime(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filemtime(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +int(%d) +int(%d) +int(%d) +int(%d) +int(%d) +*** Finished testing open_basedir configuration [filemtime] *** + diff --git a/tests/security/open_basedir_fileowner.phpt b/tests/security/open_basedir_fileowner.phpt new file mode 100644 index 000000000..b363b7e0e --- /dev/null +++ b/tests/security/open_basedir_fileowner.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("fileowner"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [fileowner] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: fileowner(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileowner(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileowner(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileowner(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileowner(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileowner(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileowner(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileowner(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileowner(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +int(%d) +int(%d) +int(%d) +int(%d) +int(%d) +*** Finished testing open_basedir configuration [fileowner] *** + diff --git a/tests/security/open_basedir_fileperms.phpt b/tests/security/open_basedir_fileperms.phpt new file mode 100644 index 000000000..a1e6511b0 --- /dev/null +++ b/tests/security/open_basedir_fileperms.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("fileperms"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [fileperms] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: fileperms(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileperms(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileperms(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileperms(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileperms(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileperms(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileperms(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileperms(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: fileperms(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +int(%d) +int(%d) +int(%d) +int(%d) +int(%d) +*** Finished testing open_basedir configuration [fileperms] *** + diff --git a/tests/security/open_basedir_filesize.phpt b/tests/security/open_basedir_filesize.phpt new file mode 100644 index 000000000..a335dfd17 --- /dev/null +++ b/tests/security/open_basedir_filesize.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("filesize"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [filesize] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: filesize(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filesize(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filesize(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filesize(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filesize(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filesize(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filesize(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filesize(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filesize(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +int(%d) +int(%d) +int(%d) +int(%d) +int(%d) +*** Finished testing open_basedir configuration [filesize] *** + diff --git a/tests/security/open_basedir_filetype.phpt b/tests/security/open_basedir_filetype.phpt new file mode 100644 index 000000000..5091db56f --- /dev/null +++ b/tests/security/open_basedir_filetype.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("filetype"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [filetype] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: filetype(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filetype(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filetype(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filetype(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filetype(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filetype(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filetype(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filetype(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: filetype(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +string(3) "dir" +string(4) "file" +string(4) "file" +string(4) "file" +string(4) "file" +*** Finished testing open_basedir configuration [filetype] *** + diff --git a/tests/security/open_basedir_fopen.phpt b/tests/security/open_basedir_fopen.phpt new file mode 100644 index 000000000..3e236af9d --- /dev/null +++ b/tests/security/open_basedir_fopen.phpt @@ -0,0 +1,86 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +$initdir = getcwd(); +test_open_basedir_before("fopen"); + +var_dump(fopen("../bad", "r")); +var_dump(fopen("../bad/bad.txt", "r")); +var_dump(fopen("..", "r")); +var_dump(fopen("../", "r")); +var_dump(fopen("/", "r")); +var_dump(fopen("../bad/.", "r")); +var_dump(fopen("../bad/./bad.txt", "r")); +var_dump(fopen("./../.", "r")); + +var_dump(fopen($initdir."/test/ok/ok.txt", "r")); +var_dump(fopen("./ok.txt", "r")); +var_dump(fopen("ok.txt", "r")); +var_dump(fopen("../ok/ok.txt", "r")); +var_dump(fopen("../ok/./ok.txt", "r")); + +test_open_basedir_after("fopen"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [fopen] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: fopen(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d + +Warning: fopen(../bad): failed to open stream: %s in %s on line %d +bool(false) + +Warning: fopen(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: fopen(../bad/bad.txt): failed to open stream: %s in %s on line %d +bool(false) + +Warning: fopen(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d + +Warning: fopen(..): failed to open stream: %s in %s on line %d +bool(false) + +Warning: fopen(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d + +Warning: fopen(../): failed to open stream: %s in %s on line %d +bool(false) + +Warning: fopen(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d + +Warning: fopen(/): failed to open stream: %s in %s on line %d +bool(false) + +Warning: fopen(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d + +Warning: fopen(../bad/.): failed to open stream: %s in %s on line %d +bool(false) + +Warning: fopen(): open_basedir restriction in effect. File(../bad/./bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: fopen(../bad/./bad.txt): failed to open stream: %s in %s on line 12 +bool(false) + +Warning: fopen(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d + +Warning: fopen(./../.): failed to open stream: %s in %s on line %d +bool(false) +resource(%d) of type (stream) +resource(%d) of type (stream) +resource(%d) of type (stream) +resource(%d) of type (stream) +resource(%d) of type (stream) +*** Finished testing open_basedir configuration [fopen] *** + diff --git a/tests/security/open_basedir_glob-win32.phpt b/tests/security/open_basedir_glob-win32.phpt new file mode 100644 index 000000000..3fa19afa3 --- /dev/null +++ b/tests/security/open_basedir_glob-win32.phpt @@ -0,0 +1,59 @@ +--TEST-- +Test open_basedir configuration +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) != 'WIN') { + die('skip Windows only variation'); +} +?> +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("glob"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [glob] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(false) +bool(false) +bool(false) +array(0) { +} +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +array(1) { + [0]=> + string(5) "../ok" +} +array(1) { + [0]=> + string(6) "ok.txt" +} +array(1) { + [0]=> + string(12) "../ok/ok.txt" +} +array(1) { + [0]=> + string(%d) "%s/test/ok/ok.txt" +} +array(1) { + [0]=> + string(%d) "%s/test/ok/../ok/ok.txt" +} +*** Finished testing open_basedir configuration [glob] *** + diff --git a/tests/security/open_basedir_glob.phpt b/tests/security/open_basedir_glob.phpt new file mode 100644 index 000000000..591cd8f4f --- /dev/null +++ b/tests/security/open_basedir_glob.phpt @@ -0,0 +1,58 @@ +--TEST-- +Test open_basedir configuration +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip Not for Windows variation'); +} +?> +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("glob"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [glob] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +array(1) { + [0]=> + string(5) "../ok" +} +array(1) { + [0]=> + string(6) "ok.txt" +} +array(1) { + [0]=> + string(12) "../ok/ok.txt" +} +array(1) { + [0]=> + string(%d) "%s/test/ok/ok.txt" +} +array(1) { + [0]=> + string(%d) "%s/test/ok/../ok/ok.txt" +} +*** Finished testing open_basedir configuration [glob] *** + diff --git a/tests/security/open_basedir_glob_variation.phpt b/tests/security/open_basedir_glob_variation.phpt new file mode 100644 index 000000000..52c354f90 --- /dev/null +++ b/tests/security/open_basedir_glob_variation.phpt @@ -0,0 +1,26 @@ +--TEST-- +Test open_basedir configuration for glob +--INI-- +open_basedir=. +--FILE-- +<?php +$dir = "globtest1"; +$dir2 = "globtest2"; +mkdir($dir); +mkdir($dir2); +chdir($dir); +var_dump(glob("../globtest*")); +?> +--CLEAN-- +<?php +$dir = "globtest1"; +$dir2 = "globtest2"; +rmdir($dir); +rmdir($dir2); +?> +--EXPECT-- +array(1) { + [0]=> + string(12) "../globtest1" +} + diff --git a/tests/security/open_basedir_is_dir.phpt b/tests/security/open_basedir_is_dir.phpt new file mode 100644 index 000000000..e4ad620d7 --- /dev/null +++ b/tests/security/open_basedir_is_dir.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("is_dir"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [is_dir] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: is_dir(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_dir(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_dir(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_dir(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_dir(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_dir(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_dir(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_dir(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_dir(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +bool(true) +bool(false) +bool(false) +bool(false) +bool(false) +*** Finished testing open_basedir configuration [is_dir] *** + diff --git a/tests/security/open_basedir_is_executable.phpt b/tests/security/open_basedir_is_executable.phpt new file mode 100644 index 000000000..375d4277c --- /dev/null +++ b/tests/security/open_basedir_is_executable.phpt @@ -0,0 +1,59 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +$initdir = getcwd(); +test_open_basedir_before("is_executable"); +test_open_basedir_error("is_executable"); + +var_dump(is_executable("ok.txt")); +var_dump(is_executable("../ok/ok.txt")); +var_dump(is_executable($initdir."/test/ok/ok.txt")); +var_dump(is_executable($initdir."/test/ok/../ok/ok.txt")); + +test_open_basedir_after("is_executable"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [is_executable] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: is_executable(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_executable(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_executable(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_executable(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_executable(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_executable(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_executable(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_executable(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +*** Finished testing open_basedir configuration [is_executable] *** diff --git a/tests/security/open_basedir_is_file.phpt b/tests/security/open_basedir_is_file.phpt new file mode 100644 index 000000000..51ef0a2d1 --- /dev/null +++ b/tests/security/open_basedir_is_file.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("is_file"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [is_file] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: is_file(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_file(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_file(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_file(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_file(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_file(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_file(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_file(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_file(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +bool(false) +bool(true) +bool(true) +bool(true) +bool(true) +*** Finished testing open_basedir configuration [is_file] *** + diff --git a/tests/security/open_basedir_is_link.phpt b/tests/security/open_basedir_is_link.phpt new file mode 100644 index 000000000..5d12148d8 --- /dev/null +++ b/tests/security/open_basedir_is_link.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("is_link"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [is_link] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: is_link(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_link(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_link(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_link(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_link(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_link(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_link(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_link(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_link(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +*** Finished testing open_basedir configuration [is_link] *** + diff --git a/tests/security/open_basedir_is_readable.phpt b/tests/security/open_basedir_is_readable.phpt new file mode 100644 index 000000000..951a19ac7 --- /dev/null +++ b/tests/security/open_basedir_is_readable.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("is_readable"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [is_readable] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: is_readable(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_readable(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_readable(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_readable(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_readable(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_readable(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_readable(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_readable(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_readable(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +*** Finished testing open_basedir configuration [is_readable] *** + diff --git a/tests/security/open_basedir_is_writable.phpt b/tests/security/open_basedir_is_writable.phpt new file mode 100644 index 000000000..25ce1c63a --- /dev/null +++ b/tests/security/open_basedir_is_writable.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("is_writable"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [is_writable] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: is_writable(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_writable(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_writable(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_writable(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_writable(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_writable(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_writable(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_writable(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: is_writable(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +*** Finished testing open_basedir configuration [is_writable] *** + diff --git a/tests/security/open_basedir_link.phpt b/tests/security/open_basedir_link.phpt new file mode 100644 index 000000000..82f97d6b0 --- /dev/null +++ b/tests/security/open_basedir_link.phpt @@ -0,0 +1,78 @@ +--TEST-- +Test open_basedir configuration +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip no links on Windows'); +} +?> +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +$initdir = getcwd(); +test_open_basedir_before("link"); + +$target = ($initdir."/test/ok/ok.txt"); +var_dump(link($target, "../bad/link.txt")); +var_dump(link($target, "../link.txt")); +var_dump(link($target, "../bad/./link.txt")); +var_dump(link($target, "./.././link.txt")); + +$link = ($initdir."/test/ok/link.txt"); +var_dump(link("../bad/bad.txt", $link)); +var_dump(link("../bad", $link)); +var_dump(link("../bad/./bad.txt", $link)); +var_dump(link("../bad/bad.txt", $link)); +var_dump(link("./.././bad", $link)); + +$target = ($initdir."/test/ok/ok.txt"); + +var_dump(link($target, $link)); +var_dump(unlink($link)); +test_open_basedir_after("link"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [link] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: link(): open_basedir restriction in effect. File(%s/test/bad/link.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: link(): open_basedir restriction in effect. File(%s/test/link.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: link(): open_basedir restriction in effect. File(%s/test/bad/link.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: link(): open_basedir restriction in effect. File(%s/test/link.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: link(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: link(): open_basedir restriction in effect. File(%s/test/bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: link(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: link(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: link(): open_basedir restriction in effect. File(%s/test/bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) +bool(true) +bool(true) +*** Finished testing open_basedir configuration [link] *** + diff --git a/tests/security/open_basedir_linkinfo.phpt b/tests/security/open_basedir_linkinfo.phpt new file mode 100644 index 000000000..5c930dddc --- /dev/null +++ b/tests/security/open_basedir_linkinfo.phpt @@ -0,0 +1,64 @@ +--TEST-- +Test open_basedir configuration +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip no symlinks on Windows'); +} +?> +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +$initdir = getcwd(); +test_open_basedir_before("linkinfo", FALSE); + +chdir($initdir); + +$target = ($initdir."/test/bad/bad.txt"); +$symlink = ($initdir."/test/ok/symlink.txt"); +var_dump(symlink($target, $symlink)); + +chdir($initdir."/test/ok"); + +var_dump(linkinfo("symlink.txt")); +var_dump(linkinfo("../ok/symlink.txt")); +var_dump(linkinfo("../ok/./symlink.txt")); +var_dump(linkinfo("./symlink.txt")); +var_dump(linkinfo($initdir."/test/ok/symlink.txt")); + +$target = ($initdir."/test/ok/ok.txt"); +$symlink = ($initdir."/test/ok/symlink.txt"); +var_dump(symlink($target, $symlink)); +var_dump(linkinfo($symlink)); +var_dump(unlink($symlink)); + +test_open_basedir_after("linkinfo"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [linkinfo] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +int(%d) +int(%d) +int(%d) +int(%d) +int(%d) + +Warning: symlink(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) +int(%d) + +Warning: unlink(): open_basedir restriction in effect. File(%s/test/ok/symlink.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) +*** Finished testing open_basedir configuration [linkinfo] *** + diff --git a/tests/security/open_basedir_lstat.phpt b/tests/security/open_basedir_lstat.phpt new file mode 100644 index 000000000..35e5a2201 --- /dev/null +++ b/tests/security/open_basedir_lstat.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_array("lstat"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [lstat] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: lstat(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: lstat(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: lstat(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: lstat(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: lstat(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: lstat(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: lstat(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: lstat(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: lstat(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +*** Finished testing open_basedir configuration [lstat] *** + diff --git a/tests/security/open_basedir_mkdir.phpt b/tests/security/open_basedir_mkdir.phpt new file mode 100644 index 000000000..9c32d408a --- /dev/null +++ b/tests/security/open_basedir_mkdir.phpt @@ -0,0 +1,52 @@ +--TEST-- +Test open_basedir configuration +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) != 'WIN') { + die('skip Windows only variation'); +} +?> +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +$initdir = getcwd(); +test_open_basedir_before("mkdir"); + +var_dump(mkdir("../bad/blah")); +var_dump(mkdir("../blah")); +var_dump(mkdir("../bad/./blah")); +var_dump(mkdir("./.././blah")); + +var_dump(mkdir($initdir."/test/ok/blah")); +var_dump(rmdir($initdir."/test/ok/blah")); +test_open_basedir_after("mkdir"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [mkdir] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: mkdir(): open_basedir restriction in effect. File(../bad/blah) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: mkdir(): open_basedir restriction in effect. File(../blah) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: mkdir(): open_basedir restriction in effect. File(../bad/./blah) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: mkdir(): open_basedir restriction in effect. File(./.././blah) is not within the allowed path(s): (.) in %s on line %d +bool(false) +bool(true) +bool(true) +*** Finished testing open_basedir configuration [mkdir] *** diff --git a/tests/security/open_basedir_opendir.phpt b/tests/security/open_basedir_opendir.phpt new file mode 100644 index 000000000..774b85356 --- /dev/null +++ b/tests/security/open_basedir_opendir.phpt @@ -0,0 +1,73 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +$initdir = getcwd(); +test_open_basedir_before("opendir"); +test_open_basedir_error("opendir"); + +var_dump(opendir($initdir."/test/ok/")); +var_dump(opendir($initdir."/test/ok")); +var_dump(opendir($initdir."/test/ok/../ok")); + +test_open_basedir_after("opendir");?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [opendir] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: opendir(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d + +Warning: opendir(../bad): failed to open dir: %s in %s on line %d +bool(false) + +Warning: opendir(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: opendir(../bad/bad.txt): failed to open dir: %s in %s on line %d +bool(false) + +Warning: opendir(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d + +Warning: opendir(..): failed to open dir: %s in %s on line %d +bool(false) + +Warning: opendir(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d + +Warning: opendir(../): failed to open dir: %s in %s on line %d +bool(false) + +Warning: opendir(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d + +Warning: opendir(/): failed to open dir: %s in %s on line %d +bool(false) + +Warning: opendir(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d + +Warning: opendir(../bad/.): failed to open dir: %s in %s on line %d +bool(false) + +Warning: opendir(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: opendir(%s/test/bad/bad.txt): failed to open dir: %s in %s on line %d +bool(false) + +Warning: opendir(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: opendir(%s/test/bad/../bad/bad.txt): failed to open dir: %s in %s on line %d +bool(false) +resource(%d) of type (stream) +resource(%d) of type (stream) +resource(%d) of type (stream) +*** Finished testing open_basedir configuration [opendir] *** + diff --git a/tests/security/open_basedir_parse_ini_file.phpt b/tests/security/open_basedir_parse_ini_file.phpt new file mode 100644 index 000000000..e2f904635 --- /dev/null +++ b/tests/security/open_basedir_parse_ini_file.phpt @@ -0,0 +1,67 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_before("parse_ini_file"); +$directory = dirname(__FILE__); + +var_dump(parse_ini_file("../bad")); +var_dump(parse_ini_file("../bad/bad.txt")); +var_dump(parse_ini_file("..")); +var_dump(parse_ini_file("../")); +var_dump(parse_ini_file("../bad/.")); +var_dump(parse_ini_file("../bad/./bad.txt")); +var_dump(parse_ini_file("./../.")); + +test_open_basedir_after("parse_ini_file"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [parse_ini_file] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: parse_ini_file(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d + +Warning: parse_ini_file(../bad): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: parse_ini_file(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: parse_ini_file(../bad/bad.txt): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: parse_ini_file(..): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: parse_ini_file(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d + +Warning: parse_ini_file(../): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: parse_ini_file(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d + +Warning: parse_ini_file(../bad/.): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: parse_ini_file(): open_basedir restriction in effect. File(../bad/./bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: parse_ini_file(../bad/./bad.txt): failed to open stream: Operation not permitted in %s on line %d +bool(false) + +Warning: parse_ini_file(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d + +Warning: parse_ini_file(./../.): failed to open stream: Operation not permitted in %s on line %d +bool(false) +*** Finished testing open_basedir configuration [parse_ini_file] *** + diff --git a/tests/security/open_basedir_readlink.phpt b/tests/security/open_basedir_readlink.phpt new file mode 100644 index 000000000..a632dce24 --- /dev/null +++ b/tests/security/open_basedir_readlink.phpt @@ -0,0 +1,76 @@ +--TEST-- +Test open_basedir configuration +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip no symlinks on Windows'); +} +?> +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +$initdir = getcwd(); +test_open_basedir_before("readlink", FALSE); + +chdir($initdir); + +$target = ($initdir."/test/bad/bad.txt"); +$symlink = ($initdir."/test/ok/symlink.txt"); +var_dump(symlink($target, $symlink)); + +chdir($initdir."/test/ok"); + +var_dump(readlink("symlink.txt")); +var_dump(readlink("../ok/symlink.txt")); +var_dump(readlink("../ok/./symlink.txt")); +var_dump(readlink("./symlink.txt")); +var_dump(readlink($initdir."/test/ok/symlink.txt")); + +$target = ($initdir."/test/ok/ok.txt"); +$symlink = ($initdir."/test/ok/symlink.txt"); +var_dump(symlink($target, $symlink)); +var_dump(readlink($symlink)); +var_dump(unlink($symlink)); + +test_open_basedir_after("readlink"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [readlink] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: readlink(): open_basedir restriction in effect. File(symlink.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: readlink(): open_basedir restriction in effect. File(../ok/symlink.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: readlink(): open_basedir restriction in effect. File(../ok/./symlink.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: readlink(): open_basedir restriction in effect. File(./symlink.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: readlink(): open_basedir restriction in effect. File(%s/test/ok/symlink.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: symlink(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: readlink(): open_basedir restriction in effect. File(%s/test/ok/symlink.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: unlink(): open_basedir restriction in effect. File(%s/test/ok/symlink.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) +*** Finished testing open_basedir configuration [readlink] *** + diff --git a/tests/security/open_basedir_realpath.phpt b/tests/security/open_basedir_realpath.phpt new file mode 100644 index 000000000..8cae890e9 --- /dev/null +++ b/tests/security/open_basedir_realpath.phpt @@ -0,0 +1,61 @@ +--TEST-- +Test open_basedir configuration +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) != 'WIN') { + die('skip only run on Windows'); +} +?> +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir("realpath"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [realpath] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: realpath(): open_basedir restriction in effect. File(%s\test\bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: realpath(): open_basedir restriction in effect. File(%s\test\bad\bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: realpath(): open_basedir restriction in effect. File(%s\test) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: realpath(): open_basedir restriction in effect. File(%s\test) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: realpath(): open_basedir restriction in effect. File(%s\) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: realpath(): open_basedir restriction in effect. File(%s\test\bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: realpath(): open_basedir restriction in effect. File(%s\test\bad\bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: realpath(): open_basedir restriction in effect. File(%s\test\bad\bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: realpath(): open_basedir restriction in effect. File(%s\test) is not within the allowed path(s): (.) in %s on line %d +bool(false) +string(%d) "%s\test\ok" +string(%d) "%s\test\ok\ok.txt" +string(%d) "%s\test\ok\ok.txt" +string(%d) "%s\test\ok\ok.txt" +string(%d) "%s\test\ok\ok.txt" +*** Finished testing open_basedir configuration [realpath] *** + diff --git a/tests/security/open_basedir_rename.phpt b/tests/security/open_basedir_rename.phpt new file mode 100644 index 000000000..274709334 --- /dev/null +++ b/tests/security/open_basedir_rename.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +$initdir = getcwd(); +test_open_basedir_before("rename"); + +var_dump(rename("../bad/bad.txt", "rename.txt")); +var_dump(rename(".././bad/bad.txt", "rename.txt")); +var_dump(rename("../bad/../bad/bad.txt", "rename.txt")); +var_dump(rename("./.././bad/bad.txt", "rename.txt")); +var_dump(rename($initdir."/test/bad/bad.txt", "rename.txt")); + +test_open_basedir_after("rename"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [rename] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: rename(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: rename(): open_basedir restriction in effect. File(.././bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: rename(): open_basedir restriction in effect. File(../bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: rename(): open_basedir restriction in effect. File(./.././bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: rename(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) +*** Finished testing open_basedir configuration [rename] *** + diff --git a/tests/security/open_basedir_rmdir.phpt b/tests/security/open_basedir_rmdir.phpt new file mode 100644 index 000000000..c1d4b6b14 --- /dev/null +++ b/tests/security/open_basedir_rmdir.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +$initdir = getcwd(); +test_open_basedir_before("rmdir"); + +var_dump(rmdir("../bad")); +var_dump(rmdir(".././bad")); +var_dump(rmdir("../bad/../bad")); +var_dump(rmdir("./.././bad")); +var_dump(rmdir($initdir."/test/bad")); + +test_open_basedir_after("rmdir"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [rmdir] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: rmdir(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: rmdir(): open_basedir restriction in effect. File(.././bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: rmdir(): open_basedir restriction in effect. File(../bad/../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: rmdir(): open_basedir restriction in effect. File(./.././bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: rmdir(): open_basedir restriction in effect. File(%s/test/bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) +*** Finished testing open_basedir configuration [rmdir] *** + diff --git a/tests/security/open_basedir_scandir.phpt b/tests/security/open_basedir_scandir.phpt new file mode 100644 index 000000000..caffaa1e5 --- /dev/null +++ b/tests/security/open_basedir_scandir.phpt @@ -0,0 +1,110 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +$initdir = getcwd(); +test_open_basedir_before("scandir"); +test_open_basedir_error("scandir"); + +var_dump(scandir($initdir."/test/ok/")); +var_dump(scandir($initdir."/test/ok")); +var_dump(scandir($initdir."/test/ok/../ok")); + +test_open_basedir_after("scandir");?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [scandir] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: scandir(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d + +Warning: scandir(../bad): failed to open dir: %s in %s on line %d + +Warning: scandir(): (errno 1): %s in %s on line %d +bool(false) + +Warning: scandir(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: scandir(../bad/bad.txt): failed to open dir: %s in %s on line %d + +Warning: scandir(): (errno 1): %s in %s on line %d +bool(false) + +Warning: scandir(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d + +Warning: scandir(..): failed to open dir: %s in %s on line %d + +Warning: scandir(): (errno 1): %s in %s on line %d +bool(false) + +Warning: scandir(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d + +Warning: scandir(../): failed to open dir: %s in %s on line %d + +Warning: scandir(): (errno 1): %s in %s on line %d +bool(false) + +Warning: scandir(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d + +Warning: scandir(/): failed to open dir: %s in %s on line %d + +Warning: scandir(): (errno 1): %s in %s on line %d +bool(false) + +Warning: scandir(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d + +Warning: scandir(../bad/.): failed to open dir: %s in %s on line %d + +Warning: scandir(): (errno 1): %s in %s on line %d +bool(false) + +Warning: scandir(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: scandir(%s/test/bad/bad.txt): failed to open dir: %s in %s on line %d + +Warning: scandir(): (errno 1): %s in %s on line %d +bool(false) + +Warning: scandir(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d + +Warning: scandir(%s/test/bad/../bad/bad.txt): failed to open dir: %s in %s on line %d + +Warning: scandir(): (errno 1): %s in %s on line %d +bool(false) +array(3) { + [0]=> + string(1) "." + [1]=> + string(2) ".." + [2]=> + string(6) "ok.txt" +} +array(3) { + [0]=> + string(1) "." + [1]=> + string(2) ".." + [2]=> + string(6) "ok.txt" +} +array(3) { + [0]=> + string(1) "." + [1]=> + string(2) ".." + [2]=> + string(6) "ok.txt" +} +*** Finished testing open_basedir configuration [scandir] *** + diff --git a/tests/security/open_basedir_stat.phpt b/tests/security/open_basedir_stat.phpt new file mode 100644 index 000000000..b80b854d6 --- /dev/null +++ b/tests/security/open_basedir_stat.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +test_open_basedir_array("stat"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [stat] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: stat(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: stat(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: stat(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: stat(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: stat(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: stat(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: stat(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: stat(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: stat(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +*** Finished testing open_basedir configuration [stat] *** + diff --git a/tests/security/open_basedir_symlink.phpt b/tests/security/open_basedir_symlink.phpt new file mode 100644 index 000000000..cdc8e7bcc --- /dev/null +++ b/tests/security/open_basedir_symlink.phpt @@ -0,0 +1,87 @@ +--TEST-- +Test open_basedir configuration +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die('skip no symlinks on Windows'); +} +?> +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +$initdir = getcwd(); +test_open_basedir_before("symlink"); + +$target = ($initdir."/test/ok/ok.txt"); +var_dump(symlink($target, "../bad/symlink.txt")); +var_dump(symlink($target, "../symlink.txt")); +var_dump(symlink($target, "../bad/./symlink.txt")); +var_dump(symlink($target, "./.././symlink.txt")); + +$symlink = ($initdir."/test/ok/symlink.txt"); +var_dump(symlink("../bad/bad.txt", $symlink)); +var_dump(symlink("../bad", $symlink)); +var_dump(symlink("../bad/./bad.txt", $symlink)); +var_dump(symlink("../bad/bad.txt", $symlink)); +var_dump(symlink("./.././bad", $symlink)); + +$target = ($initdir."/test/ok/ok.txt"); + +var_dump(symlink($target, $symlink)); +var_dump(unlink($symlink)); + +var_dump(mkdir("ok2")); +$symlink = ($initdir."/test/ok/ok2/ok.txt"); +var_dump(symlink("../ok.txt", $symlink)); // $target == (dirname($symlink)."/".$target) == ($initdir."/test/ok/ok.txt"); +var_dump(unlink($symlink)); + +test_open_basedir_after("symlink"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [symlink] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: symlink(): open_basedir restriction in effect. File(%s/test/bad/symlink.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: symlink(): open_basedir restriction in effect. File(%s/test/symlink.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: symlink(): open_basedir restriction in effect. File(%s/test/bad/symlink.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: symlink(): open_basedir restriction in effect. File(%s/test/symlink.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: symlink(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: symlink(): open_basedir restriction in effect. File(%s/test/bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: symlink(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: symlink(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: symlink(): open_basedir restriction in effect. File(%s/test/bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +*** Finished testing open_basedir configuration [symlink] *** + diff --git a/tests/security/open_basedir_tempnam.phpt b/tests/security/open_basedir_tempnam.phpt new file mode 100644 index 000000000..fd63e2978 --- /dev/null +++ b/tests/security/open_basedir_tempnam.phpt @@ -0,0 +1,75 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +$initdir = getcwd(); +test_open_basedir_before("tempnam"); + +var_dump(tempnam("../bad", "test")); +var_dump(tempnam("..", "test")); +var_dump(tempnam("../", "test")); +var_dump(tempnam("/", "test")); +var_dump(tempnam("../bad/.", "test")); +var_dump(tempnam("./../.", "test")); +var_dump(tempnam("", "test")); + +//absolute test +$file = tempnam($initdir."/test/ok", "test"); +var_dump($file); +var_dump(unlink($file)); + +//relative test +$file = tempnam(".", "test"); +var_dump($file); +var_dump(unlink($file)); + +$file = tempnam("../ok", "test"); +var_dump($file); +var_dump(unlink($file)); + +test_open_basedir_after("tempnam"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [tempnam] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: tempnam(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: tempnam(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: tempnam(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: tempnam(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: tempnam(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: tempnam(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: tempnam(): open_basedir restriction in effect. File() is not within the allowed path(s): (.) in %s on line %d +bool(false) +string(%d) "%s" +bool(true) +string(%d) "%s" +bool(true) +string(%d) "%s" +bool(true) +*** Finished testing open_basedir configuration [tempnam] *** + diff --git a/tests/security/open_basedir_touch.phpt b/tests/security/open_basedir_touch.phpt new file mode 100644 index 000000000..3a8aee821 --- /dev/null +++ b/tests/security/open_basedir_touch.phpt @@ -0,0 +1,70 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +$initdir = getcwd(); +test_open_basedir_before("touch"); + +var_dump(touch("../bad")); +var_dump(touch("../bad/bad.txt")); +var_dump(touch("..")); +var_dump(touch("../")); +var_dump(touch("/")); +var_dump(touch("../bad/.")); +var_dump(touch("../bad/./bad.txt")); +var_dump(touch("./../.")); + +var_dump(touch($initdir."/test/ok/ok.txt")); +var_dump(touch("./ok.txt")); +var_dump(touch("ok.txt")); +var_dump(touch("../ok/ok.txt")); +var_dump(touch("../ok/./ok.txt")); + +test_open_basedir_after("touch"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [touch] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: touch(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: touch(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: touch(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: touch(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: touch(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: touch(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: touch(): open_basedir restriction in effect. File(../bad/./bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: touch(): open_basedir restriction in effect. File(./../.) is not within the allowed path(s): (.) in %s on line %d +bool(false) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +*** Finished testing open_basedir configuration [touch] *** + diff --git a/tests/security/open_basedir_unlink.phpt b/tests/security/open_basedir_unlink.phpt new file mode 100644 index 000000000..aeedac913 --- /dev/null +++ b/tests/security/open_basedir_unlink.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test open_basedir configuration +--INI-- +open_basedir=. +--FILE-- +<?php +require_once "open_basedir.inc"; +$initdir = getcwd(); +test_open_basedir_before("unlink"); + +var_dump(unlink("../bad/bad.txt")); +var_dump(unlink(".././bad/bad.txt")); +var_dump(unlink("../bad/../bad/bad.txt")); +var_dump(unlink("./.././bad/bad.txt")); +var_dump(unlink($initdir."/test/bad/bad.txt")); + +test_open_basedir_after("unlink"); +?> +--CLEAN-- +<?php +require_once "open_basedir.inc"; +delete_directories(); +?> +--EXPECTF-- +*** Testing open_basedir configuration [unlink] *** +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) + +Warning: unlink(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: unlink(): open_basedir restriction in effect. File(.././bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: unlink(): open_basedir restriction in effect. File(../bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: unlink(): open_basedir restriction in effect. File(./.././bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) + +Warning: unlink(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d +bool(false) +*** Finished testing open_basedir configuration [unlink] *** + |
