Location: PHPKode > projects > Course-manager > courseman-0.1.1/check-javascript.php
<?php
  require('global-php.php');
  require('local-criteria.php');
  $gather = $_REQUEST['gather'];
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title><?=ucfirst($lang_javascript_test[$language])?></title>
<link rel="stylesheet"
      href="local.css"
      type="text/css">
<?=$local_stylesheets?>
<script type="text/javascript" src="global-javascript.php">
</script>
<script type="text/javascript">
<?php
  if ($gather) {
?>
  var successes = 0;
  var failures = 0;
<?php
  }
?>
  function positive(text) {
<?php
  if ($gather) {
?>
    successes++
    var input = document.createElement('input');
    input.name = 'success' + successes;
    input.value = text;
    return input;
<?php
  } else {
?>
    return document.createTextNode(text);
<?php
  }
?>
  }
  function negative(text) {
<?php
  if ($gather) {
?>
    failures++;
    var input = document.createElement('input');
    input.name = 'failure' + failures;
    input.value = text;
    return input;
<?php
  } else {
?>
    var output = document.createElement("span");
<?php
    if ($old_internet_explorer) {
?>
    output.style.color = "#FF0000";
<?php
    } else {
?>
    output.style.class = "hinweis";
<?php
    }
?>
    output.appendChild(document.createTextNode(text));
    return output;
<?php
  }
?>
  }
  function output(node) {
<?php
  if ($gather) {
?>
    var form = document.getElementById('results');
    form.appendChild(node);
<?php
  } else {
?>
    var paragraph = document.createElement("p");
    paragraph.appendChild(node);
    document.getElementById("test_output").appendChild(paragraph);
<?php
  }
?>
  }
  function submit_results() {
<?php
  if ($gather) {
?>
    var form = document.getElementById('results');
    var input = document.createElement('input');
    input.name = 'success';
    input.value = successes;
    form.appendChild(input);
    var input = document.createElement('input');
    input.name = 'failure';
    input.value = failures;
    form.appendChild(input);
    form.submit();
<?php
  }
?>
  }
  var add_hook_called = false;
  var remove_hook_called = false;
  function verify_add_hook(ignored) {
    add_hook_called = true;
  }
  function verify_remove_hook(ignored) {
    remove_hook_called = true;
  }
  window.onload = function() {
    var test_result;
    var test_set = new Set(new Array("a","b","c"));
<?php
  function state_containment($container,$contained,$containment) {
    global $language,$lang_contain;
    $stater = $containment ? ling_does : ling_does_not;
    return $stater($language,
                   $container[$language],
                   $contained[$language],
                   $lang_contain[$language]);
  }
  function javascript_check($checked,$attribute,$wanted,$indentation) {
    global $language,$lang_set,$lang_contain;
    return "if (test_set.contains('$checked')) {"
	. $indentation . "  test_result = "
				. ($wanted ? 'positive' : 'negative')
				. "('" . javascript_escape(
						state_containment($lang_set,
                                                           $attribute,
                                                           true))
				. "');"
	. $indentation . "} else {"
	. $indentation . "  test_result = "
				. ($wanted ? 'negative' : 'positive')
				. "('" . javascript_escape(
						state_containment($lang_set,
                                                           $attribute,
                                                           false))
				. "');"
	. $indentation . "}"
	. $indentation . "output(test_result);
";
  }
?>
    <?=javascript_check('b',$lang_expected_element,true,'
    ')?>
    <?=javascript_check('d',$lang_unexpected_element,false,'
    ')?>
    test_set.add_element("d");
    test_set.remove_element("b");
    <?=javascript_check('b',$lang_removed_element,false,'
    ')?>
    <?=javascript_check('d',$lang_inserted_element,true,'
    ')?>
    output(test_result);
    test_set = new Set();
    if (test_set.contains("b")) {
      test_result = negative("<?=state_containment($lang_empty_set,
                                                   $lang_element,
                                                   true)?>");
    } else {
      test_result = positive("<?=state_containment($lang_empty_set,
                                                   $lang_checked_element,
                                                   false)?>");
    }
    output(test_result);
    test_set = new Set(new Array("foo1","foo2","bar1","bar2"));
    test_set.remove_from(new Prefixed_Number_Set("bar"));
    <?=javascript_check('bar1',$lang_removed_element,false,'
    ')?>
    <?=javascript_check('foo1',$lang_remaining_element,true,'
    ')?>
    output(test_result);
    test_set.remove_hook = verify_remove_hook;
    test_set.add_hook = verify_add_hook;
    test_set.add_element("d");
    test_set.remove_from(new Prefixed_Number_Set("foo"));
    if (add_hook_called) {
      test_result = positive("<?=
                ling_done_simple($language,
                                 ling_hook($language,'add'),
                                 $lang_call[$language])?>");
    } else {
      test_result = negative("<?=
                ling_done_simple_not($language,
                                     ling_hook($language,'add'),
                                     $lang_call[$language])?>");
    }
    output(test_result);
    if (remove_hook_called) {
      test_result = positive("<?=
                ling_done_simple($language,
                                 ling_hook($language,'remove'),
                                 $lang_call[$language])?>");
    } else {
      test_result = negative("<?=
                ling_done_simple_not($language,
                                     ling_hook($language,'remove'),
                                     $lang_call[$language])?>");
    }
    output(test_result);
    submit_results();
  }
</script>
</head>
<body>
<?=conditional_layout_before_content(ucfirst(
			$lang_javascript_test[$language]))?>
<?php
  if ($gather) {
?>
<form id="results" action="gather-results.php" method="POST">
</form>
<?php
  } else {
?>
<p id="test_output">
</p>
<?php
  }
?>
<?=conditional_layout_after_content()?>
</body>
</html>
Return current item: Course-manager