Skip to content

Commit

Permalink
new testmethods
Browse files Browse the repository at this point in the history
  • Loading branch information
tombrain committed Nov 5, 2023
1 parent 950a52c commit 3df98e7
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 0 deletions.
48 changes: 48 additions & 0 deletions tests/uts/formhandler_ConstructorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,52 @@ public function testNoField(): void

$this->assertTriggertError('Try to get the value of an unknown field "notexist"!', E_USER_WARNING);
}

public function testNoName(): void
{
// three different versions
$form = new FormHandler();
$this->assertEquals(FH_DEFAULT_FORM_NAME, $form->getName());
$form2 = new FormHandler();
$this->assertEquals(FH_DEFAULT_FORM_NAME . "1", $form2->getName());
$form3 = new FormHandler();
$this->assertEquals(FH_DEFAULT_FORM_NAME . "2", $form3->getName());
}

public function testSetAction(): void
{
// three different versions
$form = new FormHandler(null, "action");

$a = $this->getPrivateProperty($form, "_action");
$this->assertEquals("action", $a);
}

public function testSetActionFromQueryString(): void
{
$_SERVER['PHP_SELF'] = "phpself.php";

// three different versions
$form = new FormHandler();

$a = $this->getPrivateProperty($form, "_action");
$this->assertEquals("phpself.php", $a);

$_SERVER['QUERY_STRING'] = "querystring";

// three different versions
$form2 = new FormHandler();

$a = $this->getPrivateProperty($form2, "_action");
$this->assertEquals("phpself.php?querystring", $a);
}

public function testSetExtra(): void
{
// three different versions
$form = new FormHandler(null, null, "extra");

$a = $this->getPrivateProperty($form, "_extra");
$this->assertEquals("extra", $a);
}
}
9 changes: 9 additions & 0 deletions tests/uts/formhandler_DataHandlingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ public function testGetAsArray(): void
$this->assertEquals("21", $day);
}

public function testGetAsArray_expectedError(): void
{
$form = new FormHandler();

$this->assertFalse($form->getAsArray('date'));

$this->assertTriggertError('The datefield "date" does not exists!', E_USER_NOTICE);
}

public function testGetValue(): void
{
$_POST['FormHandler_submit'] = "1";
Expand Down
8 changes: 8 additions & 0 deletions tests/uts/formhandler_RadiobuttonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,12 @@ public function test_validator(): void
$t['radiobutton']
);
}

public function test_expected_error_options_no_array(): void
{
$form = new FormHandler();

$form->radioButton("Radiobutton", "radiobutton", "noarray");
$this->assertTriggertError("You have to give an array as value with the radiobutton 'radiobutton'", E_USER_WARNING);
}
};
9 changes: 9 additions & 0 deletions tests/uts/formhandler_SelectFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,13 @@ public function test_new_extra(): void
'</select>error_selectfield'
]);
}

public function test_expected_error_options_no_array(): void
{
$form = new FormHandler();

$form->selectField("Selectfield", "selectfield", "noarray");

$this->assertTriggertError("You have to give an array as value with the selectfield 'selectfield'", E_USER_WARNING);
}
};
12 changes: 12 additions & 0 deletions tests/uts/formhandler_TimeFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,18 @@ public function test_new_format(): void
$this->assertFormFlushContains($form, $aExpected);
}

public function test_new_format_expected_formaterror(): void
{
define('FH_TIMEFIELD_SET_CUR_TIME', false);
$form = new FormHandler();

$this->assertFalse($form->isPosted());

$form->timeField("Timefield", "timefield", null, false, 13);

$this->assertTriggertError("Invalid value as hour format! Only 12 or 24 are allowed!", E_USER_WARNING);
}

/**
* @dataProvider timeintervall
*/
Expand Down
38 changes: 38 additions & 0 deletions tests/uts/formhandler_UploadFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -572,4 +572,42 @@ public function test_mergeImage(): void

$this->assertTrue(unlink("{$this->_tempPath}/uploadedandmerged.jpg"));
}

public function testIsUploaded_expectedError(): void
{
$form = new FormHandler();

$this->assertFalse($form->isUploaded('upload'));

$this->assertTriggertError('Error, the uploadfield "upload" does not exists!', E_USER_NOTICE);
}

public function testIsUploaded_expectedError2(): void
{
$form = new FormHandler();

$form->textField("Upload", "upload");

$this->assertFalse($form->isUploaded('upload'));

$this->assertTriggertError('Error, the field "upload" is not an uploadfield!', E_USER_NOTICE);
}

public function testGetFileInfo_expectedError(): void
{
$form = new FormHandler();

$this->assertCount(0, $form->getFileInfo('upload'));
$this->assertTriggertError('Error, the uploadfield "upload" does not exists!', E_USER_NOTICE);
}

public function testGetFileInfo_expectedError2(): void
{
$form = new FormHandler();

$form->textField("Upload", "upload");

$this->assertCount(0, $form->getFileInfo('upload'));
$this->assertTriggertError('Error, the field "upload" is not an uploadfield!', E_USER_NOTICE);
}
};

0 comments on commit 3df98e7

Please sign in to comment.