Skip to content

Commit

Permalink
remove workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
tombrain committed Nov 5, 2023
1 parent eda4c0a commit e18da2e
Show file tree
Hide file tree
Showing 12 changed files with 291 additions and 117 deletions.
24 changes: 0 additions & 24 deletions .github/workflows/php80.yml

This file was deleted.

23 changes: 0 additions & 23 deletions .github/workflows/php81.yml

This file was deleted.

23 changes: 0 additions & 23 deletions .github/workflows/php82.yml

This file was deleted.

33 changes: 4 additions & 29 deletions src/fields/class.DateField.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct(&$oForm, $sName, $sMask = null, $bRequired = null, $
$this->setInterval(!is_null($sInterval) ? $sInterval : FH_DATEFIELD_DEFAULT_DATE_INTERVAL);

// set if the field is required
$this->setRequired(!is_null($bRequired) ? $bRequired : FH_DATEFIELD_DEFAULT_REQUIRED);
$this->_bRequired = !is_null($bRequired) ? $bRequired : FH_DATEFIELD_DEFAULT_REQUIRED;

// d = selectfield day
// m = selectfield month
Expand Down Expand Up @@ -96,7 +96,7 @@ public function __construct(&$oForm, $sName, $sMask = null, $bRequired = null, $
$this->_oYear = new TextField($oForm, $sName . '_year');
$this->_oYear->setSize(4);
$this->_oYear->setMaxlength(4);
$this->_oYear->setValidator(_FH_DIGIT);
$this->_oYear->setValidator($this->_bRequired ? FH_DIGIT : _FH_DIGIT);
break;

// month selectfield
Expand Down Expand Up @@ -132,7 +132,7 @@ public function __construct(&$oForm, $sName, $sMask = null, $bRequired = null, $
$this->_oMonth = new TextField($oForm, $sName . '_month');
$this->_oMonth->setSize(2);
$this->_oMonth->setMaxlength(2);
$this->_oMonth->setValidator(_FH_DIGIT);
$this->_oMonth->setValidator($this->_bRequired ? FH_DIGIT :_FH_DIGIT);
break;

// day selectfield
Expand All @@ -155,7 +155,7 @@ public function __construct(&$oForm, $sName, $sMask = null, $bRequired = null, $
$this->_oDay = new TextField($oForm, $sName . '_day');
$this->_oDay->setSize(2);
$this->_oDay->setMaxlength(2);
$this->_oDay->setValidator(_FH_DIGIT);
$this->_oDay->setValidator($this->_bRequired ? FH_DIGIT :_FH_DIGIT);
break;
}
}
Expand All @@ -164,31 +164,6 @@ public function __construct(&$oForm, $sName, $sMask = null, $bRequired = null, $
parent::__construct($oForm, $sName);
}

/**
* DateField::setRequired()
*
* Set if the datefield is required or if we have to give the user
* the option to select empty value
*
* @param boolean $bStatus: the status
* @return void
* @access public
* @author Teye Heimans
*/
public function setRequired($bStatus)
{
$this->_bRequired = $bStatus;

if (isset($this->_oYear) && is_object($this->_oYear))
$this->_oYear->setValidator($bStatus ? FH_DIGIT : _FH_DIGIT);

if (isset($this->_oMonth) && is_object($this->_oMonth))
$this->_oMonth->setValidator($bStatus ? FH_DIGIT : _FH_DIGIT);

if (isset($this->_oDay) && is_object($this->_oDay))
$this->_oDay->setValidator($bStatus ? FH_DIGIT : _FH_DIGIT);
}

/**
* DateField::setDisplay()
*
Expand Down
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
145 changes: 143 additions & 2 deletions tests/uts/formhandler_DateFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private function getYears($startYear, $endYear, $yearSelected = null): array
}


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

Expand Down Expand Up @@ -172,6 +172,44 @@ public function test_posted(): void
$this->assertEquals([2018, 4, 3], $form->getAsArray("datefield4"));
}

public function different_masks(): array
{
return [
[["d.m.y", "03.04.2018"]],
[["D.M.Y", "03.04.2018"]],
[["m.y", "04.2018"]],
[["M.Y", "04.2018"]],
[["d.y", "03.2018"]],
[["D.Y", "03.2018"]],
[["d.m", "03.04"]],
[["D.M", "03.04"]],
[["d", "03"]],
[["D", "03"]],
[["m", "04"]],
[["M", "04"]],
[["y", "2018"]],
[["Y", "2018"]]
];
}
/**
* @dataProvider different_masks
*/
public function test_getValue($different_masks): void
{
$_POST['FormHandler_submit'] = "1";
$_POST['datefield_day'] = "03";
$_POST['datefield_month'] = "04";
$_POST['datefield_year'] = "2018";

$form = new FormHandler();

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

$form->dateField("Datefield", "datefield", null, null, $different_masks[0]);

$this->assertEquals($different_masks[1], $form->getValue("datefield"));
}

public function test_new_mask1(): void
{
$form = new FormHandler();
Expand Down Expand Up @@ -251,7 +289,110 @@ public function test_posted_editfields_fillvalue_byinvalid(): void

$this->assertFormFlushContains($form, 'Datefield: <input type="text" name="datefield_day" id="datefield_day" value="03" size="2" maxlength="2" class="error" />' .
' - <input type="text" name="datefield_month" id="datefield_month" value="04" size="2" maxlength="2" class="error" />' .
' - <input type="text" name="datefield_year" id="datefield_year" value="2018" size="4" maxlength="4" class="error" /> error_datefield<span id="error_datefield" class="error">forcedError');
' - <input type="text" name="datefield_year" id="datefield_year" value="2018" size="4" maxlength="4" class="error" />' .
' error_datefield<span id="error_datefield" class="error">forcedError');
}

public function test_posted_editfields_invalidDate(): void
{
$_POST['FormHandler_submit'] = "1";
$_POST['datefield_day'] = "43";
$_POST['datefield_month'] = "04";
$_POST['datefield_year'] = "2018";

$form = new FormHandler();

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

$form->dateField("Datefield", "datefield", null, null, "D-M-Y");

$this->assertEquals("43-04-2018", $form->getValue("datefield"));

$this->assertFormFlushContains($form, 'Datefield: <input type="text" name="datefield_day" id="datefield_day" value="43" size="2" maxlength="2" class="error" />' .
' - <input type="text" name="datefield_month" id="datefield_month" value="04" size="2" maxlength="2" class="error" />' .
' - <input type="text" name="datefield_year" id="datefield_year" value="2018" size="4" maxlength="4" class="error" />' .
' error_datefield<span id="error_datefield" class="error">The given date is not valid!</span>'
);
}

public function test_posted_editfields_invalidDay(): void
{
$_POST['FormHandler_submit'] = "1";
$_POST['datefield_day'] = "A";
$_POST['datefield_month'] = "04";
$_POST['datefield_year'] = "2018";

$form = new FormHandler();

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

$form->dateField("Datefield", "datefield", null, null, "D-M-Y");

$this->assertFormFlushContains($form, 'Datefield: <input type="text" name="datefield_day" id="datefield_day" value="A" size="2" maxlength="2" class="error" />' .
' - <input type="text" name="datefield_month" id="datefield_month" value="04" size="2" maxlength="2" class="error" />' .
' - <input type="text" name="datefield_year" id="datefield_year" value="2018" size="4" maxlength="4" class="error" />' .
' error_datefield<span id="error_datefield" class="error"><span id="error_datefield_day" class="error">You did not enter a correct value for this field!</span></span>'
);
}

public function test_posted_editfields_invalidMonth(): void
{
$_POST['FormHandler_submit'] = "1";
$_POST['datefield_day'] = "01";
$_POST['datefield_month'] = "A";
$_POST['datefield_year'] = "2018";

$form = new FormHandler();

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

$form->dateField("Datefield", "datefield", null, null, "D-M-Y");

$this->assertFormFlushContains($form, 'Datefield: <input type="text" name="datefield_day" id="datefield_day" value="01" size="2" maxlength="2" class="error" />' .
' - <input type="text" name="datefield_month" id="datefield_month" value="A" size="2" maxlength="2" class="error" />' .
' - <input type="text" name="datefield_year" id="datefield_year" value="2018" size="4" maxlength="4" class="error" />' .
' error_datefield<span id="error_datefield" class="error"><span id="error_datefield_month" class="error">You did not enter a correct value for this field!</span>'
);
}

public function test_posted_editfields_invalidYear1(): void
{
$_POST['FormHandler_submit'] = "1";
$_POST['datefield_day'] = "01";
$_POST['datefield_month'] = "04";
$_POST['datefield_year'] = "A";

$form = new FormHandler();

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

$form->dateField("Datefield", "datefield", null, null, "D-M-Y");

$this->assertFormFlushContains($form, 'Datefield: <input type="text" name="datefield_day" id="datefield_day" value="01" size="2" maxlength="2" class="error" />' .
' - <input type="text" name="datefield_month" id="datefield_month" value="04" size="2" maxlength="2" class="error" />' .
' - <input type="text" name="datefield_year" id="datefield_year" value="A" size="4" maxlength="4" class="error" />' .
' error_datefield<span id="error_datefield" class="error"><span id="error_datefield_year" class="error">You did not enter a correct value for this field!</span></span>'
);
}

public function test_posted_editfields_invalidYear2(): void
{
$_POST['FormHandler_submit'] = "1";
$_POST['datefield_day'] = "01";
$_POST['datefield_month'] = "04";
$_POST['datefield_year'] = "123";

$form = new FormHandler();

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

$form->dateField("Datefield", "datefield", null, null, "D-M-Y");

$this->assertFormFlushContains($form, 'Datefield: <input type="text" name="datefield_day" id="datefield_day" value="01" size="2" maxlength="2" class="error" />' .
' - <input type="text" name="datefield_month" id="datefield_month" value="04" size="2" maxlength="2" class="error" />' .
' - <input type="text" name="datefield_year" id="datefield_year" value="123" size="4" maxlength="4" class="error" />' .
' error_datefield<span id="error_datefield" class="error">The given date is not valid!</span>'
);
}

public function test_new_extra(): void
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);
}
};
Loading

0 comments on commit e18da2e

Please sign in to comment.