Skip to content

Commit

Permalink
Add tests for flash features
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabrice Luraine committed Oct 9, 2010
1 parent 17b0d64 commit 6f064c5
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1,3 +1,4 @@
.DS_STORE
.tmproj
tests/config/config.php
tests/config/config.php
**/cookiefile
84 changes: 84 additions & 0 deletions tests/apps/07-flash.php
@@ -0,0 +1,84 @@
<?php
require_once dirname(dirname(dirname(__FILE__))).'/lib/limonade.php';

function before()
{
layout('html_default_layout');
}

dispatch('/', 'index');
function index()
{
flash('notice', 'ON DISPLAY 2');
return html('<p>Hellooo!</p>');
}

dispatch('/two', 'index_two');
function index_two()
{
flash('notice', 'ON DISPLAY 3');
return html('<p>Hellooo!</p>');
}
dispatch('/three', 'index_three');
function index_three()
{
flash('error', 'ON DISPLAY 4');
return html('<p>Hellooo!</p>');
}
dispatch('/four', 'index_four');
function index_four()
{
return html('<p>NO FLASH MESSAGE ON NEXT PAGE</p>');
}
dispatch('/five', 'index_five');
function index_five()
{
flash('error', 'ON DISPLAY 6');
redirect_to('six');
}
dispatch('/six', 'index_six');
function index_six()
{
return html('<p>REDIRECTED FROM INDEX FIVE...</p><p>There will be no flash message on next page.</p>');
}



run();

# _INLINE templates___________________________________________________________

function html_default_layout($vars){ extract($vars);?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Flash features test</title>
</head>
<body>
<article>
<?=$content;?>

<?php if(!empty($flash)): ?>
<section>
<h2>Current flash messages ( flash_now() / $flash )</h2>
<pre><code>
<?= var_dump(flash_now()); ?>
</code></pre>
</section>
<?php endif; ?>
</article>
<hr>
<nav>
<p><strong>Menu:</strong>
<a href="<?=url_for('/')?>">One</a> |
<a href="<?=url_for('two')?>">Two</a> |
<a href="<?=url_for('three')?>">Three</a> |
<a href="<?=url_for('four')?>">Four</a> |
<a href="<?=url_for('five')?>">Five</a> |
<a href="<?=url_for('six')?>">Six</a>
</p>
</nav>
</body>
</html>
<?};
47 changes: 47 additions & 0 deletions tests/functional.php
Expand Up @@ -136,4 +136,51 @@ function test_functional_errors()
assert_status($response, 501);
assert_match("/A personnal error #1234/", $response);
}

function test_functional_flash()
{
$path = TESTS_DOC_ROOT.'07-flash.php/';

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookiefile");
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookiefile");
curl_setopt($ch, CURLOPT_COOKIE, session_name() . '=' . session_id());
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

curl_setopt($ch, CURLOPT_URL, $path);
$response = curl_exec($ch);
assert_no_match("/ON DISPLAY/", $response);

curl_setopt($ch, CURLOPT_URL, $path.'two');
$response = curl_exec($ch);
assert_match("/ON DISPLAY 2/", $response);

curl_setopt($ch, CURLOPT_URL, $path.'three');
$response = curl_exec($ch);
assert_match("/ON DISPLAY 3/", $response);

curl_setopt($ch, CURLOPT_URL, $path.'four');
$response = curl_exec($ch);
assert_match("/ON DISPLAY 4/", $response);
assert_match("/NO FLASH MESSAGE ON NEXT PAGE/", $response);

curl_setopt($ch, CURLOPT_URL, $path.'five');
$response = curl_exec($ch);
assert_match("/REDIRECTED FROM INDEX FIVE/", $response);
assert_match("/ON DISPLAY 6/", $response);

curl_setopt($ch, CURLOPT_URL, $path.'six');
$response = curl_exec($ch);
assert_no_match("/ON DISPLAY/", $response);

curl_setopt($ch, CURLOPT_URL, $path.'two');
$response = curl_exec($ch);
assert_no_match("/ON DISPLAY/", $response);

curl_close($ch);
}
end_test_case();

0 comments on commit 6f064c5

Please sign in to comment.