Skip to content

Commit

Permalink
Improve tests portability
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabrice Luraine committed Jul 2, 2010
1 parent 57d7632 commit ff8826c
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1,2 +1,3 @@
.DS_STORE
.tmproj
.tmproj
tests/config/config.php
93 changes: 92 additions & 1 deletion tests/all.php
Expand Up @@ -6,7 +6,98 @@

if(!defined('TESTS_DOC_ROOT'))
{
$doc_root = "http://localhost/limonade-php.net/code/tests/apps/";
# 1. CONFIG file is required
$config_file = dirname(__FILE__).'/config/config.php';
if(file_exists($config_file))
{
include $config_file;
$doc_root = $config['limonade_base_url']."tests/apps/";
}
else
{
echo <<<OUTPUT
ERROR: MISSING CONFIG FILE FOR TESTS
====================================
In order to run test, you must have a valid tests/config/config.php file.
Please copy tests/config/config.php.dist into tests/config/config.php and
set required values.
The \$config['limonade_base_url'] is required to run functional tests.
NOTE: the Limonade source code must be somewhere in your HTTP server public
folder in order to call testing limonade apps.
---
OUTPUT;
exit;
}

# 2. HTTP+CURL requirements
if(function_exists('curl_version'))
{
$url = $doc_root.'index.php';
$response = test_request($url, 'GET');
if($response)
{
$v = phpversion();
$curl_v = curl_version();
$cv = $curl_v['version'];
if($response == $v)
{

echo <<<OUTPUT
==== RUNNING LIMONADE TESTS [PHP $v — cURL $cv] =====
OUTPUT;
} else {
echo <<<OUTPUT
ERROR: Wrong response to HTTP request test
==========================================
Requesting $url
must return '$v' but returns this response:
$response
---
Your \$config['limonade_base_url'] might be wrong or maybe it's your HTTP
server configuration and/or php installation.
Please fix it in order to run tests.
---
OUTPUT;
exit;
}
}
else
{
exit;
}

}
else
{
echo <<<OUTPUT
ERROR: cURL Library is required
===============================
Please install PHP cURL library in order to run Limonade tests.
---
OUTPUT;
}


define('TESTS_DOC_ROOT', $doc_root);
}

Expand Down
1 change: 1 addition & 0 deletions tests/apps/index.php
@@ -0,0 +1 @@
<?php echo phpversion(); ?>
4 changes: 4 additions & 0 deletions tests/config/config.php.dist
@@ -0,0 +1,4 @@
<?php
$config = array();
$config['limonade_base_url'] = 'http://localhost/limonade/';
?>
11 changes: 5 additions & 6 deletions tests/output.php
Expand Up @@ -9,7 +9,6 @@ function before_each_test_in_output()
{
env(null);
option('encoding', 'utf-8');

}

function test_output_layout()
Expand Down Expand Up @@ -129,7 +128,7 @@ function before_render($content_or_func, $layout, $locals, $view_path)

function test_output_autorender()
{
$response = test_request(TESTS_DOC_ROOT.'02-outputs.php/autorender', 'GET');
$response = test_request(TESTS_DOC_ROOT.'02-outputs.php/autorender', 'GET');
assert_equal($response, 'AUTORENDERED OUTPUT for empty_controller');
}

Expand All @@ -144,12 +143,12 @@ function _test_output_html_my_layout($vars){ extract($vars);?>
<title>Page title</title>
</head>
<body>
<?=$content?>
<?php echo $content ?>
</body>
</html>
<?}
<?php }

function _test_output_html_hello_world($vars){ extract($vars);?>
<p>Hello World</p>
<?if(isset($lorem)):?><p><?=$lorem?></p><?endif;?>
<?}
<?php if(isset($lorem)):?><p><?=$lorem?></p><?php endif;?>
<?php }

0 comments on commit ff8826c

Please sign in to comment.