/**
  * Test savingForm
  * Test so a proper form is saved, with correct data.
  * Also test if it is possible to enter incorrect data that might ruin something.
  * @author Fredrik Andersson
  * @small
  * @test
  */
 public function formFunctions()
 {
     // Create new user class
     $a = new PP();
     // Check if the object was created
     $this->assertNotNull($a);
     // Adding some variables into the form class PP
     $a->student1 = "StudentName";
     $this->assertEquals("StudentName", $a->student1);
     //Test of the function test_num($data)
     $this->assertEquals(1, test_num(1));
     $this->assertEquals("-", test_num("-"));
     $this->assertEquals("-", test_num(10));
     //Test of the function test_input($data)
     $this->assertEquals("123", test_input("  123  "));
     //trim() removes spaces before the first char and after the last one.
     $this->assertEquals("123'hihi\ttab", test_input("123\\'hi\\hi\ttab"));
     //stripslashes() removes all slashes exept proper slashes like \t and \n etc.
     $this->assertEquals("&amp; &quot; &lt; &gt;", test_input("& \" < >"));
     //htmlspecialchars() changes some special characters to code that html can handle.
     //Test of the function is_empty($data)
     $this->assertEquals(false, is_empty(array('apple', 'banana ', ' cranberry ')));
     $this->assertEquals(false, is_empty(array('', '', '')));
     $temp[10] = "something";
     $this->assertEquals(false, is_empty($temp));
     //Test of the function input_length()
     $string128 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
     $string129 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab";
     $this->assertEquals($string128, input_length($string129));
     //Test of the function length_one()
     $this->assertEquals("1", length_one("12345"));
 }
Пример #2
0
test_hh_resource(STDIN);
test_hh_arraykey('herp');
test_hh_arraykey(123);
test_hh_num(123);
test_hh_num(1.23);
test_string(new string());
test_int(new int());
test_float(new float());
test_bool(new bool());
test_resource(new resource());
test_arraykey(new arraykey());
test_num(new num());
print "--- INCORRECT USAGE ---\n";
test_hh_string(new string());
test_hh_int(new int());
test_hh_float(new float());
test_hh_bool(new bool());
test_hh_resource(new resource());
test_hh_arraykey(new arraykey());
test_hh_arraykey(1.23);
test_hh_num(new num());
test_hh_num('123');
test_string('123');
test_int(123);
test_float(1.23);
test_bool(true);
test_resource(STDIN);
test_arraykey('herp');
test_arraykey(123);
test_num(1.23);
Пример #3
0
test_resource(STDIN);
test_arraykey('herp');
test_arraykey(123);
test_num(123);
test_num(1.23);
print "--- INCORRECT USAGE ---\n";
test_string(new string());
test_int(new int());
test_float(new float());
test_bool(new bool());
test_resource(new resource());
test_arraykey(new arraykey());
test_num(new num());
print "--- INCORRECT USAGE ---\n";
test_hh_string(new string());
test_hh_int(new int());
test_hh_float(new float());
test_hh_bool(new bool());
test_hh_resource(new resource());
test_hh_arraykey(new arraykey());
test_hh_arraykey(1.23);
test_hh_num(new num());
test_hh_num('123');
test_string(new string());
test_int(new int());
test_float(new float());
test_bool(new bool());
test_resource(new resource());
test_arraykey(new arraykey());
test_num(new num());
    $data->s1 = length_three(test_input(test_num($_POST["s1"])));
    $data->content1 = length_one(test_input(test_num($_POST["content1"])));
    $data->content2 = length_one(test_input(test_num($_POST["content2"])));
    $data->content3 = length_one(test_input(test_num($_POST["content3"])));
    $data->s2 = length_three(test_input(test_num($_POST["s2"])));
    $data->contribution1 = length_one(test_input(test_num($_POST["contribution1"])));
    $data->contribution2 = length_one(test_input(test_num($_POST["contribution2"])));
    $data->contribution3 = length_one(test_input(test_num($_POST["contribution3"])));
    $data->s3 = length_three(test_input(test_num($_POST["s3"])));
    $data->presentation1 = length_one(test_input(test_num($_POST["presentation1"])));
    $data->presentation2 = length_one(test_input(test_num($_POST["presentation2"])));
    $data->presentation3 = length_one(test_input(test_num($_POST["presentation3"])));
    $data->presentation4 = length_one(test_input(test_num($_POST["presentation4"])));
    $data->presentation5 = length_one(test_input(test_num($_POST["presentation5"])));
    $data->s4 = length_three(test_input(test_num($_POST["s4"])));
    $data->s5 = length_three(test_input(test_num($_POST["s5"])));
    $data->s6 = length_one(test_input(test_grade($_POST["s6"])));
    $data->impression = input_length(test_input($_POST["impression"]));
    $data->rname = input_length(test_input($_POST["rname"]));
    $data->date = length_date(test_input($_POST["date"]));
    $data->feedback = input_length(test_input($_POST["feedback"]));
    // Create the review
    $review = Review::createReview($data);
    // Add it to the submission
    $submission->addReview($review->id);
    echo '<h3>Success!</h3><a href="?"><button class="btn btn-success">Go back</button></a>';
} else {
    $data;
    $latestID = $submission->getLatestReview($user->id);
    // If user already has a review
    if ($latestID > -1) {
    $form->contentcomment3 = test_input($_POST["contentcomment3"]);
    $form->content4 = test_input(test_num($_POST["content4"]));
    $form->contentcomment4 = test_input($_POST["contentcomment4"]);
    $form->s2 = test_input(test_num($_POST["s2"]));
    $form->presentation1 = test_input(test_num($_POST["presentation1"]));
    $form->presentationcomment1 = test_input($_POST["presentationcomment1"]);
    $form->presentation2 = test_input(test_num($_POST["presentation2"]));
    $form->presentationcomment2 = test_input($_POST["presentationcomment2"]);
    $form->presentation3 = test_input(test_num($_POST["presentation3"]));
    $form->presentationcomment3 = test_input($_POST["presentationcomment3"]);
    $form->presentation4 = test_input(test_num($_POST["presentation4"]));
    $form->presentationcomment4 = test_input($_POST["presentationcomment4"]);
    $form->presentation5 = test_input(test_num($_POST["presentation5"]));
    $form->presentationcomment5 = test_input($_POST["presentationcomment5"]);
    $form->s3 = test_num(test_input(test_num($_POST["s3"])));
    $form->s4 = test_num(test_input(test_num($_POST["s4"])));
    $form->feedback = test_input($_POST["feedback"]);
    // Create the review
    $review = Review::createReview($form);
    // Add it to the submission
    $submission->addReview($review->id);
    echo '<h3>Success!</h3><a href="?"><button class="btn btn-success">Go back</button></a>';
} else {
    $data;
    if (isset($uid)) {
        $latestID = $submission->getLatestReview($uid);
    } else {
        $latestID = $submission->getLatestReview($user->id);
    }
    // If user already has a review
    if ($latestID > -1) {
Пример #6
0
var_dump($ln);
echo "p6:";
var_dump(25 / 7);
// float(3.5714285714286)
echo "p7:";
var_dump((int) (25 / 7));
// int(3)
//var_dump(round(25/7));  // float(4)
echo "p8:";
echo (int) ((0.1 + 0.7) * 10);
echo "\n";
// overflows on arithmetic
test_num('of1:', 1000000 * 1000000);
test_num('of1a:', 2147483647 * 2147483647);
test_num('of1b:', 2147483647 * 2147483660);
test_num('of1c:', -2147483647 * 2147483660);
test_num('of2:', 2147483647 + 2147483650);
test_num('of3:', 2147483647 + 2147483647);
test_num('of3a:', -2147483647 + -2147483647);
test_num('of4:', -200000000 - 200000000);
test_num('of5:', 1000000 / 1000);
// elongs
test_num('el1:', 32144 / 231);
test_num('el2:', 32144 + 231);
test_num('el3:', 32144 * 231);
test_num('el4:', 32144 - 231);
$c[] = +5;
$c[] = -12.0;
$c[] = 4.0;
$c[] = +12.5;
var_dump($c);