Hi Guys and Girls
First, I should say what a pleasure it is to have a robust and tested data access layer as soon as my datamodel is ready. No need to test that!
I've been thinking about a unit testing framework for the qforms. The testing framework would simulate the page life cycles without doing actual http requests. Suppose I had a qform with code like
<?
class MyForm{
protected function Form_Create()
{
$this->btnTest = new QButton($this);
$this->btnTest->AddAction(new QClickEvent(),
new QServerAction('btnTest_Click');
$this->lblTest = new QLabel($this);
$this->txtTest = new QTextBox($this);
}
protected function btnTest_Click($formId,$controlId,$parameter)
{
$this->lblTest->Text=$this->txtTest->Text;
}
}
?>
What I would like to do is to unit test that my btnTest_Click function is doing its job. The unit test function would have to be in a class that inherits the form, because of the convention that form objects are protected.
<?
class MyFormTester extends MyForm{
protected function Test_btnTest_Click()
{
$this->txtTest->Text="Hello World!";
MyFormTester::ExecuteAction($this->btnTest,Action:Click);
assert($this->lblTest->Text=="Hello World!");
}
}
?>
The point about ExecuteAction is that it would trigger a simulation of the page life cycle, excluding serialisation and post variable parsing, but including things like validation and the triggering of all actions associated with QActionControls.
This triggering of all actions is important, because one could have added an action to the button which causes the test to fail. I can't just call btnTest_Click() in the test. Likewise, the cause of failure could be somewhere else in the lifecycle, for example in the Form_Exit() method.
I believe this would plug into just about any unit testing framework, so you can replace the assert statement with anything relevant to your framework of choice.