/home/lnzliplg/www/alt-php81-pecl-yaf_3.3.6-1.el8.tar
tests/086.phpt000064400000000440151730720430007120 0ustar00--TEST--
Check for Yaf_Response_HTTP::setRedirect in CLI
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php
$response = new Yaf_Response_HTTP(); 
var_dump($response->setRedirect('https://yourdomain.com'));
?>
--EXPECT--
bool(false)
tests/049.phpt000064400000006327151730720430007131 0ustar00--TEST--
Check for Sample application with exception
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=0
yaf.lowcase_path=0
yaf.use_namespace=0

--FILE--
<?php 
require "build.inc";
startup();

$config = array(
	"application" => array(
		"directory" => APPLICATION_PATH,
        "dispatcher" => array (
           "catchException" => true,
        ), 
        "library" => array(
        ),
	),
);

file_put_contents(APPLICATION_PATH . "/controllers/Error.php", <<<PHP
<?php
   class ErrorController extends Yaf_Controller_Abstract {
         public function errorAction(\$exception) {
            \$this->_view->msg = \$exception->getMessage();
         }
   }
PHP
);

file_put_contents(APPLICATION_PATH . "/Bootstrap.php", <<<PHP
<?php
   class Bootstrap extends Yaf_Bootstrap_Abstract {
        public function _initConfig(Yaf_Dispatcher \$dispatcher) {
            Yaf_Registry::set("config", Yaf_Application::app()->getConfig());
        }
        public function _initPlugin(Yaf_Dispatcher \$dispatcher) {
            \$dispatcher->registerPlugin(new TestPlugin());
        }
        public function _initReturn(Yaf_Dispatcher \$dispatcher) {
 //           \$dispatcher->returnResponse(true);
        }
   }
PHP
);

file_put_contents(APPLICATION_PATH . "/plugins/Test.php", <<<PHP
<?php
   class TestPlugin extends Yaf_Plugin_Abstract {
        public function routerStartup(Yaf_Request_Abstract \$request, Yaf_Response_Abstract \$response) {
            var_dump("routerStartup");
        }
        public function routerShutdown(Yaf_Request_Abstract \$request, Yaf_Response_Abstract \$response) {
            var_dump("routerShutdown");
        }
        public function dispatchLoopStartup(Yaf_Request_Abstract \$request, Yaf_Response_Abstract \$response) {
            var_dump("dispatchLoopStartup");
        }
        public function preDispatch(Yaf_Request_Abstract \$request, Yaf_Response_Abstract \$response) {
            var_dump("preDispatch");
        }
        public function postDispatch(Yaf_Request_Abstract \$request, Yaf_Response_Abstract \$response) {
            var_dump("postDispatch");
        }
        public function dispatchLoopShutdown(Yaf_Request_Abstract \$request, Yaf_Response_Abstract \$response) {
            var_dump("dispatchLoopShutdown");
        }
   }
PHP
);

file_put_contents(APPLICATION_PATH . "/controllers/Index.php", <<<PHP
<?php
   class IndexController extends Yaf_Controller_Abstract {
         public function init() {
            var_dump("init");
         }
         public function indexAction() {
            var_dump("action");
         }
   }
PHP
);

file_put_contents(APPLICATION_PATH . "/views/index/index.phtml",
                "<?php throw new Exception('view exception'); ?>");

mkdir(APPLICATION_PATH . "/views/error/");
file_put_contents(APPLICATION_PATH . "/views/error/error.phtml",
                "catched: <?=\$msg?>");

$app = new Yaf_Application($config);
$app->bootstrap()->run();
?>
--CLEAN--
<?php
/* unlink foo2.phtml permission denied */
require "build.inc"; 
shutdown();
?>
--EXPECTF--
string(13) "routerStartup"
string(14) "routerShutdown"
string(19) "dispatchLoopStartup"
string(11) "preDispatch"
string(4) "init"
string(6) "action"
catched: view exception
tests/bug63438.phpt000064400000002502151730720430007771 0ustar00--TEST--
Bug #63438 (Strange behavior with nested rendering)
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=1
yaf.lowcase_path=0
yaf.use_namespace=0
--FILE--
<?php

function shut_down() {
   echo "done";
}

register_shutdown_function("shut_down");

function view($file){
    static $view;
   
    $view = new Yaf_View_Simple(dirname(__FILE__));
    return $view->render($file);
}

file_put_contents(dirname(__FILE__) . '/outer.phtml', "1 <?php print view('inner.phtml');?> 3\n");
file_put_contents(dirname(__FILE__) . '/inner.phtml', "2");
print (view('outer.phtml'));

file_put_contents(dirname(__FILE__) . '/outer.phtml', "1 <?php \$this->display('inner.phtml');?> 3\n");
print (view('outer.phtml'));

file_put_contents(dirname(__FILE__) . '/outer.phtml', "1 <?php echo \$this->eval('2');?> 3\n");
print (view('outer.phtml'));

file_put_contents(dirname(__FILE__) . '/outer.phtml', "1 <?php \$this->display('inner.phtml');?> 3\n");
file_put_contents(dirname(__FILE__) . '/inner.phtml', "<?php undefined_function(); ?>");
print (view('outer.phtml'));
?>
--CLEAN--
<?php
@unlink(dirname(__FILE__) . '/outer.phtml');
@unlink(dirname(__FILE__) . '/inner.phtml');
?>
--EXPECTF--
1 2 3
1 2 3
1 2 3

Fatal error: Uncaught Error: Call to undefined function undefined_function() in %sinner.phtml:%d
%a
done
tests/004.phpt000064400000000742151730720430007113 0ustar00--TEST--
Check for Yaf_Registry APIs
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php 
$str = "Ageli Platform";

Yaf_Registry::set("name",  $str);
unset($str);

var_dump(Yaf_Registry::get("name"));
var_dump(Yaf_Registry::has("name"));

$name = "name";

Yaf_Registry::del($name);

var_dump(Yaf_Registry::get($name));

var_dump(Yaf_Registry::has($name));

?>
--EXPECT--
string(14) "Ageli Platform"
bool(true)
NULL
bool(false)
tests/108.phpt000064400000002620151730720430007115 0ustar00--TEST--
Check for auto response with ErrorController
--SKIPIF--
<?php 
if (!extension_loaded("json")) die("skip, json required");
if (!extension_loaded("yaf")) die("skip");
 ?>
--EXTENSIONS--
json
--INI--
yaf.use_spl_autoload=0
yaf.lowcase_path=0
yaf.use_namespace=0
--FILE--
<?php
require "build.inc";
startup();

$config = array(
	"application" => array(
		"directory" => APPLICATION_PATH,
        "dispatcher" => array (
           "catchException" => true,
        ), 
	),
);

file_put_contents(APPLICATION_PATH . "/controllers/Error.php", <<<PHP
<?php
   class ErrorController extends Yaf_Controller_Abstract {
         public function errorAction(\$exception) {
			\$response = \$this->getResponse(); 	
			\$response->setBody(json_encode(array(
										"code" => \$exception->getCode(),
										"msg" => \$exception->getMessage(),
									)
								));
			\$response->response();
			return false;
         }
   }
PHP
);

file_put_contents(APPLICATION_PATH . "/controllers/Index.php", <<<PHP
<?php
   class IndexController extends Yaf_Controller_Abstract {
         public function init() {
			Yaf_Dispatcher::getInstance()->returnResponse(true);
         }
   }
PHP
);

$app = new Yaf_Application($config);
$response = $app->run();
?>
--CLEAN--
<?php
/* unlink foo2.phtml permission denied */
require "build.inc"; 
shutdown();
?>
--EXPECTF--
{"code":%d,"msg":"There is no method indexAction in IndexController"}
tests/063.phpt000064400000002400151730720430007111 0ustar00--TEST--
Check for Yaf_Route_Rewrite with dynamic mvc
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php 
$request = new Yaf_Request_Http("/subdir/ctl/act/name/value");

$router = new Yaf_Router();

$route  = new Yaf_Route_Rewrite(
	"/subdir/:con/:a/*",
	array(
        "module" => "m",
        "controller" => ":1",
		"action" => ":a",
	)
);

$router->addRoute("subdir", $route)->addRoute("yaf", new Yaf_Route_Rewrite(
	"/yaf/:action/*",
    array(
		"action" => ':action',
        "controller" => "index",
	)
))->route($request);

var_dump($router->getCurrentRoute());
print_r($request->getParams());
var_dump($request->getActionName());
var_dump($request->getControllerName());
var_dump($request->getModuleName());

$request = new Yaf_Request_Http("/yaf/act/name/value");
$router->route($request);

var_dump($router->getCurrentRoute());
print_r($request->getParams());
var_dump($request->getActionName());
var_dump($request->getControllerName());
var_dump($request->getModuleName());

?>
--EXPECTF--
string(6) "subdir"
Array
(
    [con] => ctl
    [a] => act
    [name] => value
)
string(3) "act"
NULL
string(1) "M"
string(3) "yaf"
Array
(
    [action] => act
    [name] => value
)
string(3) "act"
string(5) "Index"
NULL
tests/bug61493.phpt000064400000000740151730720430007772 0ustar00--TEST--
Bug #61493 (Can't remove item when using unset() with a Yaf_Config_Simple instance)
--CREDITS--
littlemiaor at gmail dot com
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php

$config = new Yaf_Config_Simple(array(
    'foo' => 'bar',
), false);

unset($config['foo']);
print_r($config);
?>
--EXPECTF--
Yaf_Config_Simple Object
(
    [readonly:protected] => 
    [config:protected] => Array
        (
        )

)
tests/029.phpt000064400000000764151730720430007126 0ustar00--TEST--
Check for Yaf_View_Simple::get and clear
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.library="/php/global/dir"
yaf.use_namespace=0
--FILE--
<?php
$view = new Yaf_View_Simple(dirname(__FILE__));
$view->assign("a", "b");
$view->assign("b", "a");
print_r($view->get("a"));
print_r($view->get());
$view->clear("b");
print_r($view->get());
$view->clear();
print_r($view->get());
?>
--EXPECTF--
bArray
(
    [a] => b
    [b] => a
)
Array
(
    [a] => b
)
Array
(
)
tests/087.phpt000064400000003606151730720430007130 0ustar00--TEST--
Check for Yaf_Route_Map with arbitrary urls
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php
$url = array(
  "/", "/foo", "/foo/", "/foo///bar", "//foo//bar", "/foo/bar///",
  "/foo/bar/:", "/foo/bar/:/", "/foo///bar/:/name/laruence/age/32",
  "foo/bar/:dummy/value:/age/37",
);

$route = new Yaf_Route_Map(true);

foreach ($url as $u) {
   $req = new Yaf_Request_Http($u);
   $route->route($req);
   echo $u, " : ",  "m=>", $req->getModuleName(), " c=>", $req->getControllerName(), " a=>",  $req->getActionName();
   if (($args = $req->getParams())) {
       echo " args=>";
       foreach ($args as $k => $v) {
          echo $k , "->", $v , ",";
       }
   }
   echo "\n";
}

$route = new Yaf_Route_Map(false, ":");

foreach ($url as $u) {
   $req = new Yaf_Request_Http($u);
   $route->route($req);
   echo $u, " : ",  "m=>", $req->getModuleName(), " c=>", $req->getControllerName(), " a=>",  $req->getActionName();
   if (($args = $req->getParams())) {
       echo " args=>";
       foreach ($args as $k => $v) {
          echo $k , "->", $v , ",";
       }
   }
   echo "\n";
}
--EXPECT--
/ : m=> c=> a=>
/foo : m=> c=>Foo a=>
/foo/ : m=> c=>Foo a=>
/foo///bar : m=> c=>Foo_Bar a=>
//foo//bar : m=> c=>Foo_Bar a=>
/foo/bar/// : m=> c=>Foo_Bar a=>
/foo/bar/: : m=> c=>Foo_Bar_: a=>
/foo/bar/:/ : m=> c=>Foo_Bar_: a=>
/foo///bar/:/name/laruence/age/32 : m=> c=>Foo_Bar_:_Name_Laruence_Age_32 a=>
foo/bar/:dummy/value:/age/37 : m=> c=>Foo_Bar_:dummy_Value:_Age_37 a=>
/ : m=> c=> a=>
/foo : m=> c=> a=>foo
/foo/ : m=> c=> a=>foo
/foo///bar : m=> c=> a=>foo_bar
//foo//bar : m=> c=> a=>foo_bar
/foo/bar/// : m=> c=> a=>foo_bar
/foo/bar/: : m=> c=> a=>foo_bar
/foo/bar/:/ : m=> c=> a=>foo_bar
/foo///bar/:/name/laruence/age/32 : m=> c=> a=>foo_bar args=>name->laruence,age->32,
foo/bar/:dummy/value:/age/37 : m=> c=> a=>foo_bar args=>dummy->value:,age->37,
tests/090.phpt000064400000004156151730720430007123 0ustar00--TEST--
Check for view path generating
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=0
yaf.lowcase_path=0
yaf.use_namespace=0
--FILE--
<?php
require "build.inc";
startup();

$config = array(
	"application" => array(
		"directory" => APPLICATION_PATH,
	),
);

file_put_contents(APPLICATION_PATH . "/controllers/Index.php", <<<PHP
<?php
   class IndexController extends Yaf_Controller_Abstract {
         public function indexAction() {
         }
         public function foo_bar_indexAction() {
         }
   }
PHP
);

file_put_contents(APPLICATION_PATH . "/views/index/index.phtml", "<?php var_dump('Index'); ?>");

$app = new Yaf_Application($config);


$app->getDispatcher()->getRouter()->AddRoute("map", new Yaf_Route_Map(true));

$request = new Yaf_Request_Http("/");
$app->getDispatcher()->dispatch($request);

/* Foo_Bar_Index controller */
mkdir(APPLICATION_PATH . "/controllers/Foo");
mkdir(APPLICATION_PATH . "/controllers/Foo/Bar");
file_put_contents(APPLICATION_PATH . "/controllers/Foo/Bar/Index.php", <<<PHP
<?php
   class Foo_Bar_IndexController extends Yaf_Controller_Abstract {
         public function indexAction() {
         }
   }
PHP
);

mkdir(APPLICATION_PATH . "/views/foo");
mkdir(APPLICATION_PATH . "/views/foo/bar");
mkdir(APPLICATION_PATH . "/views/foo/bar/index");
file_put_contents(APPLICATION_PATH . "/views/foo/bar/index/index.phtml", "<?php var_dump('CFoo_Bar_Index'); ?>");
$request = new Yaf_Request_Http("/Foo/Bar/Index");
$app->getDispatcher()->dispatch($request);

/* Foo_Bar_Index action */
mkdir(APPLICATION_PATH . "/views/index/foo");
mkdir(APPLICATION_PATH . "/views/index/foo/bar");
file_put_contents(APPLICATION_PATH . "/views/index/foo/bar/index.phtml", "<?php var_dump('AFoo_Bar_Index'); ?>");
$app->getDispatcher()->getRouter()->AddRoute("map", new Yaf_Route_Map(false));

$app->getDispatcher()->getRequest()->setDispatched(false)->setRouted(false)->setControllerName("Index");
$app->getDispatcher()->dispatch($request);

?>
--CLEAN--
<?php
require "build.inc"; 
shutdown();
?>
--EXPECT--
string(5) "Index"
string(14) "CFoo_Bar_Index"
string(14) "AFoo_Bar_Index"
tests/094.phpt000064400000004245151730720430007126 0ustar00--TEST--
Check for Yaf_Request read/write property
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=0
yaf.use_namespace=0
--FILE--
<?php

function ref_change(&$val) {
	$val = "bad";
}

$request = new Yaf_Request_Simple();

foreach (array("method", "module", "controller", "action", "uri", "base_uri", "language", 123) as $k) {
	print "Testing $k:\n";
	var_dump(@$request->{$k});
	$request->{$k} = true;
	if (phpversion() >='8.0.0' && $k==123) {
    	unset($request->{$k});
    }
	var_dump(@$request->{$k});
	$request->{$k} = "inDex";
	ref_change($request->{$k});
	if (phpversion() >='8.0.0' && $k==123) {
        unset($request->{$k});
     }
	var_dump(@$request->{$k});
	echo "\n";
}

var_dump($request);
?>
--EXPECTF--
Testing method:
string(3) "CLI"
string(3) "CLI"
string(5) "inDex"

Testing module:
NULL
NULL
string(5) "Index"

Testing controller:
NULL
NULL
string(5) "Index"

Testing action:
NULL
NULL
string(5) "index"

Testing uri:
string(0) ""

Warning: main(): Modification of Yaf_Request internal property 'uri' is not allowed in %s094.php on line %d
string(0) ""

Warning: main(): Modification of Yaf_Request internal property 'uri' is not allowed in %s094.php on line %d
string(0) ""

Testing base_uri:
NULL

Warning: main(): Modification of Yaf_Request internal property 'base_uri' is not allowed in %s094.php on line %d
NULL

Warning: main(): Modification of Yaf_Request internal property 'base_uri' is not allowed in %s094.php on line %d
NULL

Testing language:
NULL

Warning: main(): Modification of Yaf_Request internal property 'language' is not allowed in %s094.php on line %d
NULL

Warning: main(): Modification of Yaf_Request internal property 'language' is not allowed in %s094.php on line %d
NULL

Testing 123:
NULL
NULL
NULL

object(Yaf_Request_Simple)#1 (10) {
  ["method"]=>
  string(5) "inDex"
  ["module"]=>
  string(5) "Index"
  ["controller"]=>
  string(5) "Index"
  ["action"]=>
  string(5) "index"
  ["uri:protected"]=>
  string(0) ""
  ["base_uri:protected"]=>
  NULL
  ["dispatched:protected"]=>
  bool(false)
  ["routed:protected"]=>
  bool(false)
  ["language:protected"]=>
  string(0) ""
  ["params:protected"]=>
  array(0) {
  }
}tests/106.phpt000064400000003565151730720430007124 0ustar00--TEST--
Check for PSR-4 autoloading 
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=0
yaf.lowcase_path=0
yaf.use_namespace=0
--FILE--
<?php 
require "build.inc";
startup();
$config = array(
	"application" => array(
		"directory" => APPLICATION_PATH,
		"library" => array(
			"namespace" => array(
				"\Zend" => "/lib/Zend/foo",
				"\Microsoft\PHP" => "/var/lib/microsoft",
				"\Microsoft\ASP" => "/var/lib/asp",
			)
		),
	),
);
$app = new Yaf_Application($config);
$loader = Yaf_Loader::getInstance();
var_dump($loader->getNamespaces());
var_dump($loader->getNamespacePath("\Zend\Foo\Dummy"));
var_dump($loader->getNamespacePath("\Microsoft\Java"));
var_dump($loader->getNamespacePath("\Microsoft\PHP\Framework"));

$loader->registerNamespace("\Google\Robot", "/library/vendor/lib/robot");
var_dump($loader->getNamespacePath("Google\Robot"));

var_dump(class_exists("\Microsoft\PHP\Framework\Dummy"));
var_dump(class_exists("\Microsoft\ASP\Framework\Dummy"));
var_dump(class_exists("\Zend\Foo\Dummy\Bar"));
?>
--CLEAN--
<?php
require "build.inc"; 
shutdown();
?>
--EXPECTF--
array(2) {
  ["Zend"]=>
  string(13) "/lib/Zend/foo"
  ["Microsoft"]=>
  array(2) {
    ["PHP"]=>
    string(18) "/var/lib/microsoft"
    ["ASP"]=>
    string(12) "/var/lib/asp"
  }
}
string(13) "/lib/Zend/foo"
string(%d) "%sapplication%clibrary"
string(18) "/var/lib/microsoft"
string(%d) "%sapplication%clibrary"

Warning: Yaf_Loader::autoload(): Failed opening script /var/lib/microsoft%cFramework%cDummy.php: No such file or directory in %s106.php on line %d
bool(false)

Warning: Yaf_Loader::autoload(): Failed opening script /var/lib/asp%cFramework%cDummy.php: No such file or directory in %s106.php on line %d
bool(false)

Warning: Yaf_Loader::autoload(): Failed opening script /lib/Zend/foo%cFoo%cDummy%cBar.php: No such file or directory in %s106.php on line %d
bool(false)
tests/102.phpt000064400000003117151730720430007111 0ustar00--TEST--
Check for yaf.forward_limit
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
yaf.forward_limit = 10;
--FILE--
<?php 
$config = array(
	"application" => array(
		"directory" => realpath(dirname(__FILE__)),
        "modules" => "module",
	),
);

class ControllerController extends Yaf_Controller_Abstract {
    public function actionAction($from = NULL) {
		if (!$from) {
			print "starting\n";
		} else {
			var_dump($from);
		}
		$this->forward("module", "controller", "index", array("from" => __METHOD__));
		return false;
    }

    public function indexAction($from) {
		var_dump($from);
        $this->forward("dummy", array("from" => __METHOD__));
		return false;
    }

    public function dummyAction($from) {
		var_dump($from);
		$this->forward("controller", "action", array("from" => __METHOD__));
		return false;
    }
}


$app = new Yaf_Application($config);
$request = new Yaf_Request_Http("/module/controller/action");

try {
  $app->getDispatcher()->returnResponse(false)->dispatch($request);
} catch (Yaf_Exception $e) {
  echo $e->getMessage(), "\n";
}
?>
--EXPECTF--
starting
string(34) "ControllerController::actionAction"
string(33) "ControllerController::indexAction"
string(33) "ControllerController::dummyAction"
string(34) "ControllerController::actionAction"
string(33) "ControllerController::indexAction"
string(33) "ControllerController::dummyAction"
string(34) "ControllerController::actionAction"
string(33) "ControllerController::indexAction"
string(33) "ControllerController::dummyAction"
The maximum dispatching count 10 is reached
tests/058.phpt000064400000001121151730720430007114 0ustar00--TEST--
check for Yaf_Dispatcher::flushInstantly
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=0
yaf.lowcase_path=0
yaf.environ="product"
yaf.use_namespace=0
--FILE--
<?php
define("APPLICATION_PATH", dirname(__FILE__));
$app = new Yaf_Application(APPLICATION_PATH . '/simple.ini');
Yaf_Dispatcher::getInstance()->flushInstantly(true);
var_dump(Yaf_Dispatcher::getInstance()->flushInstantly());
Yaf_Dispatcher::getInstance()->flushInstantly(false);
var_dump(Yaf_Dispatcher::getInstance()->flushInstantly());
?>
--EXPECTF--
bool(true)
bool(false)
tests/084.phpt000064400000002552151730720430007124 0ustar00--TEST--
Check request methods
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php 

function checkMethod($method) {
	$request = new Yaf_Request_Simple($method, "index", "dummy", NULL, array());
	echo "checking {$method}...\n";
	var_dump($request->isGet());
	var_dump($request->isPost());
	var_dump($request->isHead());
	var_dump($request->isDelete());
	var_dump($request->isPut());
	var_dump($request->isOptions());
	var_dump($request->isPatch());
	return;
}

checkMethod("GET");
checkMethod("POST");
checkMethod("HEAD");
checkMethod("DELETE");
checkMethod("PUT");
checkMethod("OPTIONS");
checkMethod("PATCH");
?>
--EXPECTF--
checking GET...
bool(true)
bool(false)
bool(false)
bool(false)
bool(false)
bool(false)
bool(false)
checking POST...
bool(false)
bool(true)
bool(false)
bool(false)
bool(false)
bool(false)
bool(false)
checking HEAD...
bool(false)
bool(false)
bool(true)
bool(false)
bool(false)
bool(false)
bool(false)
checking DELETE...
bool(false)
bool(false)
bool(false)
bool(true)
bool(false)
bool(false)
bool(false)
checking PUT...
bool(false)
bool(false)
bool(false)
bool(false)
bool(true)
bool(false)
bool(false)
checking OPTIONS...
bool(false)
bool(false)
bool(false)
bool(false)
bool(false)
bool(true)
bool(false)
checking PATCH...
bool(false)
bool(false)
bool(false)
bool(false)
bool(false)
bool(false)
bool(true)
tests/005.phpt000064400000001653151730720430007116 0ustar00--TEST--
Check for Yaf_Response_Cli APIs
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php 
$response = new Yaf_Response_Cli();


$body  = <<<HTML
yaf
HTML;

$string = "header|";

$response->appendBody($body);
$response->prependBody($string);
$response->appendBody("|footer");

$body = $response->getBody();
unset($body);

var_dump(Yaf_Response_Abstract::DEFAULT_BODY);
print_r($response->getBody(NULL));
var_dump($response->getBody(Yaf_Response_Http::DEFAULT_BODY));
unset($string);
var_dump($response->getBody());
echo($response);
echo "\n";
var_dump($response->getBody());
$response->response();
echo "\n";
var_dump($response->getBody());
?>
--EXPECTF--
string(7) "content"
Array
(
    [content] => header|yaf|footer
)
string(17) "header|yaf|footer"
string(17) "header|yaf|footer"
header|yaf|footer
string(17) "header|yaf|footer"
header|yaf|footer
string(17) "header|yaf|footer"
tests/079.phpt000064400000001605151730720440007127 0ustar00--TEST--
Autoloading the classes under library
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=0
yaf.lowcase_path=0
yaf.use_namespace=0
--FILE--
<?php 
require "build.inc";
startup();

$config = array(
	"application" => array(
		"directory" => APPLICATION_PATH,
	),
);

file_put_contents(APPLICATION_PATH . "/Bootstrap.php", <<<PHP
<?php
   class Bootstrap extends Yaf_Bootstrap_Abstract {
       public function _initTest() {
			Yaf_Loader::getInstance()->registerLocalNamespace("Test");
			Yaf_Registry::set("test", new Test());
       }
   }
PHP
);

file_put_contents(APPLICATION_PATH . "/library/Test.php", <<<PHP
<?php
class Test {
	public function __construct() {
		var_dump("okey");
	}
}
PHP
);

$app = new Yaf_Application($config);
$response = $app->bootstrap();
?>
--CLEAN--
<?php
require "build.inc"; 
shutdown();
?>
--EXPECTF--
string(4) "okey"
tests/003.phpt000064400000002373151730720440007115 0ustar00--TEST--
Check for Yaf_Loader local names
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=0
yaf.lowcase_path=0
yaf.use_namespace=0
--FILE--
<?php 
ini_set("ap.lowcase_path", FALSE);
$loader = Yaf_Loader::getInstance(dirname(__FILE__), dirname(__FILE__) . "/global");
$loader->registerLocalNamespace("Baidu");
$loader->registerLocalNamespace("Sina");
$loader->registerLocalNamespace(array("Wb", "Inf", NULL, array(), "123"));
var_dump($loader->getLocalNamespace());
var_dump($loader->isLocalName("Baidu_Name"));
var_dump($loader->isLocalName("Inf\\Name"));

try {
	var_dump($loader->autoload("Baidu_Name"));
} catch (Yaf_Exception_LoadFailed $e) {
	var_dump($e->getMessage());
} 
try {
	var_dump($loader->autoload("Global_Name"));
} catch (Yaf_Exception_LoadFailed $e) {
	var_dump($e->getMessage());
} 

?>
--EXPECTF--
array(5) {
  [0]=>
  string(5) "Baidu"
  [1]=>
  string(4) "Sina"
  [2]=>
  string(2) "Wb"
  [3]=>
  string(3) "Inf"
  [4]=>
  string(3) "123"
}
bool(true)
bool(true)

Warning: Yaf_Loader::autoload(): Failed opening script %sBaidu%cName.php: No such file or directory in %s
bool(true)

Warning: Yaf_Loader::autoload(): Failed opening script %sglobal%cGlobal%cName.php: No such file or directory in %s
bool(true)
tests/018.phpt000064400000004454151730720440007125 0ustar00--TEST--
Bug Yaf_Config_Ini crash due to inaccurate refcount
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php 
$file = dirname(__FILE__) . "/simple.ini";
$config = new Yaf_Config_Ini($file, 'base');
print_r($config);
?>
--EXPECTF--
Yaf_Config_Ini Object
(
    [readonly:protected] => 1
    [config:protected] => Array
        (
            [application] => Array
                (
                    [directory] => APPLICATION_PATH/applcation
                )

            [name] => base
            [array] => Array
                (
                    [1] => 1
                    [name] => name
                )

            [5] => 5
            [routes] => Array
                (
                    [regex] => Array
                        (
                            [type] => regex
                            [match] => ^/ap/(.*)
                            [route] => Array
                                (
                                    [controller] => Index
                                    [action] => action
                                )

                            [map] => Array
                                (
                                    [0] => name
                                    [1] => name
                                    [2] => value
                                )

                        )

                    [simple] => Array
                        (
                            [type] => simple
                            [controller] => c
                            [module] => m
                            [action] => a
                        )

                    [supervar] => Array
                        (
                            [type] => supervar
                            [varname] => c
                        )

                    [rewrite] => Array
                        (
                            [type] => rewrite
                            [match] => /yaf/:name/:value
                            [route] => Array
                                (
                                    [controller] => Index
                                    [action] => action
                                )

                        )

                )

        )

    [filename:protected] => %s
)
tests/021.phpt000064400000001040151730720440007103 0ustar00--TEST--
Check for Yaf_Application error handler
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php 
define("APPLICATION_PATH", dirname(__FILE__));
$app = new Yaf_Application(
	dirname(__FILE__) . "/simple.ini",
	'nocatch');

function error_handler($errno, $errstr, $errfile, $errline) {
	echo "error occurrd instead of exception threw";
}

$app->getDispatcher()->setErrorHandler("error_handler", E_RECOVERABLE_ERROR);
$app->run();
?>
--EXPECTF--
error occurrd instead of exception threw
tests/051.phpt000064400000001221151730720440007107 0ustar00--TEST--
Fixed bug that segfault while a abnormal object set to Yaf_Route*::route
--SKIPIF--
<?php if (!extension_loaded("yaf") || phpversion() >='8.0.0') print "skip"; ?>
--INI--
yaf.use_spl_autoload=0
yaf.lowcase_path=0
yaf.use_namespace=0
--FILE--
<?php
error_reporting(E_ALL & ~E_WARNING);
$x = new Yaf_Route_Map(true);
$x->route($x);

$x = new Yaf_Route_Static();
$x->route($x);

$x = new Yaf_Route_Rewrite("#^/test#", array("controller" => "info"), array());
$x->route($x);

$x = new Yaf_Route_Supervar("r");
$x->route($x);

$x = new Yaf_Route_Regex("#^/test#", array("controller" => "info"), array());
$x->route($x);

echo "okey";
?>
--EXPECTF--
okeytests/007.phpt000064400000003405151730720440007116 0ustar00--TEST--
Check for Yaf_Config_Simple APIs
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php
$config = array(
	'section1' => array(
		'name' => 'value',
		'dummy' =>  'foo',
	),
	'section2' => "laruence",
);

$config1 = new Yaf_Config_Simple($config, true);
print_r($config1);
$config2 = new Yaf_Config_Simple($config, true);
var_dump($config2->readonly());
$config2->new = "value";
var_dump(isset($config->new));
$config3 = new Yaf_Config_Simple($config);
unset($config);

echo "Isset config3 section:";
var_dump(isset($config3["section2"]));
$config3->new = "value";
echo "Config3 readonly:";
var_dump($config3->readonly());

foreach($config3 as $key => $val) {
}

foreach($config3 as $key => $val) {
	print_r($key);
	print_r("=>");
	print_r($val);
	print_r("\n");
}

print_r($config3->toArray());

$sick = @new Yaf_Config_Simple([]);

var_dump($sick->__isset(1));
var_dump($sick->__get(2));
$sick->total = 1;
var_dump(count($sick));
var_dump($sick->total);
?>
--EXPECTF--
Yaf_Config_Simple Object
(
    [readonly:protected] => 1
    [config:protected] => Array
        (
            [section1] => Array
                (
                    [name] => value
                    [dummy] => foo
                )

            [section2] => laruence
        )

)
bool(true)
bool(false)
Isset config3 section:bool(true)
Config3 readonly:bool(false)
section1=>Yaf_Config_Simple Object
(
    [readonly:protected] => 
    [config:protected] => Array
        (
            [name] => value
            [dummy] => foo
        )

)

section2=>laruence
new=>value
Array
(
    [section1] => Array
        (
            [name] => value
            [dummy] => foo
        )

    [section2] => laruence
    [new] => value
)
bool(false)
NULL
int(1)
int(1)
tests/013.phpt000064400000005517151730720440007121 0ustar00--TEST--
Check for Yaf_Router and Config Routes
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php 
$file = dirname(__FILE__) . "/simple.ini";

$config = new Yaf_Config_Ini($file, 'extra');

$routes = $config->routes;
print_r($routes);

$router = new Yaf_Router();
$router->addConfig($routes);

print_r($router->getRoutes());
?>
--EXPECTF--
Yaf_Config_Ini Object
(
    [readonly:protected] => 1
    [config:protected] => Array
        (
            [regex] => Array
                (
                    [type] => regex
                    [match] => ^/ap/(.*)
                    [route] => Array
                        (
                            [controller] => Index
                            [action] => action
                        )

                    [map] => Array
                        (
                            [0] => name
                            [1] => name
                            [2] => value
                        )

                )

            [simple] => Array
                (
                    [type] => simple
                    [controller] => c
                    [module] => m
                    [action] => a
                )

            [supervar] => Array
                (
                    [type] => supervar
                    [varname] => c
                )

            [rewrite] => Array
                (
                    [type] => rewrite
                    [match] => /yaf/:name/:value
                    [route] => Array
                        (
                            [controller] => Index
                            [action] => action
                        )

                )

        )

)
Array
(
    [_default] => Yaf_Route_Static Object
        (
        )

    [regex] => Yaf_Route_Regex Object
        (
            [match:protected] => ^/ap/(.*)
            [route:protected] => Array
                (
                    [controller] => Index
                    [action] => action
                )

            [map:protected] => Array
                (
                    [0] => name
                    [1] => name
                    [2] => value
                )

            [verify:protected] => 
            [reverse:protected] => 
        )

    [simple] => Yaf_Route_Simple Object
        (
            [module:protected] => m
            [controller:protected] => c
            [action:protected] => a
        )

    [supervar] => Yaf_Route_Supervar Object
        (
            [varname:protected] => c
        )

    [rewrite] => Yaf_Route_Rewrite Object
        (
            [match:protected] => /yaf/:name/:value
            [route:protected] => Array
                (
                    [controller] => Index
                    [action] => action
                )

            [verify:protected] => 
        )

)
tests/091.phpt000064400000002075151730720440007123 0ustar00--TEST--
Check for Yaf_Request_getXXX
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=0
yaf.lowcase_path=0
yaf.use_namespace=0
--GET--
name=get
--POST--
name=raw
--FILE--
<?php
$_SERVER["name"] = "server";
$_COOKIE["name"] = "cookie";
$_POST["name"] = "post";
$_ENV["name"] = "env";
$_REQUEST["name"] = "request";

$request = new Yaf_Request_Http("/");

var_dump($request->getServer("name"));
var_dump($request->getQuery("name"));
var_dump($request->getCookie("name"));
var_dump($request->getPost("name"));
var_dump($request->getEnv("name"));
var_dump($request->getRequest("name"));
var_dump($request->getRaw());

var_dump(count($request->getServer()));
var_dump(count($request->getQuery()));
var_dump(count($request->getCookie()));
var_dump(count($request->getPost()));
var_dump(count($request->getEnv()));
var_dump(count($request->getRequest()));
?>
--EXPECTF--
string(6) "server"
string(3) "get"
string(6) "cookie"
string(4) "post"
string(3) "env"
string(7) "request"
string(8) "name=raw"
int(%d)
int(%d)
int(%d)
int(%d)
int(%d)
int(%d)
tests/024.phpt000064400000001243151730720440007113 0ustar00--TEST--
Check for Yaf_Loader::getInstace() paramters
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.library="/php/global/dir"
yaf.use_namespace=0
--FILE--
<?php 
$loader = Yaf_Loader::getInstance('/foo');

var_dump($loader->getLibraryPath());
var_dump($loader->getLibraryPath(TRUE));
$config = array(
	"application" => array(
		"directory" => realpath(dirname(__FILE__)),
	),
);

$app = new Yaf_Application($config);
$loader = Yaf_Loader::getInstance(NULL, '/bar');
var_dump($loader->getLibraryPath());
var_dump($loader->getLibraryPath(TRUE));
?>
--EXPECTF--
string(4) "/foo"
string(15) "/php/global/dir"
string(%d) "%slibrary"
string(4) "/bar"
tests/023.phpt000064400000003176151730720440007121 0ustar00--TEST--
Check for Yaf_Loader::set/get(library_path)
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=0
yaf.lowcase_path=0
yaf.use_namespace=0
--FILE--
<?php 
$loader = Yaf_Loader::getInstance('/foo', '/bar');
$loader->registerLocalNamespace(array("Foo"));

$loader->autoload("Foo_Bar");
$loader->autoload("Bar_Foo");

$loader->setLibraryPath("/foobar", FALSE);
$loader->autoload("Foo_Bar");
$loader->autoload("Bar_Foo");

$loader->setLibraryPath("/foobar", TRUE);
$loader->autoload("Foo_Bar");
$loader->autoload("Bar_Foo");

$loader->autoload("Model");
$loader->autoload("Bar_Model");
?>
--EXPECTF--
Warning: Yaf_Loader::autoload(): Failed opening script /foo%cFoo%cBar.php: No such file or directory in %s023.php on line %d

Warning: Yaf_Loader::autoload(): Failed opening script /bar%cBar%cFoo.php: No such file or directory in %s023.php on line %d

Warning: Yaf_Loader::autoload(): Failed opening script /foobar%cFoo%cBar.php: No such file or directory in %s023.php on line %d

Warning: Yaf_Loader::autoload(): Failed opening script /bar%cBar%cFoo.php: No such file or directory in %s023.php on line %d

Warning: Yaf_Loader::autoload(): Failed opening script /foobar%cFoo%cBar.php: No such file or directory in %s023.php on line %d

Warning: Yaf_Loader::autoload(): Failed opening script %cfoobar%cBar%cFoo.php: No such file or directory in %s023.php on line %d

Warning: Yaf_Loader::autoload(): Failed opening script %cfoobar%cModel.php: No such file or directory in %s023.php on line %d

Warning: Yaf_Loader::autoload(): Couldn't load a MVC class unless an Yaf_Application is initialized in %s023.php on line %d
tests/026.phpt000064400000001251151730720440007114 0ustar00--TEST--
Check for Yaf_Response::setBody/prependBody/appendBody
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.library="/php/global/dir"
yaf.use_namespace=0
--FILE--
<?php 
$response = new Yaf_Response_Http();
$response->setBody("ell")->appendBody("o")->setBody(" W", "footer")->prependBody("H")->appendBody("orld", "footer");
print_r($response);
echo $response;
?>
--EXPECTF--
Yaf_Response_Http Object
(
    [response_code:protected] => 0
    [header_sent:protected] => 
    [header:protected] => Array
        (
        )

    [body:protected] => Array
        (
            [content] => Hello
            [footer] =>  World
        )

)
Hello World
tests/097.phpt000064400000004775151730720440007142 0ustar00--TEST--
Check for Yaf_Route_Supervar with arbitrary urls
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php
$url = array(
  "/", "/foo", "/foo/", "/foo///bar", "foo/bar", "/foo/bar/",
  "/foo/bar/dummy", "/foo///bar/dummy/", "foo/bar/dummy/",
  "/my", "/my/", "/my/foo", "/my/foo/", "my/foo/bar", "my/foo/bar/",
  "/m/index/index", "/my/foo/bar/dummy/1", "my/foo/bar/dummy/1/a/2/////",
  "/my/index/index", "my/index", "/foo/index", "index/foo",
);

$config = array( 
    "application" => array(
        "directory" => '/tmp/',
        "modules"   => 'Index,My',
     ),
);

$app = new Yaf_Application($config);

$route = new Yaf_Route_Supervar("var");

foreach ($url as $u) {
   $_GET["var"] = $u;
   $req = new Yaf_Request_Http($u);
   $route->route($req);
   echo $u, " : ",  "m=>", $req->getModuleName(), " c=>", $req->getControllerName(), " a=>",  $req->getActionName();
   if (($args = $req->getParams())) {
       echo " args=>";
       foreach ($args as $k => $v) {
          echo $k , "->", $v , ",";
       }
   }
   echo "\n";
}

ini_set("yaf.action_prefer", 1);
$url = array(
  "/", "/foo", "/foo/",
  "/my", "/my/", "/my/foo", "/my//foo/", 
);

foreach ($url as $u) {
   $_GET["var"] = $u;
   $req = new Yaf_Request_Http($u);
   $route->route($req);
   echo $u, " : ",  "m=>", $req->getModuleName(), " c=>", $req->getControllerName(), " a=>",  $req->getActionName();
   if (($args = $req->getParams())) {
       echo " args=>";
       foreach ($args as $k => $v) {
          echo $k , "->", $v , ",";
       }
   }
   echo "\n";
}

?>
--EXPECTF--
/ : m=> c=> a=>
/foo : m=> c=>Foo a=>
/foo/ : m=> c=>Foo a=>
/foo///bar : m=> c=>Foo a=>bar
foo/bar : m=> c=>Foo a=>bar
/foo/bar/ : m=> c=>Foo a=>bar
/foo/bar/dummy : m=> c=>Foo a=>bar args=>dummy->,
/foo///bar/dummy/ : m=> c=>Foo a=>bar args=>dummy->,
foo/bar/dummy/ : m=> c=>Foo a=>bar args=>dummy->,
/my : m=> c=>My a=>
/my/ : m=> c=>My a=>
/my/foo : m=> c=>My a=>foo
/my/foo/ : m=> c=>My a=>foo
my/foo/bar : m=>My c=>Foo a=>bar
my/foo/bar/ : m=>My c=>Foo a=>bar
/m/index/index : m=> c=>M a=>index args=>index->,
/my/foo/bar/dummy/1 : m=>My c=>Foo a=>bar args=>dummy->1,
my/foo/bar/dummy/1/a/2///// : m=>My c=>Foo a=>bar args=>dummy->1,a->2,
/my/index/index : m=>My c=>Index a=>index
my/index : m=> c=>My a=>index
/foo/index : m=> c=>Foo a=>index
index/foo : m=> c=>Index a=>foo
/ : m=> c=> a=>
/foo : m=> c=> a=>foo
/foo/ : m=> c=> a=>foo
/my : m=> c=> a=>my
/my/ : m=> c=> a=>my
/my/foo : m=> c=>My a=>foo
/my//foo/ : m=> c=>My a=>foo
tests/issue420.phpt000064400000002244151730720440010166 0ustar00--TEST--
Issue #420 (bug in yaf_dispatcher_get_call_parameters)
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=1
yaf.lowcase_path=0
yaf.throw_exception=0
yaf.catch_exception=1
yaf.use_namespace=0
--FILE--
<?php 
require "build.inc";
startup();

$config = array(
	"application" => array(
		"directory" => APPLICATION_PATH,
	),
);

file_put_contents(APPLICATION_PATH . "/controllers/Index.php", <<<PHP
<?php
   class IndexController extends Yaf_Controller_Abstract {
		public function funcAction(\$a = 0, \$b = 1) {
			var_dump(\$a, \$b);
			return FALSE;
		}
   }
PHP
);

$app = new Yaf_Application($config);
$req = new Yaf_Request_Simple();
$req->setControllerName('Foo_Bar', false);
var_dump($req->getControllerName());
$req->setControllerName('index');
$req->setActionName('func');
$req->setParam(array('b' => 'the second param'));
$app->getDispatcher()->dispatch($req);
$req->clearParams();
$req->setParam(array('a' => 'the first param'));
$app->getDispatcher()->dispatch($req);
?>
--CLEAN--
<?php
require "build.inc"; 
shutdown();
?>
--EXPECT--
string(7) "Foo_Bar"
int(0)
string(16) "the second param"
string(15) "the first param"
int(1)
tests/103.phpt000064400000002620151730720440007111 0ustar00--TEST--
Check for Yaf_Request::set*Name 's second argument
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
yaf.forward_limit = 10;
--FILE--
<?php
$request = new Yaf_Request_Simple();

$request->setModuleName("foo", true);
var_dump($request->getModuleName());
$request->setModuleName("foo", false);
var_dump($request->getModuleName());
$request->setModuleName("foo_bAR", true);
var_dump($request->getModuleName());
$request->setModuleName("foo_bAR", false);
var_dump($request->getModuleName());


$request->setControllerName("foo", true);
var_dump($request->getControllerName());
$request->setControllerName("foo", false);
var_dump($request->getControllerName());
$request->setControllerName("foo_bAR", true);
var_dump($request->getControllerName());
$request->setControllerName("foo_bAR", false);
var_dump($request->getControllerName());

$request->setActionName("Foo", true);
var_dump($request->getActionName());
$request->setActionName("Foo", false);
var_dump($request->getActionName());
$request->setActionName("foo_bAR", true);
var_dump($request->getActionName());
$request->setActionName("foo_bAR", false);
var_dump($request->getActionName());
?>
--EXPECT--
string(3) "Foo"
string(3) "foo"
string(7) "Foo_Bar"
string(7) "foo_bAR"
string(3) "Foo"
string(3) "foo"
string(7) "Foo_Bar"
string(7) "foo_bAR"
string(3) "foo"
string(3) "Foo"
string(7) "foo_bar"
string(7) "foo_bAR"
tests/076.phpt000064400000001742151730720440007126 0ustar00--TEST--
Check for Yaf_Route_Supervar::assemble
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.throw_exception=1
yaf.use_namespace=0
--FILE--
<?php

$router = new Yaf_Router();

$route  = new Yaf_Route_Supervar('r');

$router->addRoute("supervar", $route);

var_dump($router->getRoute('supervar')->assemble(
		array(
		      ':a' => 'yafaction', 
		      'tkey' => 'tval', 
		      ':c' => 'yafcontroller', 
		      ':m' => 'yafmodule'
		), 
		array(
		      'tkey1' => 'tval1', 
		      'tkey2' => 'tval2'
		)
));

try { 
var_dump($router->getRoute('supervar')->assemble(
		array(
		      ':a' => 'yafaction', 
		      'tkey' => 'tval', 
		      ':m' => 'yafmodule'
		), 
		array(
		      'tkey1' => 'tval1', 
		      'tkey2' => 'tval2',
			  1 => array(),
		)
));
} catch (Exception $e) {
	var_dump($e->getMessage());
}
--EXPECTF--
string(%d) "?r=/yafmodule/yafcontroller/yafaction&tkey1=tval1&tkey2=tval2"
string(%d) "You need to specify the controller by ':c'"
tests/072.phpt000064400000003615151730720440007123 0ustar00--TEST--
check for Yaf_Response_Http headers function;
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php
$response = new Yaf_Response_Http();

var_dump($response->setHeader('MyName1', 'Header1'));
var_dump($response->setHeader('MyName2', 'Header2'));
var_dump($response->setHeader('MyName2', 'Header22'));
var_dump($response->setHeader('MyName1', 'Header11', false));
print_r($response);

var_dump($response->setHeader('MyName1', 'Header1'));
var_dump($response->setHeader('MyName3', 'Header31', false, 301));
var_dump($response->setHeader('MyName3', 'Header32', true, 302));
var_dump($response->setHeader('MyName1', 'Header2', false, 302));

var_dump($response->getHeader());
var_dump($response->getHeader('MyName'));
var_dump($response->getHeader('MyName1'));
print_r($response->clearHeaders());

$headers = array(
    'MyName1' => 'Header1x',
    'MyName2' => 'Header2x',
    'MyName3' => 12345
);
var_dump($response->setAllHeaders($headers));
var_dump($response->getHeader());

?>
--EXPECTF--
bool(true)
bool(true)
bool(true)
bool(true)
Yaf_Response_Http Object
(
    [response_code:protected] => 0
    [header_sent:protected] => 
    [header:protected] => Array
        (
            [MyName1] => Header1, Header11
            [MyName2] => Header22
        )

    [body:protected] => Array
        (
        )

)
bool(true)
bool(true)
bool(true)
bool(true)
array(3) {
  ["MyName1"]=>
  string(16) "Header1, Header2"
  ["MyName2"]=>
  string(8) "Header22"
  ["MyName3"]=>
  string(8) "Header32"
}
NULL
string(16) "Header1, Header2"
Yaf_Response_Http Object
(
    [response_code:protected] => 302
    [header_sent:protected] => 
    [header:protected] => Array
        (
        )

    [body:protected] => Array
        (
        )

)
bool(true)
array(3) {
  ["MyName1"]=>
  string(8) "Header1x"
  ["MyName2"]=>
  string(8) "Header2x"
  ["MyName3"]=>
  string(5) "12345"
}
tests/038.phpt000064400000001252151730720440007120 0ustar00--TEST--
Check for Yaf_View_Simple error message outputing
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.library="/php/global/dir"
log_errors=0
display_errors=1
yaf.use_namespace=0
--FILE--
<?php
require "build.inc";
startup();

$view = new Yaf_View_Simple(dirname(__FILE__));

$view->assign("name", "laruence");
$tpl  =  APPLICATION_PATH . '/tpls/foo.phtml';

file_put_contents($tpl, <<<HTML
<?php 
   if ((x) { //syntax errors
   } 
?>
HTML
);

echo $view->render($tpl);
?>
--CLEAN--
<?php
/* unlink foo2.phtml permission denied */
require "build.inc"; 
shutdown();
?>
--EXPECTF--
Parse error: syntax error, unexpected %s}%c in %sfoo.phtml on line %dtests/056.phpt000064400000001121151730720440007113 0ustar00--TEST--
check for Yaf_Dispatcher::throwException
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=0
yaf.lowcase_path=0
yaf.environ="product"
yaf.use_namespace=0
--FILE--
<?php
define("APPLICATION_PATH", dirname(__FILE__));
$app = new Yaf_Application(APPLICATION_PATH . '/simple.ini');
Yaf_Dispatcher::getInstance()->throwException(true);
var_dump(Yaf_Dispatcher::getInstance()->throwException());
Yaf_Dispatcher::getInstance()->throwException(false);
var_dump(Yaf_Dispatcher::getInstance()->throwException());
?>
--EXPECTF--
bool(true)
bool(false)
tests/062.phpt000064400000001242151730720440007114 0ustar00--TEST--
Check for Yaf_View_Simple and application's template directory
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.library="/php/global/dir"
yaf.use_namespace=0
--FILE--
<?php
$view = new Yaf_View_Simple(dirname(__FILE__));
try {
    $view = new Yaf_View_Simple("");
} catch (Yaf_Exception_TypeError $e) {
    var_dump($e->getMessage());
}

$config = array(
   "application" => array(
      "directory" => dirname(__FILE__),
   ),
);
$app = new Yaf_Application($config);

$view = Yaf_Dispatcher::getInstance()->initView("");
var_dump($view->getScriptPath());
?>
--EXPECTF--
string(%d) "Expects an absolute path for templates directory"
NULL
tests/006.phpt000064400000001555151730720440007121 0ustar00--TEST--
Check for Yaf_Route_Static routing
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php 
$request_uri = "/prefix/controller/action/name/laruence/age/28";
$base_uri	 = "/prefix/";

$request = new Yaf_Request_Http($request_uri, $base_uri);

unset($base_uri);
unset($request_uri);

$route = new Yaf_Route_Static();

var_dump($route->route($request));

print_r($request);
?>
--EXPECTF--
bool(true)
Yaf_Request_Http Object
(
    [method] => CLI
    [module] => 
    [controller] => Controller
    [action] => action
    [uri:protected] => /prefix/controller/action/name/laruence/age/28
    [base_uri:protected] => /prefix
    [dispatched:protected] => 
    [routed:protected] => 
    [language:protected] => 
    [params:protected] => Array
        (
            [name] => laruence
            [age] => 28
        )

)
tests/085.phpt000064400000000412151730720440007117 0ustar00--TEST--
Check Yaf_Request_Http::getRaw
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--POST--
a=b&c=d
--FILE--
<?php
$request = new Yaf_Request_Http("/");
var_dump($request->getRaw());
?>
--EXPECT--
string(7) "a=b&c=d"
tests/issue232.phpt000064400000000775151730720440010176 0ustar00--TEST--
ISSUE #232 (Segfault with Yaf_Route_Simple)
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.lowcase_path=0
yaf.throw_exception=0
yaf.catch_exception=1
yaf.use_namespace=0
--GET--
c=index
--FILE--
<?php 
$router = new Yaf_Route_Simple("m", "c", "a");
$request = new Yaf_Request_Http("/");
$router->route($request);
var_dump($request->getModuleName());
var_dump($request->getControllerName());
var_dump($request->getActionName());
?>
--EXPECTF--
NULL
string(5) "Index"
NULL
tests/050.phpt000064400000002124151730720440007111 0ustar00--TEST--
Check for Sample application with return response
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=0
yaf.lowcase_path=0
yaf.use_namespace=0

--FILE--
<?php 
require "build.inc";
startup();

$config = array(
	"application" => array(
		"directory" => APPLICATION_PATH,
	),
);

file_put_contents(APPLICATION_PATH . "/Bootstrap.php", <<<PHP
<?php
   class Bootstrap extends Yaf_Bootstrap_Abstract {
        public function _initReturn(Yaf_Dispatcher \$dispatcher) {
            \$dispatcher->returnResponse(true);
        }
   }
PHP
);

file_put_contents(APPLICATION_PATH . "/controllers/Index.php", <<<PHP
<?php
   class IndexController extends Yaf_Controller_Abstract {
         public function indexAction() {
         }
   }
PHP
);

file_put_contents(APPLICATION_PATH . "/views/index/index.phtml", "view");

$app = new Yaf_Application($config);
$response = $app->bootstrap()->run();
var_dump("-------");
echo $response;
?>
--CLEAN--
<?php
/* unlink foo2.phtml permission denied */
require "build.inc"; 
shutdown();
?>
--EXPECTF--
string(7) "-------"
view
tests/089.phpt000064400000002122151730720440007123 0ustar00--TEST--
Check for Yaf_Config_Ini gets
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php 
$file = dirname(__FILE__) . "/simple.ini";

define("APPLICATION_PATH", __DIR__);
$config = new Yaf_Config_Ini($file);
var_dump(count($config->base));
var_dump(gettype($config->base->application->directory));

var_dump($config->base->routes->rewrite->route->controller);
var_dump($config->base["routes"]["rewrite"]["route"]["controller"]);
var_dump($config->get("base.routes.rewrite.route.controller"));

var_dump($config->base->get("routes.rewrite.match"));
var_dump($config["base.routes.rewrite.route.controllers"]);

$config = new Yaf_Config_Ini($file, "nocatch");
var_dump(count($config));
var_dump($config->get("routes.rewrite.match"));
var_dump($config->application->dispatcher->throwException);
var_dump($config->application["dispatcher"]["catchException"]);
?>
--EXPECTF--
int(5)
string(6) "string"
string(5) "Index"
string(5) "Index"
string(5) "Index"
string(17) "/yaf/:name/:value"
NULL
int(6)
string(15) "/yaf/:name/:age"
string(0) ""
string(1) "1"
tests/011.phpt000064400000001422151730720450007107 0ustar00--TEST--
Check for Yaf_Route_Rewrite routing
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php 
$request = new Yaf_Request_Http("/subdir/ap/1.2/name/value", "/subdir");

$router = new Yaf_Router();

$route  = new Yaf_Route_Rewrite(
	"/subdir/:name/:version",
	array(
		"action" => "version",
	)
);

$router->addRoute("subdir", $route)->addRoute("ap", new Yaf_Route_Rewrite(
	"/ap/:version/*",
    array(
		"action" => 'ap',
	)
))->route($request);

var_dump($router->getCurrentRoute());
var_dump($request->getParam('version'));
var_dump($request->getActionName());
var_dump($request->getControllerName());
var_dump($request->getParam('name'));

?>
--EXPECTF--
string(2) "ap"
string(3) "1.2"
string(2) "ap"
NULL
string(5) "value"
tests/simple.ini000064400000001644151730720450007711 0ustar00[base]
application.directory=APPLICATION_PATH "/applcation"
name = "base"
array.1 = 1
5=5
array.name="name"
routes.regex.type="regex"
routes.regex.match="^/ap/(.*)"
routes.regex.route.controller="Index"
routes.regex.route.action="action"
routes.regex.map.0="name"
routes.regex.map.1="name"
routes.regex.map.2="value"
routes.simple.type="simple"
routes.simple.controller="c"
routes.simple.module="m"
routes.simple.action="a"
routes.supervar.type="supervar"
routes.supervar.varname="c"
routes.rewrite.type="rewrite"
routes.rewrite.match="/yaf/:name/:value"
routes.rewrite.route.controller="Index"
routes.rewrite.route.action="action"

[extra : base ]
value = "2"
name = "extra"
array.name = "new_name"
array.2 = "test"

[product : extra]

[nocatch : extra]
application.dispatcher.throwException=Off
application.dispatcher.catchException=yes
routes.rewrite.match="/yaf/:name/:age"

[envtest]
env=${FOO}
ini=${yaf.directory}
const=FOO

tests/093.phpt000064400000002124151730720450007121 0ustar00--TEST--
Check for numeric keys in view assign
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=0
yaf.use_namespace=0

--FILE--
<?php
require "build.inc";
startup();

$config = array(
	"application" => array(
		"directory" => APPLICATION_PATH,
	),
);

file_put_contents(APPLICATION_PATH . "/controllers/Index.php", <<<PHP
<?php
   class IndexController extends Yaf_Controller_Abstract {
         public function init() {}

         public function indexAction() {
            \$this->getView()->assign("var", "str key");
            \$this->getView()->assign(1, "number key");
            \$this->getView()->assign(2.3, "float key");
            \$this->getView()->display("index/index.phtml", [-1 => "number key", "0x2342" => "hex key"]);
            return false;
         }
   }
PHP
);

file_put_contents(APPLICATION_PATH . "/views/index/index.phtml", "<?php
var_dump(get_defined_vars());
?>");

$app = new Yaf_Application($config);
$app->run();

?>
--CLEAN--
<?php
require "build.inc";
shutdown();
?>
--EXPECTF--
array(1) {
  ["var"]=>
  string(7) "str key"
}
tests/105.phpt000064400000001750151730720450007117 0ustar00--TEST--
Check for Yaf_Application::bootstrap errors
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=0
yaf.lowcase_path=0
yaf.use_namespace=0
--FILE--
<?php 
require "build.inc";
startup();

$config = array(
	"application" => array(
		"directory" => APPLICATION_PATH,
	),
);

$app = new Yaf_Application($config);

$app->bootstrap();
file_put_contents(APPLICATION_PATH . "/Bootstrap.php", <<<PHP
PHP
);
$app->bootstrap();
file_put_contents(APPLICATION_PATH . "/Bootstrap.php", <<<PHP
<?php
class Bootstrap {}
PHP
);
try {
	$app->bootstrap();
} catch (Exception $e) {
	var_dump($e->getMessage());
}
?>
--CLEAN--
<?php
require "build.inc"; 
shutdown();
?>
--EXPECTF--
Warning: Yaf_Application::bootstrap(): Couldn't find bootstrap file %sBootstrap.php in %s105.php on line %d

Warning: Yaf_Application::bootstrap(): Couldn't find class Bootstrap in %sBootstrap.php in %s105.php on line %d
string(%d) "'Bootstrap' is not a subclass of Yaf_Bootstrap_Abstract"
tests/059.phpt000064400000002746151730720450007135 0ustar00--TEST--
Check nesting view render
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=0
yaf.lowcase_path=0
yaf.use_namespace=0
--FILE--
<?php 
require "build.inc";
startup();

$config = array(
	"application" => array(
		"directory" => APPLICATION_PATH,
	),
);

file_put_contents(APPLICATION_PATH . "/Bootstrap.php", <<<PHP
<?php
   class Bootstrap extends Yaf_Bootstrap_Abstract {
        public function _initReturn(Yaf_Dispatcher \$dispatcher) {
            \$dispatcher->returnResponse(true);
        }
   }
PHP
);

file_put_contents(APPLICATION_PATH . "/controllers/Index.php", <<<PHP
<?php
   class IndexController extends Yaf_Controller_Abstract {
         public function init() {
             Yaf_Dispatcher::getInstance()->flushInstantly(true);
         } 
         public function indexAction() {
             var_dump(\$this->_view->getScriptPath());
         }
   }
PHP
);

file_put_contents(APPLICATION_PATH . "/views/index/index.phtml", "<?php print_r(\$this); \$this->display('index/sub.phtml', array('content' => 'dummy'));?>");
file_put_contents(APPLICATION_PATH . "/views/index/sub.phtml", "<?php echo \$content; echo \$this->eval('foobar'); ?>");

$app = new Yaf_Application($config);
$response = $app->bootstrap()->run();
?>
--CLEAN--
<?php
require "build.inc"; 
shutdown();
?>
--EXPECTF--
string(%d) "%sapplication%cviews"
Yaf_View_Simple Object
(
    [tpl_dir:protected] => %s
    [tpl_vars:protected] => Array
        (
        )

)
dummyfoobar
tests/010.phpt000064400000032555151730720450007121 0ustar00--TEST--
Check for Yaf_Config_Ini basic usages
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip";
if (version_compare(PHP_VERSION, '7.1.0') <= 0) {
   print "skip PHP 7.0 strict_types __construct() output warning";
}
?>
--INI--
yaf.use_namespace=0
--FILE--
<?php
declare(strict_types=1);
$file = dirname(__FILE__) . "/simple.ini";

$config = new Yaf_Config_Ini($file);
print_r($config);
$config = new Yaf_Config_Ini($file, "extra");
print_r($config);
$config = new Yaf_Config_Ini($file);
$config->longtime = 23424234324;
var_dump($config->readonly());

var_dump($config["base.application.directory"]);

foreach($config as $key => $value) {
	print_r($key);
}

$sick = @new Yaf_Config_Ini();

var_dump($sick->__isset(1));
var_dump($sick->__get(1));
$sick->total = 1;

var_dump(count($sick));
?>
--EXPECTF--
Yaf_Config_Ini Object
(
    [readonly:protected] => 1
    [config:protected] => Array
        (
            [base] => Array
                (
                    [application] => Array
                        (
                            [directory] => APPLICATION_PATH/applcation
                        )

                    [name] => base
                    [array] => Array
                        (
                            [1] => 1
                            [name] => name
                        )

                    [5] => 5
                    [routes] => Array
                        (
                            [regex] => Array
                                (
                                    [type] => regex
                                    [match] => ^/ap/(.*)
                                    [route] => Array
                                        (
                                            [controller] => Index
                                            [action] => action
                                        )

                                    [map] => Array
                                        (
                                            [0] => name
                                            [1] => name
                                            [2] => value
                                        )

                                )

                            [simple] => Array
                                (
                                    [type] => simple
                                    [controller] => c
                                    [module] => m
                                    [action] => a
                                )

                            [supervar] => Array
                                (
                                    [type] => supervar
                                    [varname] => c
                                )

                            [rewrite] => Array
                                (
                                    [type] => rewrite
                                    [match] => /yaf/:name/:value
                                    [route] => Array
                                        (
                                            [controller] => Index
                                            [action] => action
                                        )

                                )

                        )

                )

            [extra] => Array
                (
                    [application] => Array
                        (
                            [directory] => APPLICATION_PATH/applcation
                        )

                    [name] => extra
                    [array] => Array
                        (
                            [1] => 1
                            [name] => new_name
                            [2] => test
                        )

                    [5] => 5
                    [routes] => Array
                        (
                            [regex] => Array
                                (
                                    [type] => regex
                                    [match] => ^/ap/(.*)
                                    [route] => Array
                                        (
                                            [controller] => Index
                                            [action] => action
                                        )

                                    [map] => Array
                                        (
                                            [0] => name
                                            [1] => name
                                            [2] => value
                                        )

                                )

                            [simple] => Array
                                (
                                    [type] => simple
                                    [controller] => c
                                    [module] => m
                                    [action] => a
                                )

                            [supervar] => Array
                                (
                                    [type] => supervar
                                    [varname] => c
                                )

                            [rewrite] => Array
                                (
                                    [type] => rewrite
                                    [match] => /yaf/:name/:value
                                    [route] => Array
                                        (
                                            [controller] => Index
                                            [action] => action
                                        )

                                )

                        )

                    [value] => 2
                )

            [product] => Array
                (
                    [application] => Array
                        (
                            [directory] => APPLICATION_PATH/applcation
                        )

                    [name] => extra
                    [array] => Array
                        (
                            [1] => 1
                            [name] => new_name
                            [2] => test
                        )

                    [5] => 5
                    [routes] => Array
                        (
                            [regex] => Array
                                (
                                    [type] => regex
                                    [match] => ^/ap/(.*)
                                    [route] => Array
                                        (
                                            [controller] => Index
                                            [action] => action
                                        )

                                    [map] => Array
                                        (
                                            [0] => name
                                            [1] => name
                                            [2] => value
                                        )

                                )

                            [simple] => Array
                                (
                                    [type] => simple
                                    [controller] => c
                                    [module] => m
                                    [action] => a
                                )

                            [supervar] => Array
                                (
                                    [type] => supervar
                                    [varname] => c
                                )

                            [rewrite] => Array
                                (
                                    [type] => rewrite
                                    [match] => /yaf/:name/:value
                                    [route] => Array
                                        (
                                            [controller] => Index
                                            [action] => action
                                        )

                                )

                        )

                    [value] => 2
                )

            [nocatch] => Array
                (
                    [application] => Array
                        (
                            [directory] => APPLICATION_PATH/applcation
                            [dispatcher] => Array
                                (
                                    [throwException] => 
                                    [catchException] => 1
                                )

                        )

                    [name] => extra
                    [array] => Array
                        (
                            [1] => 1
                            [name] => new_name
                            [2] => test
                        )

                    [5] => 5
                    [routes] => Array
                        (
                            [regex] => Array
                                (
                                    [type] => regex
                                    [match] => ^/ap/(.*)
                                    [route] => Array
                                        (
                                            [controller] => Index
                                            [action] => action
                                        )

                                    [map] => Array
                                        (
                                            [0] => name
                                            [1] => name
                                            [2] => value
                                        )

                                )

                            [simple] => Array
                                (
                                    [type] => simple
                                    [controller] => c
                                    [module] => m
                                    [action] => a
                                )

                            [supervar] => Array
                                (
                                    [type] => supervar
                                    [varname] => c
                                )

                            [rewrite] => Array
                                (
                                    [type] => rewrite
                                    [match] => /yaf/:name/:age
                                    [route] => Array
                                        (
                                            [controller] => Index
                                            [action] => action
                                        )

                                )

                        )

                    [value] => 2
                )

            [envtest] => Array
                (
                    [env] => 
                    [ini] => 
                    [const] => FOO
                )

        )

    [filename:protected] => %s
)
Yaf_Config_Ini Object
(
    [readonly:protected] => 1
    [config:protected] => Array
        (
            [application] => Array
                (
                    [directory] => APPLICATION_PATH/applcation
                )

            [name] => extra
            [array] => Array
                (
                    [1] => 1
                    [name] => new_name
                    [2] => test
                )

            [5] => 5
            [routes] => Array
                (
                    [regex] => Array
                        (
                            [type] => regex
                            [match] => ^/ap/(.*)
                            [route] => Array
                                (
                                    [controller] => Index
                                    [action] => action
                                )

                            [map] => Array
                                (
                                    [0] => name
                                    [1] => name
                                    [2] => value
                                )

                        )

                    [simple] => Array
                        (
                            [type] => simple
                            [controller] => c
                            [module] => m
                            [action] => a
                        )

                    [supervar] => Array
                        (
                            [type] => supervar
                            [varname] => c
                        )

                    [rewrite] => Array
                        (
                            [type] => rewrite
                            [match] => /yaf/:name/:value
                            [route] => Array
                                (
                                    [controller] => Index
                                    [action] => action
                                )

                        )

                )

            [value] => 2
        )

    [filename:protected] => %s
)

Warning: Yaf_Config_Ini::__set(): config is readonly in %s010.php on line %d
bool(true)
string(%d) "%sapplcation"
baseextraproductnocatchenvtest
Fatal error: Uncaught ArgumentCountError: Yaf_Config_Ini::__construct() expects at least 1 %s, 0 given in %s010.php:%d
Stack trace:
#0 %s010.php(%d): Yaf_Config_Ini->__construct()
#1 {main}
  thrown in %s010.php on line %d

tests/build.inc000064400000001740151730720450007506 0ustar00<?php
define('DIR_ROOT', dirname(__FILE__));

define("APPLICATION_PATH", DIR_ROOT . DIRECTORY_SEPARATOR . 'application');

function shutdown($root = APPLICATION_PATH) {
    $dp = opendir($root);
    while (($dir = readdir($dp))) {
        if (in_array($dir, array('.', '..'))) {
            continue;
        }
        $path = $root . DIRECTORY_SEPARATOR . $dir;

        if (is_dir($path)) {
            shutdown($path);
        } else if (is_file($path)) {
            unlink($path);
        }
    }
    rmdir($root);
}

function startup($root = APPLICATION_PATH) {
    $dirs = array();
    $dirs[] = 'library';
    $dirs[] = 'controllers';
	$dirs[] = 'actions';
    $dirs[] = 'plugins';
    $dirs[] = 'models';
    $dirs[] = 'views';
    $dirs[] = 'views/index';
    $dirs[] = 'tpls';

    foreach($dirs as $dir){
        $dir = $root . DIRECTORY_SEPARATOR . $dir;
        if (!file_exists($dir)) {
            mkdir($dir, 0755, true);
            chmod($dir, 0755);
        }
    }
}

?>
tests/088.phpt000064400000003007151730720450007126 0ustar00--TEST--
Check for Yaf_Route_Rwrite with arbitrary urls
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php
$url = array(
	"/", "/foo", "//foo/", "/foo/bar", "/foo///",
	"/foo/cont/act", "/foo/cont/act/", "/foocont/act", 
	"/foo/cont//act", "/foo//cont///act//",
    "/foo/cont/act//var/value/", "/foo/cont/act//var/value/age",
	"/foo/cont/act//var/value/age/12//",
);

$route = new Yaf_Route_Rewrite(
	"/foo/:name/:subname/*",
	array(
		"controller" => ":name",
		"action" => ":subname"
	)
);

foreach ($url as $u) {
   $req = new Yaf_Request_Http($u);
   $route->route($req);
   echo $u, " : ",  "m=>", $req->getModuleName(), " c=>", $req->getControllerName(), " a=>",  $req->getActionName();
   if (($args = $req->getParams())) {
       echo " args=>";
       foreach ($args as $k => $v) {
          echo $k , "->", $v , ",";
       }
   }
   echo "\n";
}
?>
--EXPECT--
/ : m=> c=> a=>
/foo : m=> c=> a=>
//foo/ : m=> c=> a=>
/foo/bar : m=> c=> a=>
/foo/// : m=> c=> a=>
/foo/cont/act : m=> c=> a=>
/foo/cont/act/ : m=> c=>Cont a=>act args=>name->cont,subname->act,
/foocont/act : m=> c=> a=>
/foo/cont//act : m=> c=> a=>
/foo//cont///act// : m=> c=>Cont a=>act args=>name->cont,subname->act,
/foo/cont/act//var/value/ : m=> c=>Cont a=>act args=>name->cont,subname->act,var->value,
/foo/cont/act//var/value/age : m=> c=>Cont a=>act args=>name->cont,subname->act,var->value,age->,
/foo/cont/act//var/value/age/12// : m=> c=>Cont a=>act args=>name->cont,subname->act,var->value,age->12,
tests/issue163.phpt000064400000002063151730720450010172 0ustar00--TEST--
Issue #163 (forward from init controller)
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=1
yaf.lowcase_path=0
yaf.throw_exception=0
yaf.catch_exception=1
yaf.use_namespace=0
--FILE--
<?php 
require "build.inc";
startup();

$config = array(
	"application" => array(
		"directory" => APPLICATION_PATH,
	),
);

file_put_contents(APPLICATION_PATH . "/controllers/Index.php", <<<PHP
<?php
   class IndexController extends Yaf_Controller_Abstract {
		public function init() {
			\$this->forward("Index", "Second", "okey");
		}
		public function indexAction() {
			echo "bad";
		}
   }
PHP
);

file_put_contents(APPLICATION_PATH . "/controllers/Second.php", <<<PHP
<?php
   class SecondController extends Yaf_Controller_Abstract {
			public function okeyAction() {
				echo "Okey";
				return FALSE;
			}
   }
PHP
);

file_put_contents(APPLICATION_PATH . "/views/index/index.phtml", "Okey");

$app = new Yaf_Application($config);
$response = $app->run();
?>
--CLEAN--
<?php
require "build.inc"; 
shutdown();
?>
--EXPECT--
Okey
tests/issue530.phpt000064400000001304151730720450010165 0ustar00--TEST--
Segfault while exiting in action
--SKIPIF--
<?php 
	if (!extension_loaded("yaf")) exit("skip"); 
	if (version_compare(PHP_VERSION, "8.0.0", "lt")) exit("skip only PHP8 affected");
?>
--INI--
yaf.use_namespace=0
yaf.use_spl_autoload=0
--FILE--
<?php 
require "build.inc";
startup();

$config = array(
	"application" => array(
		"directory" => APPLICATION_PATH,
	),
);
$app = new Yaf_Application($config);

file_put_contents(APPLICATION_PATH . "/controllers/Index.php", <<<PHP
<?php
class IndexController extends Yaf_Controller_Abstract {
    public function indexAction() {
		echo 'okey'; exit;
    }    
}
PHP
);

$app->run();
?>
--CLEAN--
<?php
require "build.inc"; 
shutdown();
?>
--EXPECT--
okey
tests/054.phpt000064400000001036151730720450007117 0ustar00--TEST--
check for Various segfault
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=0
yaf.lowcase_path=0
yaf.use_namespace=0
--FILE--
<?php
try {
    $config = new Yaf_Config_Ini(dirname(__FILE__), "test");
} catch (Exception $e) {
    var_dump($e->getMessage());
}

$request = new Yaf_Request_Simple(NULL);
var_dump($request->isOptions());


$config = new Yaf_Config_Simple(array());
$config->key();
echo "okey";
?>
--EXPECTF--
string(%d) "Argument is not a valid ini file '%s'"
bool(false)
okey
tests/bug63381.phpt000064400000002212151730720450007766 0ustar00--TEST--
Bug #63381 ($_SERVER['SCRIPT_NAME'] changed by yaf)
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=1
yaf.lowcase_path=0
yaf.use_namespace=0
--FILE--
<?php 
require "build.inc";
startup();

$server = $_SERVER;
$cookie = $_COOKIE;
$post   = $_POST;
$get    = $_GET;

$config = array(
	"application" => array(
		"directory" => APPLICATION_PATH,
	),
);

file_put_contents(APPLICATION_PATH . "/controllers/Index.php", <<<PHP
<?php
   class IndexController extends Yaf_Controller_Abstract {
       public function indexAction() {
       }
   }
PHP
);

file_put_contents(APPLICATION_PATH . "/controllers/Dummy.php", <<<PHP
<?php
   class DummyController extends Yaf_Controller_Abstract {
       public function indexAction() {
       }
   }
PHP
);

file_put_contents(APPLICATION_PATH . "/views/index/index.phtml", "");

$app = new Yaf_Application($config);
$response = $app->run();

var_dump($server === $_SERVER);
var_dump($cookie === $_COOKIE);
var_dump($get === $_GET);
var_dump($post === $_POST);

?>
--CLEAN--
<?php
require "build.inc"; 
shutdown();
?>
--EXPECTF--
bool(true)
bool(true)
bool(true)
bool(true)
tests/080.phpt000064400000002010151730720450007107 0ustar00--TEST--
PHP7 didn't display Error.
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php 
require "build.inc";
startup();

$config = array(
	"application" => array(
		"directory" => APPLICATION_PATH,
		"bootstrap" => APPLICATION_PATH . "/mybootstrap.php",
	),
);

file_put_contents(APPLICATION_PATH . "/mybootstrap.php", <<<PHP
<?php
   class Bootstrap extends Yaf_Bootstrap_Abstract {
   }
PHP
);

file_put_contents(APPLICATION_PATH . "/controllers/Index.php", <<<PHP
<?php
class IndexController extends Yaf_Controller_Abstract {

    public function indexAction() {
        geoge();//funciton undefined!    
    }    
}
PHP
);

$app = new Yaf_Application($config);
$app->bootstrap()->run();
?>
--CLEAN--
<?php
require "build.inc"; 
shutdown();
?>
--EXPECTF--
Fatal error: Uncaught Error: Call to undefined function geoge() in %s:5
Stack trace:
#0 [internal function]: IndexController->indexAction()
#1 %s080.php(%d): Yaf_Application->run()
#2 {main}
  thrown in %s on line %d
tests/052.phpt000064400000003107151730720450007116 0ustar00--TEST--
Check for Yaf_Request APis
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=0
yaf.use_namespace=0
--FILE--
<?php
declare(strict_types=1);
try {
	$request == new Yaf_Request_Http(new stdClass(), "xxxx", false);
} catch (TypeError $e) {
	var_dump($e->getMessage());
}
$request = new Yaf_Request_Http("xxxxxxxxxxxxxxxxxxxxxxxxxxx");
var_dump($request->get("xxx"));
var_dump($request->getQuery("xxx"));
var_dump($request->getServer("xxx"));
var_dump($request->getPost("xxx"));
var_dump($request->getCookie("xxx"));
var_dump($request->getEnv("xxx"));
echo "------default value-------\n";
var_dump($request->get("xxx", "123"));
print_r($request->getQuery("xxx", new stdClass()));
print_r($request->getServer("xxx", array()));
var_dump($request->getPost("xxx", NULL));
var_dump($request->getCookie("xxx"), false);
var_dump($request->getEnv("xxx"), "2.13232");
echo "-----others-----\n";
var_dump($request->isXmlHttpRequest());
var_dump($request->isCli());
var_dump($request->isPost());
echo "------params-------\n";
var_dump($request->getParam("xxxx"));
var_dump($request->getParams());
var_dump($request->setParam("xxxx"));
?>
--EXPECTF--
string(%d) "Yaf_Request_Http::__construct() expects at most 2 %s, 3 given"
NULL
NULL
NULL
NULL
NULL
NULL
------default value-------
string(3) "123"
stdClass Object
(
)
Array
(
)
NULL
NULL
bool(false)
NULL
string(7) "2.13232"
-----others-----
bool(false)
bool(true)
bool(false)
------params-------
NULL
array(0) {
}

Fatal error: Uncaught TypeError: Yaf_Request_Abstract::setParam()%sarray, string given in %s052.php:%d
%atests/092.phpt000064400000001610151730720460007120 0ustar00--TEST--
Check for base uri detecting
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=0
yaf.lowcase_path=0
yaf.use_namespace=0
--FILE--
<?php 

$_SERVER["REQUEST_URI"] = "/yaf/c/a";
$_SERVER["SCRIPT_FILENAME"] = "/usr/local/www/yaf/index.php";
$_SERVER["SCRIPT_NAME"] = "/yaf/index.php";
$req = new Yaf_Request_Http();
var_dump($req->getBaseuri());
var_dump($req->getRequestUri());

unset($_SERVER["SCRIPT_NAME"]);
$_SERVER["PHP_SELF"] = "/yaf/index.php";
$req = new Yaf_Request_Http();
var_dump($req->getBaseuri());
var_dump($req->getRequestUri());


unset($_SERVER["REQUEST_URI"]);
unset($_SERVER["PHP_SELF"]);
$_SERVER["PATH_INFO"] = "/c/a";
$req = new Yaf_Request_Http();
var_dump($req->getBaseuri());
var_dump($req->getRequestUri());
?>
--EXPECT--
string(4) "/yaf"
string(8) "/yaf/c/a"
string(4) "/yaf"
string(8) "/yaf/c/a"
string(0) ""
string(4) "/c/a"
tests/036.phpt000064400000005114151730720460007121 0ustar00--TEST--
Check for Yaf_Route_Static with arbitrary urls
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php
$url = array(
  "/", "/foo", "/foo/", "/foo///bar", "foo/bar", "/foo/bar/",
  "/foo/bar/dummy", "/foo///bar/dummy/", "foo/bar/dummy/",
  "/my", "/my/", "/my/foo", "/my/foo/", "my/foo/bar", "my/foo/bar/",
  "/m/index/index", "/my/foo/bar/dummy/1", "my/foo/bar/dummy/1/a/2/////",
  "/my/index/index", "my/index", "/foo/index", "index/foo", "//foo///bar///p1////v1////p2/v2/",
);

$config = array( 
    "application" => array(
        "directory" => '/tmp/',
        "modules"   => 'Index,My',
     ),
);

$app = new Yaf_Application($config);

$route = Yaf_Dispatcher::getInstance()->getRouter();

foreach ($url as $u) {
   $req = new Yaf_Request_Http($u);
   $route->route($req);
   echo $u, " : ",  "m=>", $req->getModuleName(), " c=>", $req->getControllerName(), " a=>",  $req->getActionName();
   if (($args = $req->getParams())) {
       echo " args=>";
       foreach ($args as $k => $v) {
          echo $k , "->", $v , ",";
       }
   }
   echo "\n";
}

ini_set("yaf.action_prefer", 1);
$url = array(
  "/", "/foo", "/foo/",
  "/my", "/my/", "/my/foo", "/my//foo/", 
);

foreach ($url as $u) {
   $req = new Yaf_Request_Http($u);
   $route->route($req);
   echo $u, " : ",  "m=>", $req->getModuleName(), " c=>", $req->getControllerName(), " a=>",  $req->getActionName();
   if (($args = $req->getParams())) {
       echo " args=>";
       foreach ($args as $k => $v) {
          echo $k , "->", $v , ",";
       }
   }
   echo "\n";
}

?>
--EXPECT--
/ : m=> c=> a=>
/foo : m=> c=>Foo a=>
/foo/ : m=> c=>Foo a=>
/foo///bar : m=> c=>Foo a=>bar
foo/bar : m=> c=>Foo a=>bar
/foo/bar/ : m=> c=>Foo a=>bar
/foo/bar/dummy : m=> c=>Foo a=>bar args=>dummy->,
/foo///bar/dummy/ : m=> c=>Foo a=>bar args=>dummy->,
foo/bar/dummy/ : m=> c=>Foo a=>bar args=>dummy->,
/my : m=> c=>My a=>
/my/ : m=> c=>My a=>
/my/foo : m=> c=>My a=>foo
/my/foo/ : m=> c=>My a=>foo
my/foo/bar : m=>My c=>Foo a=>bar
my/foo/bar/ : m=>My c=>Foo a=>bar
/m/index/index : m=> c=>M a=>index args=>index->,
/my/foo/bar/dummy/1 : m=>My c=>Foo a=>bar args=>dummy->1,
my/foo/bar/dummy/1/a/2///// : m=>My c=>Foo a=>bar args=>dummy->1,a->2,
/my/index/index : m=>My c=>Index a=>index
my/index : m=> c=>My a=>index
/foo/index : m=> c=>Foo a=>index
index/foo : m=> c=>Index a=>foo
//foo///bar///p1////v1////p2/v2/ : m=> c=>Foo a=>bar args=>p1->,v1->,p2->v2,
/ : m=> c=> a=>
/foo : m=> c=> a=>foo
/foo/ : m=> c=> a=>foo
/my : m=> c=> a=>my
/my/ : m=> c=> a=>my
/my/foo : m=> c=>My a=>foo
/my//foo/ : m=> c=>My a=>foo
tests/bug62702.phpt000064400000003272151730720460007772 0ustar00--TEST--
FR #62702 (Make baseuri case-insensitive)
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php

$router = new Yaf_Route_Static();
$request = new Yaf_Request_Http("/sample", "/sample");
$router->route($request);
var_dump($request->getControllerName());

$request = new Yaf_Request_Http("/Sample/ABC", "/sample");
$router->route($request);
var_dump($request->getControllerName());


$router = new Yaf_Route_Map(true);
$request = new Yaf_Request_Http("/sample/A/B/C", "/sample");
$router->route($request);
var_dump($request->getControllerName());

$request = new Yaf_Request_Http("/sample", "/sAmplE/");
$router->route($request);
var_dump($request->getControllerName());

$router = new Yaf_Route_Regex("#^/test#", array("controller" => "info"), array());
$request = new Yaf_Request_Http("/test/", "/Test");
$router->route($request);
var_dump($request->getControllerName());

$request = new Yaf_Request_Http("/sample/test", "/sAmplE");
$router->route($request);
var_dump($request->getControllerName());

$router = new Yaf_Route_Rewrite("/test", array("controller" => "info"), array());
$request = new Yaf_Request_Http("/test/", "/Test");
$router->route($request);
var_dump($request->getControllerName());

$request = new Yaf_Request_Http("/sample/test", "/sAmplE");
$router->route($request);
var_dump($request->getControllerName());

$router = new Yaf_Route_Rewrite("/sample/", array("controller" => "info"), array());
$request = new Yaf_Request_Http("/sample/test", "/sam");
$router->route($request);
var_dump($request->getControllerName());
?>
--EXPECTF--
NULL
string(3) "Abc"
string(5) "A_B_C"
NULL
NULL
string(4) "Info"
NULL
string(4) "Info"
string(4) "Info"
tests/073.phpt000064400000002704151730720460007124 0ustar00--TEST--
Check for Yaf_Route_Rewrite::assemble
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php

$router = new Yaf_Router();

$route  = new Yaf_Route_Rewrite(
                "/product/:name/:id/*",
                array(
                        'controller' => "product",
                ),
                array()
);

$router->addRoute("rewrite", $route);

var_dump($router->getRoute('rewrite')->assemble(
                        array(
                                ':name' => 'foo',
                                ':id' => 'bar',
                                ':tmpkey1' => 'tmpval1'
                        ),
                        array(
                                'tkey1' => 'tval1',
                                'tkey2' => 'tval2'
                             )
                        )
);

var_dump($router->getRoute('rewrite')->assemble(
                        array(
                                ':name' => 'foo',
                                ':id' =>  1,
                                ':tmpkey1' => 'tmpval1'
                        ),
                        array(
                                'tkey1' => 'tval1',
                                'tkey2' => 22222
                             )
                        )
);

--EXPECTF--
string(57) "/product/foo/bar/tmpkey1/tmpval1/?tkey1=tval1&tkey2=tval2"
string(55) "/product/foo/1/tmpkey1/tmpval1/?tkey1=tval1&tkey2=22222"
tests/098.phpt000064400000001654151730720460007136 0ustar00--TEST--
Check for Yaf_Bootstrap protected method
--SKIPIF--
<?php
if (!extension_loaded("yaf")) print "skip";
if (!version_compare(PHP_VERSION, "5.3", "ge")) print "skip only for 5.3+";
?>
--INI--
yaf.use_namespace=0
--FILE--
<?php 
$config = array(
	"application" => array(
		"directory" => realpath(dirname(__FILE__)),
		"dispatcher" => array(
			"catchException" => 0,
			"throwException" => 0,
		),
	),
);

class Bootstrap extends Yaf_Bootstrap_Abstract {
    protected function _initErrorHandler(Yaf_Dispatcher $dispatcher) {
		echo "Bad";
    }
}

class IndexController extends Yaf_Controller_Abstract {
    public function indexAction() {
		echo "Okey";
        return FALSE;
    }
}

$app = new Yaf_Application($config);
try {
    $app->bootstrap()->run();
} catch (Exception $e) {
    var_dump($e->getMessage());
}
?>
--EXPECTF--
Warning: %scannot call protected method Bootstrap::_initErrorHandler() in %s098.php on line %d
Okey
tests/107.phpt000064400000002123151730720460007115 0ustar00--TEST--
Check for Yaf_Dispatcher::setRespone
--SKIPIF--
<?php 
if (!extension_loaded("json")) die("skip, json required");
if (!extension_loaded("yaf")) die("skip");
 ?>
--EXTENSIONS--
json
--INI--
yaf.use_spl_autoload=0
yaf.lowcase_path=0
yaf.use_namespace=0
--FILE--
<?php 
require "build.inc";
startup();

$config = array(
	"application" => array(
		"directory" => APPLICATION_PATH,
	),
);

class my_response extends Yaf_Response_Abstract {
	public $bodys;

	public function appendBody($body, $name = NULL) {
		$this->bodys[] = $body;
	}
	public function response() {
		var_dump(json_encode($this->bodys));
	}
}

file_put_contents(APPLICATION_PATH . "/controllers/Index.php", <<<PHP
<?php
   class IndexController extends Yaf_Controller_Abstract {
         public function indexAction() {
         }
   }
PHP
);

file_put_contents(APPLICATION_PATH . "/views/index/index.phtml", "custom response");

$app = new Yaf_Application($config);
$app->getDispatcher()->setResponse(new my_response());
$app->run();
?>
--CLEAN--
<?php
require "build.inc"; 
shutdown();
?>
--EXPECT--
string(19) "["custom response"]"
tests/074.phpt000064400000001322151730720460007120 0ustar00--TEST--
Check for Yaf_Route_Simple::assemble
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php

$router = new Yaf_Router();

$route  = new Yaf_Route_Simple('m', 'c', 'a');

$router->addRoute("simple", $route);

var_dump($router->getRoute('simple')->assemble(
            array(
                ':a' => 'yafaction', 
                'tkey' => 'tval', 
                ':c' => 'yafcontroller', 
                ':m' => 'yafmodule'
                ), 
            array(
                'tkey1' => 'tval1', 
                'tkey2' => 'tval2'
                )
            ));
--EXPECTF--
string(64) "?m=yafmodule&c=yafcontroller&a=yafaction&tkey1=tval1&tkey2=tval2"
tests/015.phpt000064400000001003151730720460007107 0ustar00--TEST--
Check for Yaf_Exception
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
<?php if (version_compare(PHP_VERSION, "5.3.0", "lt")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php 
$previous = new Yaf_Exception("Previous", 100);
$exception = new Yaf_Exception("Exception", 200, $previous);

var_dump($previous === $exception->getPrevious());
var_dump($exception->getMessage());
var_dump($exception->getPrevious()->getCode());
?>
--EXPECTF--
bool(true)
string(9) "Exception"
int(100)
tests/035.phpt000064400000002011151730720460007111 0ustar00--TEST--
Check for Yaf_View_Simple with short_tag_open
--SKIPIF--
<?php
if (!extension_loaded("yaf")) print "skip"; 
if (version_compare(PHP_VERSION, '5.4.0') >= 0) {
   print "skip PHP 5.4 remove short_open_tag";
} 
?>
--INI--
short_open_tag = 0
yaf.use_namespace=0
--FILE--
<?php 
$view = new Yaf_View_Simple(dirname(__FILE__));
$tpl = dirname(__FILE__) . '/short_tag_test.phtml';

$content = "<?=\$name?>";

file_put_contents($tpl, $content);

echo $view->render($tpl, array('name' => 'template'));
echo "\n";
$view->display($tpl, array('name' => 'template'));
$view = new Yaf_View_Simple(dirname(__FILE__), array("short_tag" => 0));
echo "\n";
var_dump(ini_get("short_open_tag"));
$view->display($tpl, array('name' => 'template'));
echo "\n";
print_r($view);
unlink($tpl);
?>
--EXPECTF--
template
template
string(1) "0"
<?=$name?>
Yaf_View_Simple Object
(
    [_tpl_vars:protected] => Array
        (
        )

    [_tpl_dir:protected] => %s
    [_options:protected] => Array
        (
            [short_tag] => 0
        )

)
tests/issue513.phpt000064400000005216151730720460010175 0ustar00--TEST--
Check for Custom MVC name
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=0
yaf.use_namespace=0
--FILE--
<?php
require "build.inc";
startup();

$config = array(
	"application" => array(
		"directory" => APPLICATION_PATH,
        "bootstrap" => APPLICATION_PATH . "/cboot.php",
        "dispatcher" => array (
           "catchException" => true,
        ), 
        "library" => array(
        ),
	),
);

file_put_contents(APPLICATION_PATH . "/controllers/Error.php", <<<PHP
<?php
   class ErrorController extends Yaf_Controller_Abstract {
         public function errorAction(\$exception) {
              var_dump(\$exception->getMessage());
              return FALSE;
         }
   }
PHP
);

file_put_contents(APPLICATION_PATH . "/cboot.php", <<<PHP
<?php
   class Bootstrap extends Yaf_Bootstrap_Abstract {
        public function _initPlugin(Yaf_Dispatcher \$dispatcher) {
            \$dispatcher->registerPlugin(new TestPlugin());
        }
   }
PHP
);

file_put_contents(APPLICATION_PATH . "/plugins/Test.php", <<<PHP
<?php
   class TestPlugin extends Yaf_Plugin_Abstract {
        public function routerShutdown(Yaf_Request_Abstract \$request, Yaf_Response_Abstract \$response) {
			\$request->setModuleName("CUSTOM", false);
			\$request->setControllerName("INDEX", false);
			\$request->setActionName("CamelName", false);
			return;
        }
        public function dispatchLoopStartup(Yaf_Request_Abstract \$request, Yaf_Response_Abstract \$response) {
        }
        public function preDispatch(Yaf_Request_Abstract \$request, Yaf_Response_Abstract \$response) {
        }
        public function postDispatch(Yaf_Request_Abstract \$request, Yaf_Response_Abstract \$response) {
			var_dump(\$request->getControllerName());
			var_dump(\$request->getActionName());
        }
   }
PHP
);

$value = NULL;

@mkdir(APPLICATION_PATH . "/modules");
@mkdir(APPLICATION_PATH . "/modules/CUSTOM");
@mkdir(APPLICATION_PATH . "/modules/CUSTOM/controllers");
@mkdir(APPLICATION_PATH . "/modules/CUSTOM/views");
/* Controller name here should be lowercase anyway? */
@mkdir(APPLICATION_PATH . "/modules/CUSTOM/views/index");
file_put_contents(APPLICATION_PATH . "/modules/CUSTOM/controllers/INDEX.php", <<<PHP
<?php
   class INDEXController extends Yaf_Controller_Abstract {
         public function CamelNameAction() {
         }
   }
PHP
);

file_put_contents(APPLICATION_PATH . "/modules/CUSTOM/views/index/CamelName.phtml", "<?php var_dump('ok'); ?>");

$app = new Yaf_Application($config);
$app->bootstrap()->run();

?>
--CLEAN--
<?php
require "build.inc"; 
shutdown();
?>
--EXPECTF--
string(5) "INDEX"
string(9) "CamelName"
string(2) "ok"
tests/issue469.phpt000064400000003674151730720460010215 0ustar00--TEST--
Issue #469 (treat autocontroller as Contorller mistakenly)
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=0
yaf.lowcase_path=0
yaf.throw_exception=0
yaf.catch_exception=1
yaf.use_namespace=0
yaf.name_separator=""
--FILE--
<?php 
Yaf_Loader::getInstance("/tmp/library");

set_error_handler(function($level, $msg) {
	global $is_mvc;
	if (strpos($msg, "Couldn't load a MVC class unless") !== false && !$is_mvc) {
		var_dump($msg);
	} else if (strpos($msg, "Couldn't load a MVC class unless") === false && $is_mvc) {
		var_dump($msg);
	}
});

function try_load_class($name) {
	Yaf_Loader::getInstance()->autoload($name);
}

ini_set("yaf.name_suffix", 1);
$is_mvc = false;
try_load_class("automodel");
try_load_class("autoplugin");
try_load_class("autocontroller");
$is_mvc = true;
try_load_class("autoModel");
try_load_class("autoPlugin");
try_load_class("autoController");

ini_set("yaf.name_suffix", 0);
$is_mvc = false;
try_load_class("modelauto");
try_load_class("pluginauto");
try_load_class("controllerauto");
$is_mvc = true;
try_load_class("Modelauto");
try_load_class("Pluginauto");
try_load_class("Controllerauto");

ini_set("yaf.name_suffix", 1);
ini_set("yaf.name_separator", "_");
$is_mvc = false;
try_load_class("auto_model");
try_load_class("auto_plugin");
try_load_class("auto_controller");
$is_mvc = true;
try_load_class("auto_Model");
try_load_class("auto_Plugin");
try_load_class("auto_Controller");

ini_set("yaf.name_suffix", 0);
$is_mvc = false;
try_load_class("model_auto");
try_load_class("plugin_auto");
try_load_class("controller_auto");
try_load_class("Modelauto");
try_load_class("Pluginauto");
try_load_class("Controllerauto");

$is_mvc = true;
try_load_class("Model_auto");
try_load_class("Plugin_auto");
try_load_class("Controller_auto");

ini_set("yaf.name_separator", "\\");
try_load_class("Model\auto");
try_load_class("\Plugin\auto");
try_load_class("\Controller\auto");
?>
okey
--EXPECT--
okey
tests/100.phpt000064400000004363151730720460007116 0ustar00--TEST--
Check for error conditions of Yaf_Application::constructor
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=0
yaf.lowcase_path=0
yaf.use_namespace=0
--FILE--
<?php
require "build.inc";
startup();

try {
	$app = new Yaf_Application(fopen(__FILE__, "r"));
} catch (Exception $e) {
	var_dump($e->getMessage());	
}
var_dump(isset($app));

try {
	$app = new Yaf_Application(array(), "r");
} catch (Exception $e) {
	var_dump($e->getMessage());	
}
var_dump(isset($app));

try {
	$app = new Yaf_Application(array("yaf" => 1), "r");
} catch (Exception $e) {
	var_dump($e->getMessage());	
}
var_dump(isset($app));

try {
	$app = new Yaf_Application(array("yaf" => array()), "r");
} catch (Exception $e) {
	var_dump($e->getMessage());	
}
var_dump(isset($app));

try {
	$app = new Yaf_Application(array("yaf" => array("directory" => __DIR__)), fopen(__FILE__, 'r'));
} catch (Error $e) {
  if (phpversion() >='8.0.0') {
      var_dump('Yaf_Application::__construct() expects parameter 2 to be string, resource given');
   }else{
    var_dump($e->getMessage());
	}
}
var_dump(isset($app));

$app = new Yaf_Application(array("yaf" => array("directory" => APPLICATION_PATH)));

try {
	$double = new Yaf_Application(array("yaf" => array("directory" => __DIR__)));
} catch (Exception $e) {
	var_dump($e->getMessage());	
}
var_dump(isset($double));

file_put_contents(APPLICATION_PATH . "/controllers/Index.php", <<<PHP
<?php
   class IndexController extends Yaf_Controller_Abstract {
         public function init() {
			Yaf_dispatcher::getInstance()->getApplication()->run();
         }
   }
PHP
);

try {
	$app->run();
} catch (Exception $e) {
    var_dump($e->getMessage());
}
?>
--CLEAN--
<?php
require "build.inc"; 
shutdown();
?>
--EXPECT--
string(43) "Initialization of application config failed"
bool(false)
string(46) "Expected an array of application configuration"
bool(false)
string(46) "Expected an array of application configuration"
bool(false)
string(55) "Expected 'directory' entry in application configuration"
bool(false)
string(79) "Yaf_Application::__construct() expects parameter 2 to be string, resource given"
bool(false)
string(39) "Only one application can be initialized"
bool(false)
string(30) "Application is already started"
tests/019.phpt000064400000001206151730720460007120 0ustar00--TEST--
Yaf_Router::getCurrent with number key
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php 
$request = new Yaf_Request_Http("/subdir/ap/1.2/name/value", "/subdir");

$router = new Yaf_Router();

$router->addConfig(
 array(
    array(
    "type" => "regex",
    "match" => "#^/ap/([^/]*)/*#i",
    "route" => array(
        array(
            "action" => 'ap',
            ),
        ),
    "map" => array(
        1 => 'version',
    )
  ) 
 )
)->route($request);

var_dump($router->getCurrentRoute());
var_dump($request->getParam("version"));

?>
--EXPECT--
int(0)
string(3) "1.2"
tests/bug76213.phpt000064400000001140151730720460007764 0ustar00--TEST--
Bug #76213 (Memory leaks with yaf_dispatcher_exception_handler)
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php 
$config = array(
    "application" => array(
        "directory" => realpath(dirname(__FILE__)),
        "dispatcher" => array(
            "catchException" => 1
        )
    ),
);

$app = new Yaf_Application($config);

try {
    $request = new Yaf_Request_Http("/index/admin/login1");
    $app->getDispatcher()->dispatch($request);
} catch(Yaf_Exception $e) {
    var_dump($e->getMessage());
}
?>
--EXPECTF--
string(%d) "%s"
tests/037.phpt000064400000003572151730720460007130 0ustar00--TEST--
Check for Yaf_Loader and open_basedir
--SKIPIF--
<?php 
if (!extension_loaded("yaf")) {
   die("skip");
}
if (version_compare(PHP_VERSION, "5.3", "lt")) {
   die("skip open_basedir only can be tightened as of 5.3.0");
}
?>
--INI--
yaf.lowcase_path=0
yaf.use_spl_autoload=0
yaf.use_namespace=0
--FILE--
<?php
$dir = __DIR__;
$odir = $dir . "/foo";
var_dump(Yaf_Loader::import("./Dummy.php"));
$loader = Yaf_Loader::getInstance();
var_dump($loader->import("./Dummy.php"));
var_dump($loader->autoload("Dummy"));

file_put_contents($dir . "/Dummy.php", "");
ini_set("open_basedir",  $odir);
$loader = Yaf_Loader::getInstance($dir);
$loader->import($dir . "/Dummy.php");
$loader->autoload("Dummy");
?>
--CLEAN--
<?php
unlink(__DIR__ . "/Dummy.php");
?>
--EXPECTF--
Warning: Yaf_Loader::import(): Yaf_Loader need to be initialize first in %s037.php on line %d
bool(false)
bool(false)

Warning: Yaf_Loader::autoload(): Failed opening script %cDummy.php: No such file or directory in %s037.php on line %d
bool(true)

Warning: Yaf_Loader::import(): open_basedir restriction in effect. File(%sDummy.php) is not within the allowed path(s): (%sfoo) in %s037.php on line %d

Warning: Yaf_Loader::import(%sDummy.php): %cailed to open stream: Operation not permitted in %s037.php on line %d

Warning: Yaf_Loader::import(): Failed opening '%sDummy.php' for inclusion (include_path='%s') in %s037.php on line %d

Warning: Yaf_Loader::autoload(): open_basedir restriction in effect. File(%sDummy.php) is not within the allowed path(s): (%sfoo) in %s037.php on line %d

Warning: Yaf_Loader::autoload(%sDummy.php): %cailed to open stream: Operation not permitted in %s037.php on line %d

Warning: Yaf_Loader::autoload(): Failed opening '%sDummy.php' for inclusion (include_path='%s') in %s037.php on line %d

Warning: Yaf_Loader::autoload(): Failed opening script %sDummy.php: Operation not permitted in %s037.php on line %d
tests/061.phpt000064400000002075151730720470007123 0ustar00--TEST--
Bug empty template file interrupts forward chain
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=1
yaf.lowcase_path=0
yaf.use_namespace=0
--FILE--
<?php 
require "build.inc";
startup();

$config = array(
	"application" => array(
		"directory" => APPLICATION_PATH,
	),
);

file_put_contents(APPLICATION_PATH . "/controllers/Index.php", <<<PHP
<?php
   class IndexController extends Yaf_Controller_Abstract {
       public function indexAction() {
           \$this->forward("dummy");
       }
       public function dummyAction() {
       }
   }
PHP
);

file_put_contents(APPLICATION_PATH . "/controllers/Dummy.php", <<<PHP
<?php
   class DummyController extends Yaf_Controller_Abstract {
       public function indexAction() {
       }
   }
PHP
);

file_put_contents(APPLICATION_PATH . "/views/index/index.phtml", "");
file_put_contents(APPLICATION_PATH . "/views/index/dummy.phtml", "Dummy");

$app = new Yaf_Application($config);
$response = $app->run();
?>
--CLEAN--
<?php
require "build.inc"; 
shutdown();
?>
--EXPECTF--
Dummy
tests/060.phpt000064400000002665151730720470007127 0ustar00--TEST--
Check for working with other autoloaders
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=1
yaf.lowcase_path=0
yaf.use_namespace=0
--FILE--
<?php 
require "build.inc";
startup();

function my_autoload($class) {
     eval("class $class {}");
     return TRUE;
}

$config = array(
	"application" => array(
		"directory" => APPLICATION_PATH,
	),
);

file_put_contents(APPLICATION_PATH . "/Bootstrap.php", <<<PHP
<?php
   class Bootstrap extends Yaf_Bootstrap_Abstract {
        public function _initAutoload(Yaf_Dispatcher \$dispatcher) {
             spl_autoload_register("my_autoload");
        }

        public static function errorHandler(\$error, \$errstr) {
              var_dump(\$errstr);
        }

        public function _initErrorHandler(Yaf_Dispatcher \$dispatcher) {
              \$dispatcher->setErrorHandler(array("Bootstrap", "errorHandler"));
        }
   }
PHP
);

file_put_contents(APPLICATION_PATH . "/controllers/Index.php", <<<PHP
<?php
   class IndexController extends Yaf_Controller_Abstract {
         public function indexAction() {
            \$obj = new Dummy();
            \$this->_view->obj = \$obj;
         }
   }
PHP
);

file_put_contents(APPLICATION_PATH . "/views/index/index.phtml", "<?php echo get_class(\$obj);?>");

$app = new Yaf_Application($config);
$response = $app->bootstrap()->run();
?>
--CLEAN--
<?php
require "build.inc"; 
shutdown();
?>
--EXPECTF--
Dummy
tests/048.phpt000064400000006426151730720470007134 0ustar00--TEST--
Check for Sample application
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=0
yaf.lowcase_path=0
yaf.use_namespace=0

--FILE--
<?php
require "build.inc";
startup();

$config = array(
	"application" => array(
		"directory" => APPLICATION_PATH,
        "dispatcher" => array (
           "catchException" => true,
        ), 
        "library" => array(
        ),
	),
);

file_put_contents(APPLICATION_PATH . "/controllers/Error.php", <<<PHP
<?php
   class ErrorController extends Yaf_Controller_Abstract {
         public function errorAction(\$exception) {
              var_dump(\$exception->getMessage());
              return FALSE;
         }
   }
PHP
);

file_put_contents(APPLICATION_PATH . "/Bootstrap.php", <<<PHP
<?php
   class Bootstrap extends Yaf_Bootstrap_Abstract {
        public function _initConfig(Yaf_Dispatcher \$dispatcher) {
            Yaf_Registry::set("config", Yaf_Application::app()->getConfig());
        }
        public function _initPlugin(Yaf_Dispatcher \$dispatcher) {
            \$dispatcher->registerPlugin(new TestPlugin());
        }
   }
PHP
);

file_put_contents(APPLICATION_PATH . "/plugins/Test.php", <<<PHP
<?php
   class TestPlugin extends Yaf_Plugin_Abstract {
        public function routerStartup(Yaf_Request_Abstract \$request, Yaf_Response_Abstract \$response) {
            var_dump("routerStartup");
        }
        public function routerShutdown(Yaf_Request_Abstract \$request, Yaf_Response_Abstract \$response) {
            var_dump("routerShutdown");
        }
        public function dispatchLoopStartup(Yaf_Request_Abstract \$request, Yaf_Response_Abstract \$response) {
            var_dump("dispatchLoopStartup");
        }
        public function preDispatch(Yaf_Request_Abstract \$request, Yaf_Response_Abstract \$response) {
            var_dump("preDispatch");
        }
        public function postDispatch(Yaf_Request_Abstract \$request, Yaf_Response_Abstract \$response) {
            var_dump("postDispatch");
        }
        public function dispatchLoopShutdown(Yaf_Request_Abstract \$request, Yaf_Response_Abstract \$response) {
            global \$value;
            var_dump("dispatchLoopShutdown, global var is:" . \$value);
        }
   }
PHP
);

$value = NULL;

file_put_contents(APPLICATION_PATH . "/controllers/Index.php", <<<PHP
<?php
   class IndexController extends Yaf_Controller_Abstract {
         public function init() {
            var_dump("init");
         }
         public function indexAction() {
            global \$value;
            var_dump("action");
            var_dump(Yaf_Registry::get("config")->application->dispatcher->catchException);
            \$this->getView()->assignRef("ref", \$value);
         }
   }
PHP
);

file_put_contents(APPLICATION_PATH . "/views/index/index.phtml",
                "<?php var_dump('view'); \$ref = \"changed\"; ?>");

$app = new Yaf_Application($config);
$app->bootstrap()->run();

?>
--CLEAN--
<?php
/* unlink foo2.phtml permission denied */
require "build.inc"; 
shutdown();
?>
--EXPECTF--
string(13) "routerStartup"
string(14) "routerShutdown"
string(19) "dispatchLoopStartup"
string(11) "preDispatch"
string(4) "init"
string(6) "action"
bool(true)
string(12) "postDispatch"
string(43) "dispatchLoopShutdown, global var is:changed"
string(4) "view"
tests/068.phpt000064400000002057151730720470007132 0ustar00--TEST--
Check for multi inheritance of section
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php 
$config = new Yaf_Config_Ini(dirname(__FILE__) . "/multi-section.ini");
print_r($config->toArray());

?>
--EXPECTF--
Array
(
    [base] => Array
        (
            [base] => Array
                (
                    [a] => 1
                    [b] => 2
                )

        )

    [extra] => Array
        (
            [base] => Array
                (
                    [c] => 3
                )

        )

    [foo] => Array
        (
            [base] => Array
                (
                    [d] => 4
                )

        )

    [multi] => Array
        (
            [base] => Array
                (
                    [d] => 4
                    [a] => 1
                    [b] => 2
                    [c] => 3
                )

        )

    [] => Array
        (
            [base] => Array
                (
                    [d] => 4
                )

        )

)
tests/109.phpt000064400000003053151730720470007123 0ustar00--TEST--
Check for SIMD build_camel_name
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=0
yaf.lowcase_path=0
yaf.use_namespace=0
--FILE--
<?php
$name = array(
	'_a_b_cd_1_eF_g_', /* 15 bytes */
	'a_b_cd_1_eF_g_h',
	'_a_b_cd_1_eF_g_h', /* 16 bytes */
	'a_b_cd_1_eF_g_H_',
	'_a_b_cd_1_eF_g_h_', /* 17 bytes */
	'a_b_cd_1_eF_g_H_i',
	'_a_b_cd_1_eF_g_h_1', /* 18 bytes */
	'a_b_cd_1_eF_g_H_i1',
	'_a_b_cd_1_eF_g_h_iiiiii_J123_u', /* 32 bytes */
	'a_b_cd_1_eF_g_h_Jiiiii_j123_kl',
	'_a_b_cd_1_eF_g_h_iiiiii_J123k_l1', /* 34 bytes */
	'a_b_cd_1_eF_g_h_Jiiiii_j123_uV_L',
);

$request = new Yaf_Request_Simple();

setlocale(LC_ALL, "C");

function build_camel_name($u) {
    $u[0] = strtoupper($u[0]);
    for($i = 1; $i < strlen($u); $i++) {
       if ($u[$i - 1] == '_') {
		  $u[$i] = strtoupper($u[$i]);
       } else {
          $u[$i] = strtolower($u[$i]);
       }
    }
	return $u;
}

/* standard test */
foreach ($name as $u) {
	$request->setControllerName($u);
    if ($request->getControllerName() != build_camel_name($u)) {
		echo $u, ": expected: " , build_camel_name($u), "; got: ", $request->getControllerName(), "\n";
    }
}

/* random test */
$i = 0;
while ($i++ < 1024) {
	$len = rand(1, 64);
    $u = str_repeat(' ', $len);
    for ($c = 0; $c < $len; $c++) {
       @$u[$c] = rand(1, 255);
    }
	$request->setControllerName($u);
	if ($request->getControllerName() != build_camel_name($u)) {
		echo $u, ": expected: " , build_camel_name($u), "; got: ", $request->getControllerName(), "\n";
	}
}
?>
okey
--EXPECT--
okey
tests/041.phpt000064400000003256151730720470007123 0ustar00--TEST--
Check for controller return false preventing auto-renderring
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php 
$config = array(
	"application" => array(
		"directory" => realpath(dirname(__FILE__)),
		"dispatcher" => array(
			"catchException" => 0,
			"throwException" => 1,
		),
        "modules" => "module",
	),
);

class ControllerController extends Yaf_Controller_Abstract {
    public function actionAction() {
    }

    public function indexAction() {
        $this->forward("controller", "dummy");
        return FALSE; /* don't auto-render */
    }

    public function dummyAction() {
        Yaf_Dispatcher::getInstance()->enableView();
    }
}


$app = new Yaf_Application($config);
$request = new Yaf_Request_Http("/module/controller/action");

try {
  $app->getDispatcher()->returnResponse(false)->dispatch($request);
} catch (Yaf_Exception $e) {
  echo $e->getMessage(), "\n";
}

$view = new Yaf_View_Simple(dirname(__FILE__) . 'no-exists');
$app->getDispatcher()->setView($view);
try {
  $app->getDispatcher()->returnResponse(false)->dispatch($request);
} catch (Yaf_Exception $e) {
  echo $e->getMessage(), "\n";
}

$request = new Yaf_Request_Http("/module/controller/index");
try {
  $app->getDispatcher()->returnResponse(false)->dispatch($request);
} catch (Yaf_Exception $e) {
  echo $e->getMessage(), "\n";
}
?>
--EXPECTF--
Failed opening template %stests%cmodules%cModule%cviews%ccontroller%caction.phtml: No such file or directory
Failed opening template %stestsno-exists%ccontroller%caction.phtml: No such file or directory
Failed opening template %stestsno-exists%ccontroller%cdummy.phtml: No such file or directory
tests/101.phpt000064400000001202151730720470007105 0ustar00--TEST--
Check for various  cycle references
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=0
yaf.lowcase_path=0
yaf.use_namespace=0
--FILE--
<?php 
$foo = new Stdclass();
$foo->request = new Yaf_Request_Simple();
$foo->request->setParam("foo", $foo);
unset($foo);

$foo = new Stdclass();
$foo->config = new Yaf_Config_Simple(array(), 0);
$foo->config->foo = $foo;
unset($foo);

$foo = new Stdclass();
$foo->request = new Yaf_Request_Simple();
$app = new Yaf_Application(["yaf" => ["directory" => __DIR__]]);
$app->getDispatcher()->setRequest($foo->request);
unset($foo);
?>
okey
--EXPECT--
okey
tests/104.phpt000064400000010551151730720470007117 0ustar00--TEST--
Check for Yaf_Dispatcher::dispatch() of errors while loading executor
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
yaf.use_spl_autoload=0
--FILE--
<?php 
require "build.inc";
startup();

$config = array(
	"application" => array(
		"directory" => APPLICATION_PATH,
	),
);
$app = new Yaf_Application($config);
$dispatcher = $app->getDispatcher();

$request = new Yaf_Request_Simple();
set_error_handler(function ($no, $msg) {
	var_dump(substr($msg, 0, 100));
});
$request->setControllerName(str_repeat("Index", 1024 * 1024));

try {
	$dispatcher->dispatch($request);
} catch (Exception $e) {
	var_dump(substr($e->getMessage(), 0, 100));
}
$request->setControllerName("index");

try {
	$dispatcher->dispatch($request);
} catch (Exception $e) {
	var_dump($e->getMessage());
}

file_put_contents(APPLICATION_PATH . "/controllers/Index.php", "xxx");
try {
	$dispatcher->dispatch($request);
} catch (Exception $e) {
	var_dump($e->getMessage());
}

file_put_contents(APPLICATION_PATH . "/controllers/Index.php", <<<PHP
<?php
class IndexController  {
    public function indexAction() {
    }    
}
PHP
);
try {
	$dispatcher->dispatch($request);
} catch (Exception $e) {
	var_dump($e->getMessage());
}

$request->setControllerName("dummy");
file_put_contents(APPLICATION_PATH . "/controllers/Dummy.php", <<<PHP
<?php
class DummyController extends Yaf_Controller_Abstract {
}
PHP
);
try {
	$dispatcher->dispatch($request);
} catch (Exception $e) {
	var_dump($e->getMessage());
}

$request->setControllerName("dummy1");
file_put_contents(APPLICATION_PATH . "/controllers/Dummy1.php", <<<PHP
<?php
class Dummy1Controller extends Yaf_Controller_Abstract {
	public \$actions;
}
PHP
);
try {
	$dispatcher->dispatch($request);
} catch (Exception $e) {
	var_dump($e->getMessage());
}

$request->setControllerName("dummy2");
file_put_contents(APPLICATION_PATH . "/controllers/Dummy2.php", <<<PHP
<?php
class Dummy2Controller extends Yaf_Controller_Abstract {
	public \$actions = array();
}
PHP
);
try {
	$dispatcher->dispatch($request);
} catch (Exception $e) {
	var_dump($e->getMessage());
}

$request->setControllerName("dummy3");
file_put_contents(APPLICATION_PATH . "/controllers/Dummy3.php", <<<PHP
<?php
class Dummy3Controller extends Yaf_Controller_Abstract {
	public \$actions = array("index" => NULL);
}
PHP
);
try {
	$dispatcher->dispatch($request);
} catch (Exception $e) {
	var_dump($e->getMessage());
}

$request->setControllerName("dummy4");
file_put_contents(APPLICATION_PATH . "/controllers/Dummy4.php", <<<PHP
<?php
class Dummy4Controller extends Yaf_Controller_Abstract {
	public \$actions = array(
		"index" => "actions/index.php",
		"foo" => "actions/foo.php",
	);
}
PHP
);
try {
	$dispatcher->dispatch($request);
} catch (Exception $e) {
	var_dump($e->getMessage());
}

file_put_contents(APPLICATION_PATH . "/actions/index.php", <<<PHP
<?php
class IndexAction {
}
PHP
);
try {
	$dispatcher->dispatch($request);
} catch (Exception $e) {
	var_dump($e->getMessage());
}
try {
	$dispatcher->dispatch($request);
} catch (Exception $e) {
	var_dump($e->getMessage());
}

$request->setActionName("foo");
file_put_contents(APPLICATION_PATH . "/actions/foo.php", <<<PHP
<?php
class FooAction extends Yaf_Action_Abstract {
}
PHP
);
$dispatcher->dispatch($request);
?>
--CLEAN--
<?php
require "build.inc"; 
shutdown();
?>
--EXPECTF--
string(100) "path too long while loading 'Indexindexindexindexindexindexindexindexindexindexindexindexindexindexi"
string(%d) "Failed opening controller script %sIndex.php: No such file or directory"
xxxstring(%d) "Could not find class IndexController in controller script %sIndex.php"
string(73) "Controller 'IndexController' is not a subclass of Yaf_Controller_Abstract"
string(49) "There is no method indexAction in DummyController"
string(50) "There is no method indexAction in Dummy1Controller"
string(60) "There is no method indexAction in Dummy2Controller::$actions"
string(70) "Action 'index' in Dummy3Controller::actions does not have a valid path"
string(%s) "Failed opening action script %sindex.php: No such file or directory"
string(61) "Action 'IndexAction' is not a subclass of Yaf_Action_Abstract"
string(61) "Action 'IndexAction' is not a subclass of Yaf_Action_Abstract"

Fatal error: Class FooAction contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Yaf_Action_Abstract::execute) in %sfoo.php on line %d
tests/082.phpt000064400000001170151730720470007121 0ustar00--TEST--
Check for variables out of scope
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.library="/php/global/dir"
log_errors=0
display_errors=1
yaf.use_namespace=0
--FILE--
<?php
require "build.inc";
startup();

$view = new Yaf_View_Simple(DIR_ROOT);
$view->assign("name", "laruence");
$tpl  =  APPLICATION_PATH . '/tpls/foo.phtml';

file_put_contents($tpl, <<<HTML
<?php
   echo \$name, \$tpl;
HTML
);

echo $view->render($tpl);
?>
--CLEAN--
<?php
/* unlink foo2.phtml permission denied */
require "build.inc"; 
shutdown();
?>
--EXPECTF--
laruence
%s: Undefined variable%stpl in %sfoo.phtml on line %dtests/064.phpt000064400000002462151730720470007126 0ustar00--TEST--
Check for Yaf_Route_Regex with dynamic mvc
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php 
$request = new Yaf_Request_Http("/subdir/ctl/act/name/value");

$router = new Yaf_Router();

$route  = new Yaf_Route_Regex(
	"#subdir/(?<c>.*?)/(.*?)/.*#",
	array(
        "module" => "m",
        "controller" => ":c",
		"action" => ":a",
	),
    array(
        2 => "a",
    )
);

$router->addRoute("subdir", $route)->addRoute("yaf", new Yaf_Route_Regex(
	"#yaf/(.*?)/.*#",
    array(
		"action" => ':action',
        "controller" => "index",
	),
    array(
        1 => "action",
    )
))->route($request);

var_dump($router->getCurrentRoute());
print_r($request->getParams());
var_dump($request->getActionName());
var_dump($request->getControllerName());
var_dump($request->getModuleName());

$request = new Yaf_Request_Http("/yaf/act/name/value");
$router->route($request);

var_dump($router->getCurrentRoute());
print_r($request->getParams());
var_dump($request->getActionName());
var_dump($request->getControllerName());
var_dump($request->getModuleName());

?>
--EXPECTF--
string(6) "subdir"
Array
(
    [c] => ctl
    [a] => act
)
string(3) "act"
string(3) "Ctl"
string(1) "M"
string(3) "yaf"
Array
(
    [action] => act
)
string(3) "act"
string(5) "Index"
NULL
tests/032.phpt000064400000001161151730720470007114 0ustar00--TEST--
Check for Yaf_Config_Ini with env
--SKIPIF--
<?php 
if (!extension_loaded("yaf")) print "skip"; 
if (substr(PHP_OS, 0, 3) == 'WIN') {
    die('skip seems windows doesnt support this');
}
?>
--INI--
yaf.directory=/foo/bar
yaf.use_namespace=0
--FILE--
<?php 
putenv("FOO=bar");
define("FOO", "Dummy");
print_r(new Yaf_Config_Ini(
	dirname(__FILE__) . "/simple.ini", "envtest"));
?>
--EXPECTF--
Yaf_Config_Ini Object
(
    [readonly:protected] => 1
    [config:protected] => Array
        (
            [env] => bar
            [ini] => /foo/bar
            [const] => Dummy
        )

    [filename:protected] => %s
)
tests/069.phpt000064400000001400151730720470007122 0ustar00--TEST--
Fixed bug that alter_response is not binary safe
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=0
yaf.lowcase_path=0
yaf.use_namespace=0
--FILE--
<?php 
require "build.inc";
startup();

$config = array(
	"application" => array(
		"directory" => APPLICATION_PATH,
	),
);

file_put_contents(APPLICATION_PATH . "/controllers/Index.php", <<<PHP
<?php
   class IndexController extends Yaf_Controller_Abstract {
         public function indexAction() {
         }
   }
PHP
);


file_put_contents(APPLICATION_PATH . "/views/index/index.phtml", "head <?php echo chr(0);?> tail" . PHP_EOL);

$app = new Yaf_Application($config);
$app->run();
?>
--CLEAN--
<?php
require "build.inc"; 
shutdown();
?>
--EXPECTF--
head  tail
tests/039.phpt000064400000001530151730720470007123 0ustar00--TEST--
Check for Yaf_View_Simple recursive render error message outputing
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.library="/php/global/dir"
log_errors=0
display_errors=1
yaf.use_namespace=0
--FILE--
<?php
require "build.inc";
startup();

$view = new Yaf_View_Simple(DIR_ROOT);
$view->assign("name", "laruence");
$tpl  =  APPLICATION_PATH . '/tpls/foo.phtml';
$tpl2  =  APPLICATION_PATH . '/tpls/foo2.phtml';

file_put_contents($tpl, <<<HTML
<?php
   echo \$this->render(\$tpl);
?>
HTML
);

file_put_contents($tpl2, <<<HTML
<?php
   if ((1) { //syntax error
   }
?>
HTML
);

try {
	echo $view->render($tpl, array('tpl' => $tpl2));
} catch (Error $e) {
	echo $e->getMessage();
}
?>
--CLEAN--
<?php
/* unlink foo2.phtml permission denied */
require "build.inc"; 
shutdown();
?>
--EXPECTF--
syntax error, unexpected %s}%c
tests/095.phpt000064400000003457151730720470007137 0ustar00--TEST--
Check for Yaf_Request read/write property
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=0
yaf.use_namespace=0
--FILE--
<?php

function ref_change(&$val) {
	$val = "bad";
}

$app = new Yaf_Application(array(
	"yaf" => array(
		"directory" => __DIR__ ,
	),
));

foreach (array(
	"environ", "running", "config", "library",
    "directory", "ext", "view_ext", "err_no", "err_msg",
   "bootstrap", "dispatcher", 123, "noexists", ) as $k) {
	print "Testing $k:\n";
	var_dump($app->{$k});
	$app->{$k} = true;
	var_dump($app->{$k});
	$app->{$k} = "inDex";
	ref_change($app->{$k});
	var_dump($app->{$k});
	echo "\n";
}

var_dump($app);
?>
--EXPECTF--
Testing environ:
NULL
NULL
NULL

Testing running:
NULL
NULL
NULL

Testing config:
NULL
NULL
NULL

Testing library:
NULL
NULL
string(5) "inDex"

Testing directory:
string(%d) "%s"
string(%d) "%s"
string(5) "inDex"

Testing ext:
NULL
NULL
string(5) "inDex"

Testing view_ext:
NULL
NULL
string(5) "inDex"

Testing err_no:
NULL
NULL
NULL

Testing err_msg:
NULL
NULL
NULL

Testing bootstrap:
NULL
NULL
string(5) "inDex"

Testing dispatcher:
NULL
NULL
NULL

Testing 123:
NULL
NULL
NULL

Testing noexists:
NULL
NULL
NULL

object(Yaf_Application)#1 (13) {
  ["directory"]=>
  string(5) "inDex"
  ["library"]=>
  string(5) "inDex"
  ["bootstrap"]=>
  string(5) "inDex"
  ["ext"]=>
  string(5) "inDex"
  ["view_ext"]=>
  string(5) "inDex"
  ["environ:protected"]=>
  string(7) "product"
  ["running:protected"]=>
  bool(false)
  ["err_msg:protected"]=>
  NULL
  ["err_no:protected"]=>
  int(0)
  ["config:protected"]=>
  object(Yaf_Config_Simple)#%d (%d) {
%A
  }
  ["dispatcher:protected"]=>
  object(Yaf_Dispatcher)#%d (%d) {
%A
  }
  ["modules:protected"]=>
  array(1) {
    [0]=>
    string(5) "Index"
  }
  ["default_route:protected"]=>
  NULL
}
tests/070.phpt000064400000001004151730720470007112 0ustar00--TEST--
Fixed misleading error message when providing a string in Yaf_Application construction
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php

$config = <<<INI
[product]
;CONSTANTS is supported
application.directory = APP_PATH "/application/"
INI;

try {
	$app = new Yaf_Application($config);
	$app->run();
}
catch (Exception $e){
	print $e->getPrevious()->getMessage();
}

?>
--CLEAN--
--EXPECTF--
Expects a path to *.ini configuration file as parameter
tests/012.phpt000064400000001434151730720470007115 0ustar00--TEST--
Check for Yaf_Route_Regex
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php 
$request = new Yaf_Request_Http("/subdir/ap/1.2/name/value", "/subdir");

$router = new Yaf_Router();

$route  = new Yaf_Route_regex(
	"#/subdir/(.*)#",
	array(
		"action" => "version",
	),
	array(
	)
);

$router->addRoute("subdir", $route)->addRoute("ap", new Yaf_Route_Regex(
	"#^/ap/([^/]*)/*#i",
    array(
		"action" => 'ap',
	),
	array(
		1 => 'version',
	)
))->route($request);

var_dump($router->getCurrentRoute());
var_dump($request->getParam('version'));
var_dump($request->getActionName());
var_dump($request->getControllerName());
var_dump($request->getParam('name'));

?>
--EXPECTF--
string(2) "ap"
string(3) "1.2"
string(2) "ap"
NULL
NULL
tests/033.phpt000064400000003242151730720470007117 0ustar00--TEST--
Check for Yaf_View_Simple with predefined template dir
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php 
$config = array(
	"application" => array(
		"directory" => realpath(dirname(__FILE__)),
		"dispatcher" => array(
			"catchException" => 0,
			"throwException" => 1,
		),
        "modules" => "module",
	),
);

class ControllerController extends Yaf_Controller_Abstract {
    public function actionAction() {
    }

    public function indexAction() {
        Yaf_Dispatcher::getInstance()->disableView();
        $this->forward("dummy");
    }

    public function dummyAction() {
        Yaf_Dispatcher::getInstance()->enableView();
    }
}


$app = new Yaf_Application($config);
$request = new Yaf_Request_Http("/module/controller/action");

try {
  $app->getDispatcher()->returnResponse(false)->dispatch($request);
} catch (Yaf_Exception $e) {
  echo $e->getMessage(), "\n";
}

$view = new Yaf_View_Simple(dirname(__FILE__) . 'no-exists');
$app->getDispatcher()->setView($view);
try {
  $app->getDispatcher()->returnResponse(false)->dispatch($request);
} catch (Yaf_Exception $e) {
  echo $e->getMessage(), "\n";
}

$request = new Yaf_Request_Http("/module/controller/index");
try {
  $app->getDispatcher()->returnResponse(false)->dispatch($request);
} catch (Yaf_Exception $e) {
  echo $e->getMessage(), "\n";
}
?>
--EXPECTF--
Failed opening template %stests%cmodules%cModule%cviews%ccontroller%caction.phtml: No such file or directory
Failed opening template %stestsno-exists%ccontroller%caction.phtml: No such file or directory
Failed opening template %stestsno-exists%ccontroller%cdummy.phtml: No such file or directory
tests/065.phpt000064400000001436151730720470007127 0ustar00--TEST--
Yaf_Route_Regex map is optional
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php 

$request = new Yaf_Request_Http("/subdir/ap/1.2/name/value", "/subdir");

$router = new Yaf_Router();

$router->addConfig(
 array(
    array(
    "type" => "regex",
    "match" => "#^/ap/([^/]*)/*#i",
    "route" => array(
        array(
            "action" => 'ap',
            ),
        ),
  ) 
 )
)->route($request);

var_dump($router->getCurrentRoute());
var_dump($request->getActionName());


$router->addRoute("regex", new Yaf_Route_Regex("#^/ap/([^/]*)/*#i", array("action" => "ap")))->route($request);

var_dump($router->getCurrentRoute());
var_dump($request->getActionName());

?>
--EXPECT--
int(0)
NULL
string(5) "regex"
string(2) "ap"
tests/008.phpt000064400000002766151730720470007133 0ustar00--TEST--
Check for Yaf_Router basic usages
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php

$router = new Yaf_Router();

$route  = new Yaf_Route_Simple('m', 'c', 'a');
$sroute = new Yaf_Route_Supervar('r');

$router->addRoute("simple", $route)->addRoute("super", $sroute);
print_r($router);
var_dump($router->getCurrentRoute());
print_r($router->getRoutes());
print_r($router->getRoute("simple"));
var_dump($router->getRoute("noexists"));
?>
--EXPECTF--
Yaf_Router Object
(
    [routes:protected] => Array
        (
            [_default] => Yaf_Route_Static Object
                (
                )

            [simple] => Yaf_Route_Simple Object
                (
                    [module:protected] => m
                    [controller:protected] => c
                    [action:protected] => a
                )

            [super] => Yaf_Route_Supervar Object
                (
                    [varname:protected] => r
                )

        )

    [current:protected] => 
)
NULL
Array
(
    [_default] => Yaf_Route_Static Object
        (
        )

    [simple] => Yaf_Route_Simple Object
        (
            [module:protected] => m
            [controller:protected] => c
            [action:protected] => a
        )

    [super] => Yaf_Route_Supervar Object
        (
            [varname:protected] => r
        )

)
Yaf_Route_Simple Object
(
    [module:protected] => m
    [controller:protected] => c
    [action:protected] => a
)
NULL
tests/multi-section.ini000064400000000202151730720470011203 0ustar00[base ]
base.a=1
base.b=2
[ extra]
base.c=3
[ foo]
base.d=4

[ multi:: extra: base  : foo ]
[ ::multi2::::: base:]
[: : :: : foo]
tests/022.phpt000064400000001451151730720470007115 0ustar00--TEST--
Check for Yaf_Application::get/setAppDirectory
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php 
$config = array(
	"application" => array(
		"directory" => realpath(dirname(__FILE__)),
		"dispatcher" => array(
			"catchException" => 0,
			"throwException" => 0,
		),
	),
);

$app = new Yaf_Application($config);
var_dump($app->getAppDirectory());
$dir = $app->getAppDirectory() . "/tmp";
mkdir($dir);
$app->setAppDirectory($dir);
var_dump($app->getAppDirectory());
$app->run();
?>
--CLEAN--
<?php
rmdir(dirname(__FILE__) . "/tmp");
?>
--EXPECTF--
string(%d) "%stests"
string(%d) "%stmp"

%s fatal error: Yaf_Application::run(): Failed opening controller script %stmp%ccontrollers%cIndex.php: No such file or directory in %s022.php on line %d
tests/081.phpt000064400000000542151730720470007122 0ustar00--TEST--
PHP7 Yaf_Response leak memory
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php 
$response = new Yaf_Response_Cli();
$string = "Jason is a good boy";
$response->setBody($string);
$response->setBody($string);
var_dump($response->getBody());
?>
--EXPECTF--
string(19) "Jason is a good boy"
tests/067.phpt000064400000002731151730720470007130 0ustar00--TEST--
Check actions map with defined action class
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=0
yaf.lowcase_path=0
yaf.use_namespace=0
--FILE--
<?php 
require "build.inc";
startup();

$config = array(
	"application" => array(
		"directory" => APPLICATION_PATH,
	),
);

file_put_contents(APPLICATION_PATH . "/controllers/Index.php", <<<PHP
<?php
   class IndexController extends Yaf_Controller_Abstract {
		public \$actions = array(
				"sub" => "actions/sub.php",
			);
         public function indexAction() {
             var_dump(\$this->forward('sub'));
         }
   }
PHP
);

file_put_contents(APPLICATION_PATH . "/actions/sub.php", <<<PHP
<?php
   class SubAction extends Yaf_Action_Abstract {
         public function execute() {
			var_dump(\$this->getModuleName());
			var_dump(\$this->getControllerName());
         }
   }
PHP
);

file_put_contents(APPLICATION_PATH . "/views/index/index.phtml", "indexAction" . PHP_EOL);
file_put_contents(APPLICATION_PATH . "/views/index/sub.phtml", "subAction" . PHP_EOL);

$app = new Yaf_Application($config);
$request = new Yaf_Request_Simple();
$app->getDispatcher()->dispatch($request);
$new_request = new Yaf_Request_Simple();
$new_request->setActionName('sub');
$app->getDispatcher()->dispatch($new_request);
?>
--CLEAN--
<?php
require "build.inc"; 
shutdown();
?>
--EXPECTF--
bool(true)
string(5) "Index"
string(5) "Index"
indexAction
subAction
string(5) "Index"
string(5) "Index"
subAction
tests/055.phpt000064400000001075151730720470007125 0ustar00--TEST--
check for Yaf_Dispatcher::autoRender
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=0
yaf.lowcase_path=0
yaf.environ="product"
yaf.use_namespace=0
--FILE--
<?php
define("APPLICATION_PATH", dirname(__FILE__));
$app = new Yaf_Application(APPLICATION_PATH . '/simple.ini');
Yaf_Dispatcher::getInstance()->autoRender(true);
var_dump(Yaf_Dispatcher::getInstance()->autoRender());
Yaf_Dispatcher::getInstance()->autoRender(false);
var_dump(Yaf_Dispatcher::getInstance()->autoRender());
?>
--EXPECTF--
bool(true)
bool(false)
tests/044.phpt000064400000001012151730720470007112 0ustar00--TEST--
Memleaks in Yaf_Dispatcher::getInstance()
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
yaf.environ="product"
yaf.use_namespace=0
--FILE--
<?php
define("APPLICATION_PATH", dirname(__FILE__));
$app = new Yaf_Application(APPLICATION_PATH . '/simple.ini');
Yaf_Dispatcher::getInstance();
$a = Yaf_Dispatcher::getInstance();
unset($a);
Yaf_Dispatcher::getInstance();
$b = Yaf_Dispatcher::getInstance();
var_dump(get_class($b));
?>
--EXPECTF--
string(14) "Yaf_Dispatcher"
tests/issue134.phpt000064400000000741151730720500010165 0ustar00--TEST--
ISSUE #134 (Segfault while calling assemble)
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php
$router = new Yaf_Router();
$route  = new Yaf_Route_Rewrite(
	"/detail/:id",
	array(
		'controller' => 'index',
		'action' => 'detail',
		'module' => 'kfc'
	)
);
$router->addRoute("kfc/index/detail", $route);

print_r($router->getRoute('kfc/index/detail')->assemble(
	array(
		':id' => '1',
	)
));
--EXPECTF--
/detail/1
tests/001.phpt000064400000001022151730720500007076 0ustar00--TEST--
Check for yaf presence
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--FILE--
<?php 
echo "yaf extension is available";
/*
	you can add regression tests for your extension here

  the output of your test code has to be equal to the
  text in the --EXPECT-- section below for the tests
  to pass, differences between the output and the
  expected text are interpreted as failure

  see php5/README.TESTING for further information on
  writing regression tests
*/
?>
--EXPECT--
yaf extension is available
tests/030.phpt000064400000000630151730720500007104 0ustar00--TEST--
Check for Yaf_Config_Ini::__construct with section
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.library="/php/global/dir"
yaf.use_namespace=0
--FILE--
<?php
$file = dirname(__FILE__) . "/simple.ini";

try {
  $config = new Yaf_Config_Ini($file, "ex");
} catch (Exception $e) { 
  print_r($e->getMessage());
}

?>
--EXPECTF--
There is no section 'ex' in '%ssimple.ini'
tests/071.phpt000064400000000426151730720500007114 0ustar00--TEST--
return type in Yaf_Simple_Config::valid() should be boolean
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php

$new = new Yaf_Config_Simple(array());
var_dump($new->valid());
?>
--CLEAN--
--EXPECTF--
bool(false)
tests/bug76217.phpt000064400000002106151730720500007766 0ustar00--TEST--
Bug #76217 (Memory leaks with Yaf_Dispatcher::setDefault*)
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php
require "build.inc";
startup();

file_put_contents(APPLICATION_PATH . "/Bootstrap.php", <<<PHP
<?php
class Bootstrap extends Yaf_Bootstrap_Abstract
{
    public function _initView(Yaf_Dispatcher \$dispatcher)
    {
        \$dispatcher->setDefaultModule("index")
                    ->setDefaultController("admin")
                    ->setDefaultAction("login");
    }
}
PHP
);

file_put_contents(APPLICATION_PATH . "/controllers/Admin.php", <<<PHP
<?php
class AdminController extends Yaf_Controller_Abstract
{
     public function loginAction()
     {
         var_dump("index/admin/login");
         return false;
     }
}
PHP
);

$config = array(
    "application" => array(
        "directory" => APPLICATION_PATH,
        "modules" => "Index,User,Admin",
    ),
);

$app = new Yaf_Application($config);
$app->bootstrap()->run();
?>
--CLEAN--
<?php
require "build.inc"; 
shutdown();
?>
--EXPECTF--
string(%d) "%s"
tests/bug70913.phpt000064400000002237151730720500007770 0ustar00--TEST--
Bug #70913 (Segfault while new Yaf_Controller)
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=1
yaf.lowcase_path=0
yaf.throw_exception=0
yaf.catch_exception=1
yaf.use_namespace=0
--FILE--
<?php 
require "build.inc";
startup();

$config = array(
	"application" => array(
		"directory" => APPLICATION_PATH,
	),
);

file_put_contents(APPLICATION_PATH . "/controllers/Index.php", <<<PHP
<?php
   class IndexController extends Yaf_Controller_Abstract {
		public function indexAction() {
			new SecondController(\$this->getRequest(), \$this->getResponse(), \$this->getView());
		}
   }
PHP
);

file_put_contents(APPLICATION_PATH . "/controllers/Second.php", <<<PHP
<?php
   class SecondController extends Yaf_Controller_Abstract {
		public function __construct(\$request, \$response, \$view) {}
   }
PHP
);

file_put_contents(APPLICATION_PATH . "/views/index/index.phtml", "Okey\n");

$app = new Yaf_Application($config);
$response = $app->run();
print_r($response);
?>
--CLEAN--
<?php
require "build.inc"; 
shutdown();
?>
--EXPECT--
Okey
Yaf_Response_Cli Object
(
    [response_code:protected] => 0
    [header_sent:protected] => 
)
tests/075.phpt000064400000001602151730720500007115 0ustar00--TEST--
Check for Yaf_Route_Regex::assemble
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php

$router = new Yaf_Router();

$route  = new Yaf_Route_Regex(
            "#^/product/([^/]+)/([^/])+#",
            array(
                'controller' => "product",  //route to product controller,
                ),
            array(),
            array(),
            '/:m/:c/:a'
        );

$router->addRoute("regex", $route);

var_dump($router->getRoute('regex')->assemble(
            array(
                ':m' => 'module',
                ':c' => 'controller',
                ':a' => 'action'
                ),
            array(
                'tkey1' => 'tval1',
                'tkey2' =>
                'tval2'
                )
            )
        );
--EXPECTF--
string(49) "/module/controller/action?tkey1=tval1&tkey2=tval2"
tests/077.phpt000064400000001523151730720500007121 0ustar00--TEST--
Check for Yaf_Route_Static::assemble
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php

$router = new Yaf_Router();

$route  = new Yaf_Route_Static();

$router->addRoute("static", $route);

var_dump($router->getRoute('static')->assemble(
			array(
				':a' => 'yafaction',
				'tkey' => 'tval',
				':c' => 'yafcontroller',
				':m' => 'yafmodule'
	        ),
			array(
				'tkey1' => 'tval1',
				'tkey2' => 'tval2'
		    )
		)
);

var_dump($router->getRoute('static')->assemble(
			array(
				':a' => 'yafaction',
				'tkey' => 'tval',
				':c' => 'yafcontroller',
				':m' => 'yafmodule'
	        ),
			array(
				1 => 2,
				array(),
		    )
		)
);
--EXPECTF--
string(%d) "/yafmodule/yafcontroller/yafaction?tkey1=tval1&tkey2=tval2"
string(%d) "/yafmodule/yafcontroller/yafaction"
tests/040.phpt000064400000000550151730720500007106 0ustar00--TEST--
Fixed bug that segv in Yaf_View_Simple::render if the tpl is not a string
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.library="/php/global/dir"
yaf.use_namespace=0
--FILE--
<?php
$view = new Yaf_View_Simple(dirname(__FILE__));
$view->render(NULL);
$view->render(0);
$view->render(true);
echo "okey";
?>
--EXPECT--
okey
tests/034.phpt000064400000001045151730720500007111 0ustar00--TEST--
Check for Yaf_View_Simple::eval
--SKIPIF--
<?php
if (!extension_loaded("yaf")) print "skip";
if (substr(PHP_OS, 0, 3) == 'WIN') {
    die('skip windows has a different absolute path');
}
?>
--INI--
yaf.use_namespace=0
--FILE--
<?php 
$view = new Yaf_View_Simple("/tmp");

$tpl = <<<PHP
<?php
echo \$name, "\n";
foreach(\$entry as \$list) {
   echo "1. ", \$list, "\n";
}
?>
<?=\$name?>
PHP;

$view->assign("entry", array('a', 'b', 'c'));
echo $view->eval($tpl, array('name' => 'template'));

?>
--EXPECTF--
template
1. a
1. b
1. c
template
tests/027.phpt000064400000001601151730720500007111 0ustar00--TEST--
Check for Yaf autoload controller
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=0
yaf.library="/php/global/dir"
yaf.environ="product"
yaf.use_namespace=0
--FILE--
<?php 
$config = array(
		"application" => array(
			"directory" => realpath(dirname(__FILE__)),
			"dispatcher" => array(
				"catchException" => 0,
				"throwException" => 0,
				),
			),
		);

function main() {
    $dummy = new NoExistsController();
}

$app = new Yaf_Application($config);
var_dump($app->environ());
var_dump(count($app->getConfig()->application));
$app->execute("main");
$app->execute(123);
?>
--EXPECTF--
string(7) "product"
int(2)

Warning: Yaf_Loader::autoload(): Failed opening script %scontrollers%cNoExists.php: No such file or directory in %s027.php on line %d

Fatal error: Uncaught Error: Class %sNoExistsController%s not found in %s027.php:%d
%a

tests/031.phpt000064400000001674151730720500007116 0ustar00--TEST--
Check for application.dispatcher.defaultRoute
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.library="/php/global/dir"
yaf.use_namespace=0
--FILE--
<?php 
$config = array(
	"application" => array(
		"directory" => realpath(dirname(__FILE__)),
        "dispatcher" => array(
            "defaultRoute" => array(
               "type" => "map",
               "delimiter" => '##',
               "controllerPrefer" => 1,
            ),
         ),
	),
);

$app = new Yaf_Application($config);
print_r($app->getDispatcher()->getRouter()->getRoutes());
var_export($app->getDispatcher()->getRouter()->getRoutes());
?>
--EXPECTF--
Array
(
    [_default] => Yaf_Route_Map Object
        (
            [ctl_prefer:protected] => 1
            [delimiter:protected] => ##
        )

)
array (
  '_default' => 
  %saf_Route_Map::__set_state(array(
     'ctl_prefer:protected' => true,
     'delimiter:protected' => '##',
  )),
)
tests/020.phpt000064400000001565151730720500007113 0ustar00--TEST--
Check for Yaf_Application errors variables
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php 
$config = array(
	"application" => array(
		"directory" => realpath(dirname(__FILE__)),
		"dispatcher" => array(
			"catchException" => 0,
			"throwException" => 0,
		),
	),
);

function error_handler($errno, $errstr, $errfile, $errline) {
	var_dump(Yaf_Application::app()->getLastErrorNo());
	var_dump(Yaf_Application::app()->getLastErrorMsg());
	Yaf_Application::app()->clearLastError();
	var_dump(Yaf_Application::app()->getLastErrorNo());
	var_dump(Yaf_Application::app()->getLastErrorMsg());
}

$app = new Yaf_Application($config);
$app->getDispatcher()->setErrorHandler("error_handler", E_RECOVERABLE_ERROR);
$app->run();
?>
--EXPECTF--
int(516)
string(%d) "Failed opening controller script %s: %s"
int(0)
string(0) ""
tests/099.phpt000064400000006213151730720500007126 0ustar00--TEST--
Check for Multiple exception in plugins
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=0
yaf.lowcase_path=0
yaf.use_namespace=0

--FILE--
<?php 
require "build.inc";
startup();

$config = array(
	"application" => array(
		"directory" => APPLICATION_PATH,
        "dispatcher" => array (
           "catchException" => true,
        ), 
        "library" => array(
        ),
	),
);

file_put_contents(APPLICATION_PATH . "/controllers/Error.php", <<<PHP
<?php
   class ErrorController extends Yaf_Controller_Abstract {
         public function errorAction() {
            \$this->_view->msg = \$this->getRequest()->getException()->getMessage();
         }
   }
PHP
);

file_put_contents(APPLICATION_PATH . "/Bootstrap.php", <<<PHP
<?php
   class Bootstrap extends Yaf_Bootstrap_Abstract {
        public function _initConfig(Yaf_Dispatcher \$dispatcher) {
            Yaf_Registry::set("config", Yaf_Application::app()->getConfig());
        }
        public function _initPlugin(Yaf_Dispatcher \$dispatcher) {
            \$dispatcher->registerPlugin(new TestPlugin());
        }
        public function _initReturn(Yaf_Dispatcher \$dispatcher) {
  //          \$dispatcher->returnResponse(true);
        }
   }
PHP
);

file_put_contents(APPLICATION_PATH . "/plugins/Test.php", <<<PHP
<?php
   class TestPlugin extends Yaf_Plugin_Abstract {
        public function routerStartup(Yaf_Request_Abstract \$request, Yaf_Response_Abstract \$response) {
            throw new Exception("routerStartup");
        }
        public function routerShutdown(Yaf_Request_Abstract \$request, Yaf_Response_Abstract \$response) {
            throw new Exception("routerShutdown");
        }
        public function dispatchLoopStartup(Yaf_Request_Abstract \$request, Yaf_Response_Abstract \$response) {
            throw new Exception("dispatchLoopStartup");
        }
        public function preDispatch(Yaf_Request_Abstract \$request, Yaf_Response_Abstract \$response) {
            throw new Exception("preDispatch");
        }
        public function postDispatch(Yaf_Request_Abstract \$request, Yaf_Response_Abstract \$response) {
            throw new Exception("postDispatch");
        }
        public function dispatchLoopShutdown(Yaf_Request_Abstract \$request, Yaf_Response_Abstract \$response) {
           throw new Exception("dispatchLoopShutdown");
        }
   }
PHP
);

file_put_contents(APPLICATION_PATH . "/controllers/Index.php", <<<PHP
<?php
   class IndexController extends Yaf_Controller_Abstract {
         public function init() {
            var_dump("init");
         }
         public function indexAction() {
            var_dump("action");
         }
   }
PHP
);

file_put_contents(APPLICATION_PATH . "/views/index/index.phtml",
                "<?php throw new Exception('view exception'); ?>");

mkdir(APPLICATION_PATH . "/views/error/");
file_put_contents(APPLICATION_PATH . "/views/error/error.phtml",
                "catched: <?=\$msg?>");

$app = new Yaf_Application($config);
$app->bootstrap()->run();
?>
--CLEAN--
<?php
/* unlink foo2.phtml permission denied */
require "build.inc"; 
shutdown();
?>
--EXPECT--
catched: routerStartup
tests/066.phpt000064400000001264151730720500007121 0ustar00--TEST--
Check for Yaf_Route_Regex with abnormal map
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php 
$request = new Yaf_Request_Http("/subdir/ap/1.2/xxx/name/value", "/subdir");

$router = new Yaf_Router();

$router->addRoute("ap", new Yaf_Route_Regex(
	"#^/ap/([^/]*)/([^/]*)/*#i",
    array(
		"action" => 'ap',
	),
	array(
		1 => 23432,
        2 => NULL,
	)
))->route($request);

var_dump($router->getCurrentRoute());
var_dump($request->getParam(1));
var_dump($request->getActionName());
var_dump($request->getControllerName());
var_dump($request->getParam('name'));

?>
--EXPECTF--
string(2) "ap"
NULL
string(2) "ap"
NULL
NULL
tests/083.phpt000064400000001676151730720500007127 0ustar00--TEST--
Check for ReturnResponse in cli
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=0
yaf.lowcase_path=0
yaf.use_namespace=0
--FILE--
<?php 
require "build.inc";
startup();

$config = array(
	"application" => array(
		"directory" => APPLICATION_PATH,
        "view" => array(
 	        "ext" => "html",
        ),
    ),
);

file_put_contents(APPLICATION_PATH . "/controllers/Index.php", <<<PHP
<?php
   class IndexController extends Yaf_Controller_Abstract {
         public function indexAction() {}
   }
PHP
);

file_put_contents(APPLICATION_PATH . "/views/index/index.html", "okey");

$app = new Yaf_Application($config);
$response = $app->getDispatcher()->returnResponse(true)->dispatch(new Yaf_Request_Simple("CLI", "Index","Index","index"));
var_dump($response->getBody());
?>
--CLEAN--
<?php
/* unlink foo2.phtml permission denied */
require "build.inc"; 
shutdown();
?>
--EXPECTF--
string(4) "okey"
tests/issue231.phpt000064400000002125151730720500010161 0ustar00--TEST--
ISSUE #231 (php-fpm worker core dump BUG)
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
variables_order=EPS
yaf.lowcase_path=0
yaf.throw_exception=0
yaf.catch_exception=1
yaf.use_namespace=0
--POST--
SCRIPT_FILENAME=issue231.php
--FILE--
<?php 
$request = new Yaf_Request_Http(dirname(__FILE__));
print_r($request);
$request = new Yaf_Request_Http(dirname(__FILE__), dirname(dirname(__FILE__)));
var_export($request);
?>
--EXPECTF--
Yaf_Request_Http Object
(
    [method] => POST
    [module] => 
    [controller] => 
    [action] => 
    [uri:protected] => %stests
    [base_uri:protected] => 
    [dispatched:protected] => 
    [routed:protected] => 
    [language:protected] => 
    [params:protected] => Array
        (
        )

)
%saf_Request_Http::__set_state(array(
   'method' => 'POST',
   'module' => NULL,
   'controller' => NULL,
   'action' => NULL,
   'uri:protected' => '%stests',
   'base_uri:protected' => '%s',
   'dispatched:protected' => false,
   'routed:protected' => false,
   'language:protected' => '',
   'params:protected' => 
  array (
  ),
))
tests/053.phpt000064400000003675151730720510007126 0ustar00--TEST--
Check for Custom view engine
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=0
yaf.lowcase_path=0
yaf.use_namespace=0
--FILE--
<?php 
require "build.inc";
startup();

$config = array(
	"application" => array(
		"directory" => APPLICATION_PATH,
	),
);

class SimpleView implements Yaf_View_Interface {
	protected $tpl_dir;
	protected $view;
	public function __construct() {
		$this->view = new Yaf_View_Simple(__DIR__);
	}
	public function assign($name, $value = NULL) {
		$this->view->assign($name,  $value . " custom view");
	}
	public function __set($name, $value = NULL) {
		return $this->assign($name, $value);
	}
	public function getScriptPath($request = NULL) {
		return $this->tpl_dir;
	}
	public function setScriptPath($path) {
		$this->view->setScriptPath($path);
		return true;
	}
	public function render($script, $value = NULL) {
		return $this->view->render($script, $value);
	}
	public function display($script, $value = NULL) {
		return 	$this->view->display($script, $value);
	}
}

$tpl_dir = APPLICATION_PATH . "/views";
file_put_contents(APPLICATION_PATH . "/Bootstrap.php", <<<PHP
<?php
   class Bootstrap extends Yaf_Bootstrap_Abstract {
        public function _initView(Yaf_Dispatcher \$dispatcher) {
            \$dispatcher->setView(new SimpleView('{$tpl_dir}'));
        }
   }
PHP
);

file_put_contents(APPLICATION_PATH . "/controllers/Index.php", <<<PHP
<?php
   class IndexController extends Yaf_Controller_Abstract {
         public function indexAction() {
            \$this->_view->assign("name", "name");
            \$this->_view->val = "val";
         }
   }
PHP
);

file_put_contents($tpl_dir . "/index/index.phtml", <<<HTML
<?=\$name?>

<?=\$val?>
HTML
);

$app = new Yaf_Application($config);
$response = $app->bootstrap()->run();
echo $response;
?>
--CLEAN--
<?php
/* unlink foo2.phtml permission denied */
require "build.inc"; 
shutdown();
?>
--EXPECTF--
name custom view
val custom view
tests/078.phpt000064400000002117151730720510007123 0ustar00--TEST--
Check for Yaf_Route_Map::assemble
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php

$router = new Yaf_Router();

$route  = new Yaf_Route_Map();

$router->addRoute("map", $route);

var_dump($router->getRoute('map')->assemble(
                        array(
                                ':c' => 'foo_bar'
                        ),
                        array(
                                'tkey1' => 'tval1',
                                'tkey2' => 'tval2'
                        )
                   )
);

$route = new Yaf_Route_Map(true, '_');
$router->addRoute("map", $route);

var_dump($router->getRoute('map')->assemble(
                        array(
                                ':a' => 'foo_bar'
                        ),
                        array(
                                'tkey1' => 'tval1',
                                'tkey2' => 'tval2'
                        )
                   )
);

--EXPECTF--
string(%d) "/foo/bar?tkey1=tval1&tkey2=tval2"
string(%d) "/foo/bar/_/tkey1/tval1/tkey2/tval2"
tests/issue303.phpt000064400000001640151730720510010163 0ustar00--TEST--
ISSUE #303 (local variable is overrided by view renderring)
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=0
yaf.lowcase_path=0
yaf.use_namespace=0
--FILE--
<?php
require "build.inc";
startup();

$config = array(
	"application" => array(
		"directory" => APPLICATION_PATH,
	),
);

file_put_contents(APPLICATION_PATH . "/controllers/Index.php", <<<PHP
<?php
   class IndexController extends Yaf_Controller_Abstract {
         public function indexAction() {
            \$local = true;
            \$this->display("index", array());;
            var_dump(\$local);
			return false;
         }
   }
PHP
);

file_put_contents(APPLICATION_PATH . "/views/index/index.phtml", "<?php \$local = false; ?>");

$app = new Yaf_Application($config);
$app->run();

?>
--CLEAN--
<?php
/* unlink foo2.phtml permission denied */
require "build.inc"; 
shutdown();
?>
--EXPECTF--
bool(true)
tests/096.phpt000064400000002745151730720510007132 0ustar00--TEST--
Check for Custom route
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php
$router = new Yaf_Router();

$switch = true;
class myRoute implements Yaf_Route_Interface {
	public function route($request) {
		global $switch;
		if ($switch) {
			$request->setModuleName("moDule");
			$request->setControllerName("index");
			$request->action = "ActioN";
		}
		return $switch;
	}

	public function assemble($info, $verify = NULL) {
	}
}

$router->addRoute("custom", new myRoute);

$request = new Yaf_Request_Http("/foo/dummy");
$router->route($request);
print_r($request);
var_dump($router->getCurrentRoute());

$switch = false;
$request = new Yaf_Request_Http("/foo/dummy");
$router->route($request);
print_r($request);
var_dump($router->getCurrentRoute());
?>
--EXPECT--
Yaf_Request_Http Object
(
    [method] => CLI
    [module] => Module
    [controller] => Index
    [action] => action
    [uri:protected] => /foo/dummy
    [base_uri:protected] => 
    [dispatched:protected] => 
    [routed:protected] => 1
    [language:protected] => 
    [params:protected] => Array
        (
        )

)
string(6) "custom"
Yaf_Request_Http Object
(
    [method] => CLI
    [module] => 
    [controller] => Foo
    [action] => dummy
    [uri:protected] => /foo/dummy
    [base_uri:protected] => 
    [dispatched:protected] => 
    [routed:protected] => 1
    [language:protected] => 
    [params:protected] => Array
        (
        )

)
string(8) "_default"
tests/045.phpt000064400000002443151730720510007117 0ustar00--TEST--
Check for segfault while use closure as error handler
--SKIPIF--
<?php
if (!extension_loaded("yaf")) print "skip";
if (!version_compare(PHP_VERSION, "5.3", "ge")) print "skip only for 5.3+";
?>
--INI--
yaf.use_namespace=0
--FILE--
<?php 
$config = array(
	"application" => array(
		"directory" => realpath(dirname(__FILE__)),
		"dispatcher" => array(
			"catchException" => 0,
			"throwException" => 0,
		),
	),
);

class Bootstrap extends Yaf_Bootstrap_Abstract {
    public function _initErrorHandler(Yaf_Dispatcher $dispatcher) {
		var_dump($dispatcher->getDefaultModule());
		var_dump($dispatcher->getDefaultController());
		$dispatcher->setDefaultAction("dummy");
		var_dump($dispatcher->getDefaultAction());
        $dispatcher->setErrorHandler(function($errorCode, $errorMessage, $file, $line) {
            throw new ErrorException($errorMessage, 0, $errorCode, $file, $line);
        });
    }
}

class IndexController extends Yaf_Controller_Abstract {
    public function dummyAction() {
        echo  $undefined_var;
        return FALSE;
    }
}

$app = new Yaf_Application($config);
try {
    $app->bootstrap()->run();
} catch (Exception $e) {
    var_dump($e->getMessage());
}
?>
--EXPECTF--
string(5) "Index"
string(5) "Index"
string(5) "dummy"
string(33) "Undefined variable%sundefined_var"tests/017.phpt000064400000001130151730720510007106 0ustar00--TEST--
Bug (mem leak and crash in Yaf_Config_Ini)
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip";
if (version_compare(PHP_VERSION, '7.1.0') <= 0) {
   print "skip PHP 7.0 strict_types __construct() output warning";
}
?>
--INI--
yaf.use_namespace=0
--FILE--
<?php
declare(strict_types=1);
$config = new Yaf_Config_Ini;

var_dump($config->get("\0"));
?>
--EXPECTF--
Fatal error: Uncaught ArgumentCountError: Yaf_Config_Ini::__construct() expects at least 1%s, 0 given in %s017.php:%d
Stack trace:
#0 %s017.php(%d): Yaf_Config_Ini->__construct()
#1 {main}
  thrown in %s017.php on line %dtests/issue415.phpt000064400000002331151730720510010165 0ustar00--TEST--
Issue #415 ($actions changed to be reference)
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=1
yaf.lowcase_path=0
yaf.throw_exception=0
yaf.catch_exception=1
yaf.use_namespace=0
--FILE--
<?php 
require "build.inc";
startup();

$config = array(
	"application" => array(
		"directory" => APPLICATION_PATH,
	),
);

file_put_contents(APPLICATION_PATH . "/controllers/Index.php", <<<PHP
<?php
   class IndexController extends Yaf_Controller_Abstract {
		public \$actions = [
			'index' => 'need init',
		];

		public function init() {
			// foreach (\$this->actions as \$action => \$path) {
			// 	\$this->actions[\$action] = 'actions/IndexAction.php';
			// }
			array_walk(\$this->actions, function(\$path, \$action) {
				\$this->actions[\$action] = 'actions/IndexAction.php';
			});
		}
   }
PHP
);

@mkdir(APPLICATION_PATH . "/actions/");
file_put_contents(APPLICATION_PATH . "/actions/IndexAction.php", <<<PHP
<?php
   class IndexAction extends Yaf_Action_Abstract {
			public function execute() {
				echo "Okey";
				return FALSE;
			}
   }
PHP
);

$app = new Yaf_Application($config);
$response = $app->run();
?>
--CLEAN--
<?php
require "build.inc"; 
shutdown();
?>
--EXPECT--
Okey
tests/028.phpt000064400000001112151730720510007110 0ustar00--TEST--
Bug segfault while call exit in a view template
--SKIPIF--
<?php if (!extension_loaded("yaf")|| phpversion() >='8.0.0' ) print "skip"; ?>
--INI--
yaf.library="/php/global/dir"
yaf.use_namespace=0
--FILE--
<?php
require "build.inc";
startup();

$view = new Yaf_View_Simple(dirname(__FILE__));

$view->assign("name", "laruence");
$tpl  =  APPLICATION_PATH . '/tpls/foo.phtml';

file_put_contents($tpl, <<<HTML
okey
<?php exit; ?>
HTML
);
echo $view->render($tpl);
?>
--CLEAN--
<?php
/* unlink foo2.phtml permission denied */
require "build.inc"; 
shutdown();
?>
--EXPECTF--
okey
tests/issue297.phpt000064400000001720151730720510010176 0ustar00--TEST--
ISSUE #297 (Yaf_Loader fail to load namespace class name)
--SKIPIF--
<?php
if (!extension_loaded("yaf")) die("skip");
if (substr(PHP_OS, 0, 3) == "WIN") die("skip Linux only");
?>
--INI--
yaf.lowcase_path=0
yaf.throw_exception=0
yaf.catch_exception=1
yaf.use_namespace=1
yaf.use_spl_autoload=0
--FILE--
<?php 
$loader = Yaf\Loader::getInstance(__DIR__, __DIR__);
var_dump($loader->autoload("Test\Test"));
var_dump(new \Test\Test\Test\Test\Test\Test\T\Test\Test); //for __SSE2__
?>
--EXPECTF--
Warning: Yaf\Loader::autoload(): Failed opening script %s%cTest/Test.php: No such file or directory in %sissue297.php on line %d
bool(true)

Warning: Yaf\Loader::autoload(): Failed opening script %s/Test/Test/Test/Test/Test/Test/T/Test/Test.php: No such file or directory in %sissue297.php on line %d

Fatal error: Uncaught Error: Class %cTest\Test\Test\Test\Test\Test\T\Test\Test%c not found in %sissue297.php:%d
Stack trace:
#0 {main}
  thrown in %sissue297.php on line %dtests/issue535.phpt000064400000002731151730720510010174 0ustar00--TEST--
ISSUE #535 (Segsev while throw exception in action)
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=1
yaf.lowcase_path=0
yaf.use_namespace=0
--FILE--
<?php 
require "build.inc";
startup();

$config = array(
	"application" => array(
		"directory" => APPLICATION_PATH,
	),
);

file_put_contents(APPLICATION_PATH . "/controllers/Index.php", <<<PHP
<?php
   class IndexController extends Yaf_Controller_Abstract {
		public \$actions = array(
				"test_seprate" => "actions/test/seprate.php",
			);
   }
PHP
);

@mkdir(APPLICATION_PATH . "/actions/test/");
file_put_contents(APPLICATION_PATH . "/actions/test/seprate.php", <<<PHP
<?php
   class Test_SeprateAction extends Yaf_Action_Abstract {
         public function execute() {
			\$x  = new XX();
			\$yy  = new YY();
			echo "okey";
			return false;
         }
   }
PHP
);

file_put_contents(APPLICATION_PATH . "/library/XX.php", <<<PHP
<?php
	class XX extends ZZ {
		public static function test() {
        }
    }
PHP
);

file_put_contents(APPLICATION_PATH . "/library/YY.php", <<<PHP
<?php
	class YY extends ZZ {
		public static function test() {
        }
    }
PHP
);

file_put_contents(APPLICATION_PATH . "/library/ZZ.php", <<<PHP
<?php
	class ZZ { }
PHP
);

$app = new Yaf_Application($config);
$request = new Yaf_Request_Simple("GET", "Index", "Index", "test_seprate");
$app->getDispatcher()->dispatch($request);
?>
--CLEAN--
<?php
require "build.inc"; 
shutdown();
?>
--EXPECT--
okey
tests/issue311.phpt000064400000001022151730720510010154 0ustar00--TEST--
ISSUE #311 (Yaf_application::environ should respect $environ)
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=0
yaf.lowcase_path=0
yaf.use_namespace=0
yaf.environ=product
--FILE--
<?php
$config = array(
    "application" => array(
        "directory" => dirname(__DIR__),
    ),
);
$app = new Yaf_Application($config,'dev');//使用dev环境
echo ini_get('yaf.environ'),' ',$app->environ();//显示系统配置的yaf环境和当前应用的yaf环境
?>
--EXPECT--
product dev
tests/043.phpt000064400000002041151730720510007107 0ustar00--TEST--
Check for yaf.system settings
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.library="/tmp"
yaf.use_spl_autoload=1
yaf.name_suffix=1
yaf.name_separator=""
yaf.lowcase_path=1
yaf.environ="product"
yaf.use_namespace=0
--FILE--
<?php
define("APPLICATION_PATH", dirname(__FILE__));

$app = new Yaf_Application(APPLICATION_PATH . '/system.ini');
var_dump(ini_get("yaf.library") == APPLICATION_PATH);
var_dump(ini_get("yaf.open_basedir") == "");
var_dump(ini_get("yaf.use_spl_autoload") == "0");
//yaf.cache_config is INI_SYSTEM, can not be overridden
var_dump(ini_get("yaf.cache_config") == "0");
var_dump(ini_get("yaf.name_suffix") == "1");
var_dump(ini_get("yaf.name_separator") == "__");

new Plugin__ABC_EFG();
?>
--EXPECTF--
bool(true)
bool(true)
bool(true)
bool(true)
bool(false)
bool(true)

Warning: Yaf_Loader::autoload(): Failed opening script %sapplcation%cplugins%cABC%cEFG.php: No such file or directory in %s043.php on line %d

Fatal error: Uncaught Error: Class %cPlugin__ABC_EFG%c not found in %s043.php:%d
%atests/057.phpt000064400000001121151730720510007112 0ustar00--TEST--
check for Yaf_Dispatcher::catchException
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=0
yaf.lowcase_path=0
yaf.environ="product"
yaf.use_namespace=0
--FILE--
<?php
define("APPLICATION_PATH", dirname(__FILE__));
$app = new Yaf_Application(APPLICATION_PATH . '/simple.ini');
Yaf_Dispatcher::getInstance()->catchException(true);
var_dump(Yaf_Dispatcher::getInstance()->catchException());
Yaf_Dispatcher::getInstance()->catchException(false);
var_dump(Yaf_Dispatcher::getInstance()->catchException());
?>
--EXPECTF--
bool(true)
bool(false)
tests/issue518.phpt000064400000000704151730720510010173 0ustar00--TEST--
Check for Yaf_Response_HTTP::setRedirect in CGI
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--GET--
foo=bar
--FILE--
<?php
$response = new Yaf_Response_HTTP(); 
$response->setHeader("custom", "foobar");
$response->response();
var_dump($response->setRedirect('https://yourdomain.com'));
?>
--EXPECTHEADERS--
Status: 302 Found
Location: https://yourdomain.com
custom: foobar
--EXPECT--
bool(true)
tests/047.phpt000064400000001522151730720510007116 0ustar00--TEST--
Check for Yaf_Loader with spl_autoload
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=0
yaf.lowcase_path=0
yaf.use_namespace=0
--FILE--
<?php 
$config = array(
	"application" => array(
		"directory" => realpath(dirname(__FILE__)),
        "library" => array(
            "directory" => "./Notexists",
            "namespace" => "Foo",
        ),
	),
);

function pre_load($name) {
    var_dump($name);
}

function load($name) {
    eval("class " . $name . " {} ");
    return TRUE;
}

spl_autoload_register("pre_load");

$app = new Yaf_Application($config);

spl_autoload_register("load");

$a = new Foo();

print_r($a);
?>
--EXPECTF--
string(3) "Foo"

Warning: Yaf_Loader::autoload(): Failed opening script %sNotexists%cFoo.php: No such file or directory in %s047.php on line %d
Foo Object
(
)
tests/bug63900.phpt000064400000002045151730720510007764 0ustar00--TEST--
Bug #63900 (Segfault if separated action executes failed)
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=1
yaf.lowcase_path=0
yaf.throw_exception=0
yaf.catch_exception=1
yaf.use_namespace=0
--FILE--
<?php 
require "build.inc";
startup();

$config = array(
	"application" => array(
		"directory" => APPLICATION_PATH,
	),
);

file_put_contents(APPLICATION_PATH . "/controllers/Index.php", <<<PHP
<?php
   class IndexController extends Yaf_Controller_Abstract {
       public \$actions = array(
          "index" => "controllers/IndexAction.php",
       );
   }
PHP
);

file_put_contents(APPLICATION_PATH . "/controllers/IndexAction.php", <<<PHP
<?php
   class IndexAction extends Yaf_Action_Abstract {
       public function execute() {
            return FALSE;
       }
   }
PHP
);

file_put_contents(APPLICATION_PATH . "/views/index/index.phtml", "Okey");

$app = new Yaf_Application($config);
$response = $app->run();
echo "Okey";
?>
--CLEAN--
<?php
require "build.inc"; 
shutdown();
?>
--EXPECTF--
Okey
tests/025.phpt000064400000002032151730720520007110 0ustar00--TEST--
Check for Yaf_Loader with namespace configuration
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.library="/php/global/dir"
yaf.use_namespace=0
yaf.use_spl_autoload=0
yaf.lowercase_path=0
--FILE--
<?php 
$config = array(
	"application" => array(
		"directory" => realpath(dirname(__FILE__)),
        "library" => array(
            "directory" => "/tmp",
            "namespace" => "Foo, Bar",
        ),
	),
);

$app = new Yaf_Application($config);
Yaf_Loader::getInstance()->registerLocalNamespace("Dummy");
print_r(Yaf_Loader::getInstance());
var_dump(Yaf_Loader::getInstance()->isLocalName("Bar_Name"));

?>
--EXPECTF--
Yaf_Loader Object
(
    [library:protected] => /tmp
    [global_library:protected] => /php/global/dir
    [namespace:protected] => Array
        (
            [0] => Foo
            [1] => Bar
            [2] => Dummy
        )

    [use_spl_autoload:protected] => 
    [lowercase_path:protected] => 
    [is_name_suffix:protected] => 1
    [has_name_seperator:protected] => 
)
bool(true)
tests/009.phpt000064400000001362151730720520007117 0ustar00--TEST--
Check for Yaf_View_Simple basic usages
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php
$view = new Yaf_View_Simple(dirname(__FILE__));
$value = "laruence";
$view->assign("name", $value);
unset($value);
print_r($view);
var_dump(strlen($view->render(dirname(__FILE__) . "/001.phpt")));
var_dump($view->name);
var_dump($view->noexists);
print_r($view);
?>
--EXPECTF--
Yaf_View_Simple Object
(
    [tpl_dir:protected] => %s
    [tpl_vars:protected] => Array
        (
            [name] => laruence
        )

)
int(116)
string(8) "laruence"
NULL
Yaf_View_Simple Object
(
    [tpl_dir:protected] => %s
    [tpl_vars:protected] => Array
        (
            [name] => laruence
        )

)
tests/042.phpt000064400000001544151730720520007116 0ustar00--TEST--
Check for throw exception in Yaf_Controller::init
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php 
$config = array(
	"application" => array(
		"directory" => realpath(dirname(__FILE__)),
		"dispatcher" => array(
			"catchException" => 0,
			"throwException" => 1,
		),
        "modules" => "module",
	),
);

class ControllerController extends Yaf_Controller_Abstract {
    public function init() {
        throw new Yaf_Exception("exception");
    }

    public function indexAction() {
        echo "okey";
        return FALSE;
    }
}


$app = new Yaf_Application($config);
$request = new Yaf_Request_Http("/module/controller/index");

try {
  $app->getDispatcher()->returnResponse(false)->dispatch($request);
} catch (Yaf_Exception $e) {
  echo $e->getMessage(), "\n";
}
?>
--EXPECTF--
exception
tests/014.phpt000064400000003771151730720520007121 0ustar00--TEST--
Check for Yaf_Application
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.environ="product"
yaf.use_namespace=0
--FILE--
<?php 
define("APPLICATION_PATH", dirname(__FILE__));
$app = new Yaf_Application(
	dirname(__FILE__) . "/simple.ini",
	'product');
print_r($app);
?>
--EXPECTF--
Yaf_Application Object
(
    [directory] => %stests%capplcation
    [library] => 
    [bootstrap] => 
    [ext] => php
    [view_ext] => phtml
    [environ:protected] => product
    [running:protected] => 
    [err_msg:protected] => 
    [err_no:protected] => 0
    [config:protected] => Yaf_Config_Ini Object
        (
%A
        )

    [dispatcher:protected] => Yaf_Dispatcher Object
        (
            [auto_render:protected] => 1
            [instant_flush:protected] => 
            [return_response:protected] => 
            [request:protected] => Yaf_Request_Http Object
                (
                    [method] => CLI
                    [module] => 
                    [controller] => 
                    [action] => 
                    [uri:protected] => 
                    [base_uri:protected] => 
                    [dispatched:protected] => 
                    [routed:protected] => 
                    [language:protected] => 
                    [params:protected] => Array
                        (
                        )

                )

            [response:protected] => 
            [router:protected] => Yaf_Router Object
                (
                    [routes:protected] => Array
                        (
                            [_default] => Yaf_Route_Static Object
                                (
                                )

                        )

                    [current:protected] => 
                )

            [view:protected] => 
            [plugins:protected] => Array
                (
                )

        )

    [modules:protected] => Array
        (
            [0] => Index
        )

    [default_route:protected] => 
)
tests/issue468.phpt000064400000002242151730720520010177 0ustar00--TEST--
ISSUE #468 Check for same name variables assignment
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=0
yaf.use_namespace=0

--FILE--
<?php
require "build.inc";
startup();

$config = array(
	"application" => array(
		"directory" => APPLICATION_PATH,
        "dispatcher" => array (
           "catchException" => true,
        ),
	),
);


file_put_contents(APPLICATION_PATH . "/controllers/Index.php", <<<PHP
<?php
   class IndexController extends Yaf_Controller_Abstract {
         protected function init() {
            \$this->getView()->assign("ref", "first-source");
		 }

         public function indexAction() {
            \$this->getView()->assign("ref", "second-source");
            \$this->getView()->display("index/index.phtml", ["ref" => "thrid-source"]);
			var_dump(\$this->getViewpath());
            return false;
         }
   }
PHP
);

file_put_contents(APPLICATION_PATH . "/views/index/index.phtml", "<?php
   var_dump(\$ref);
?>");

$app = new Yaf_Application($config);
$app->run();

?>
--CLEAN--
<?php
require "build.inc";
shutdown();
?>
--EXPECTF--
string(12) "thrid-source"
string(%d) "%sapplication%cviews"
tests/046.phpt000064400000001403151730720520007114 0ustar00--TEST--
Check for Yaf_Loader with single class
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=0
yaf.lowcase_path=0
yaf.use_namespace=0
--FILE--
<?php 
$config = array(
	"application" => array(
		"directory" => realpath(dirname(__FILE__)),
        "library" => array(
            "directory" => "/tmp",
            "namespace" => "Foo",
        ),
	),
);
$app = new Yaf_Application($config);
$loader = Yaf_Loader::getInstance();
var_dump($loader->isLocalName("Foo_Bar"));
var_dump($loader->isLocalName("Foo"));
$loader->clearLocalNamespace();
$loader->registerLocalNamespace("Bar");
var_dump($loader->isLocalName("Foo_Bar"));
var_dump($loader->isLocalName("Bar"));
?>
--EXPECTF--
bool(true)
bool(true)
bool(false)
bool(true)
tests/system.ini000064400000001133151730720520007733 0ustar00[base]
application.directory=APPLICATION_PATH "/applcation"
application.system.lowcase_path=0
application.system.name_suffix=0
application.system.name_separator="__"
[product : base]
;only yaf runtime configure can be set
application.system.open_basedir=APPLICATION_PATH
application.system.use_spl_autoload=0
application.system.open_basedir=APPLICATION_PATH
application.system.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa=0
application.system.library=APPLICATION_PATH
application.system.cache_config=Off
tests/002.phpt000064400000004724151730720520007115 0ustar00--TEST--
Check for Yaf_Request_Simple
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_namespace=0
--FILE--
<?php
declare(strict_types=1);
$request  = new Yaf_Request_Simple("CLI", "index", "dummy", NULL, array("foo" => "bar"));
print_r($request);
var_dump((bool)$request->setParam("name", "Laruence"));
$request->setParam(["age" => 28, "gender" => "man"]);
var_dump($request->isCli());
var_dump($request->isXmlHttpRequest());
var_dump($request->isPost());
var_dump($request->getParam("name"));
var_dump($request->getParam("notexists"));

$app =  new Yaf_Application(array("application" => array(
            "directory" => dirname(__FILE__),
            )));

try {
    $app->getDispatcher()->dispatch($request);
} catch (Yaf_Exception_LoadFailed_Controller $e) {
    var_dump($e->getMessage());
}

var_dump($request->get("xxx"));
var_dump($request->getQuery("xxx"));
var_dump($request->getServer("xxx"));
var_dump($request->getPost("xxx"));
var_dump($request->getCookie("xxx"));
var_dump($request->getEnv("xxx"));
echo "------default value-------\n";
var_dump($request->get("xxx", "123"));
print_r($request->getQuery("xxx", new stdClass()));
print_r($request->getServer("xxx", array()));
var_dump($request->getPost("xxx", NULL));
var_dump($request->getCookie("xxx", false));
var_dump($request->getEnv("xxx", "2.13232"));
echo "------params-------\n";
var_dump($request->getParams());
var_dump($request->setParam("xxxx"));
var_dump($request->getParam("xxxx"));

?>
--EXPECTF--
Yaf_Request_Simple Object
(
    [method] => CLI
    [module] => Index
    [controller] => Dummy
    [action] => index
    [uri:protected] => 
    [base_uri:protected] => 
    [dispatched:protected] => 
    [routed:protected] => 1
    [language:protected] => 
    [params:protected] => Array
        (
            [foo] => bar
        )

)
bool(true)
bool(true)
bool(false)
bool(false)
string(8) "Laruence"
NULL
string(%d) "Failed opening controller script %sDummy.php: No such file or directory"
NULL
NULL
NULL
NULL
NULL
NULL
------default value-------
string(3) "123"
stdClass Object
(
)
Array
(
)
NULL
bool(false)
string(7) "2.13232"
------params-------
array(4) {
  ["foo"]=>
  string(3) "bar"
  ["name"]=>
  string(8) "Laruence"
  ["age"]=>
  int(28)
  ["gender"]=>
  string(3) "man"
}

Fatal error: Uncaught TypeError: Yaf_Request_Abstract::setParam()%sarray, string given in %s002.php:%d
Stack trace:
#0 %s002.php(%d): Yaf_Request_Abstract->setParam('xxxx')
#1 {main}
  thrown in %s002.php on line %d
tests/016.phpt000064400000001573151730720520007121 0ustar00--TEST--
Check for Yaf_Session
--SKIPIF--
<?php if (!extension_loaded("session")) die("skip session required"); ?>
<?php if (!extension_loaded("yaf")) die("skip"); ?>
--INI--
yaf.use_namespace=0
session.save_handler=files
session.save_path=
--FILE--
<?php 
$session = Yaf_Session::getInstance();

$_SESSION["name"] = "Laruence";

$age = 28;
$session->age = $age;
unset($age);

unset($session);
$session2 = Yaf_Session::getInstance();
$session2["company"] = "Baidu";

var_dump(isset($session2->age));
var_dump($session2->has("name"));
var_dump(count($session2));
foreach ($session2 as $key => $value) {
	echo $key , "=>", $value, "\n";
}

unset($session2);
$session3 = Yaf_Session::getInstance();

$session3->del("name");
unset($session3["company"]);
unset($session3->age);

var_dump(count($session3));
?>
--EXPECTF--
bool(true)
bool(true)
int(3)
name=>Laruence
age=>28
company=>Baidu
int(0)