<?php
session_start();
require 'includes/phpautotest_config.php';
require 'includes/phpautotest_functions.php';
require 'includes/HttpClient.class.php';
require 'includes/header.php';
require 'includes/top_menu.php';
restrict_access();
if(isset($_GET['case_id']))
{
$case_id = $_GET['case_id'];
}
else
{
phpautotest_show_error('$_GET[\'case_id\'] is not set.');
}
// We start from zero since we have LIMIT 0, 1 to select first row
if(isset($_GET['page_no']))
{
$page_no = $_GET['page_no'];
}
else
{
$page_no = 0;
}
// Update database with edited php test code and html test. We check if html_test is set because php_test_code will not be set if the textarea is disabled.
if(isset($_POST['html_test']))
{
// No HTML entities should be stored in the database
$html_test = htmlentities($_POST['html_test']);
$QUERY = <<<END
UPDATE
`$phpautotest_table_page`
SET
php_test_code = '$_POST[php_test_code]',
html_test = '$html_test',
page_location = '$_POST[page_location]'
WHERE
`id` = $_POST[id]
END;
phpautotest_send_query($QUERY);
phpautotest_show_message($phpautotest_message['test_update_success']);
}
// Use case_id to select all pages for this case
$QUERY = <<<END
SELECT
*
FROM
`$phpautotest_table_page`
WHERE
`case_id` = $case_id
ORDER BY id ASC
LIMIT $page_no, 2
END;
$result = phpautotest_send_query($QUERY);
// Extract serialized_variable_dump for the current page we are editing
$page = mysql_fetch_assoc($result);
$serialized_variable_dump = $page['serialized_variable_dump'];
$php_test_code = $page['php_test_code'];
// Make sure that data was recorded before allowing a test case to be recorded
$variable_dump = unserialize($serialized_variable_dump);
if(!is_array($variable_dump))
{
$disable_code_edit = 'disabled';
$php_test_code = 'No variables were recorded. PHP test cannot be conducted for this page!';
}
else
{
$disable_code_edit = '';
}
// Show link to previous page if there is one
if($page_no > 0)
{
$prev_page_no = $page_no - 1;
echo "<center><b><a href = '$PHP_SELF?page_no=$prev_page_no&case_id=$case_id'>Previous page</a></b></center>";
}
// Show link to next page if there is one
$next_page = mysql_fetch_assoc($result);
if(isset($next_page['id']))
{
$next_page_no = $page_no + 1;
echo "<center> <b><a href = '$PHP_SELF?page_no=$next_page_no&case_id=$case_id'>Next page</a></b></center>";
}
// Make output a valid regular expression
$html_output = escape_for_regex($page['html_output']);
echo
"
<script type='text/javascript' src='./jsolait/init.js'></script>
<SCRIPT LANGUAGE='JavaScript'>
// Pastes downloaded html output into the test textarea
function paste_html_output()
{
document.edit_test.html_test.value = document.edit_test.html_output.value;
}
// Generates code based on template in php_test_code_template
function generate_code()
{
var php_test_code = document.edit_test.php_test_code;
var php_vars = document.edit_test.php_vars;
for(var i = 0; i < php_vars.options.length; i++)
{
if (php_vars.options[i].selected)
{
code = '$php_test_code_template'.format(php_vars.options[i].value, php_vars.options[i].value, php_vars.options[i].value, php_vars.options[i].value);
php_test_code.value += code;
}
}
}
</SCRIPT>
<form method = 'POST' action = '$PHP_SELF?page_no=$page_no&case_id=$case_id' name = 'edit_test'>
<table cellspacing='1' cellpadding='3' bgcolor='white' class = 'box'>
<tr bgcolor='#005896'>
<td colspan = '2'><font color='#FFFFFF'><b>Edit tests for $page[page_location]</b></font></td>
</tr>
<tr bgcolor = '#dddddd'>
<td valign = 'top'><b>Page location</b><br>Do not modify this value unless the page under test has moved!</td>
<td valign = 'top'><input type = 'textbox' name = 'page_location' value = '$page[page_location]'></td>
</tr>
<tr bgcolor = '#dddddd'>
<td valign = 'top'><b>PHP variable test</b><br><i>Select the variables you would like to compare and click <b>Generate code</b></i></td>
<td valign = 'top'>
";
// --------------
if(is_array($variable_dump))
{
echo "<b>Variables</b><br><select name = 'php_vars' size = 8 multiple>";
foreach($variable_dump as $key => $var)
{
echo "<option value='$key'>$key</option>";
}
echo "
</select>
<br>
<input type = 'button' value = 'Generate code' onClick = 'generate_code()' class = 'phpautotest_button'>
<p>
<b>Test code</b><br>
<textarea name = 'php_test_code' class = 'phpautotest_text' cols = 70' rows='10'>$php_test_code</textarea></td>
";
}
else
{
echo "PHP variables were not recorded";
}
// --------------
echo
"
</td>
</tr>
<tr bgcolor = '#dddddd'>
<td valign = 'top'><b>HTML test</b><br><i>This is text that you want phpautotest to look for on the page.<br>Do not forget to <b>add a \ before ^.[]$()|*+?{\</b>.</i></td>
<td>
<textarea name = 'html_test' class = 'phpautotest_text' cols='70' rows='10'>$page[html_test]</textarea>
<textarea name = 'html_output' class = 'phpautotest_text' cols='70' rows='10' style='display: none'>$html_output</textarea>
</td>
</tr>
<tr bgcolor = '#dddddd'>
<td colspan = '2' align = 'right'>
<input type = 'button' value = 'paste html output' onClick = 'paste_html_output()' class = 'phpautotest_button'>
<input type = 'submit' value = 'update' class = 'phpautotest_button'>
</td>
</tr>
</table>
<input type = 'hidden' name = 'id' value = '$page[id]'>
</form>
";
require 'includes/footer.php';
?>