Forum Moderators: coopster

Message Too Old, No Replies

Test Form Submit

         

HoboTraveler

4:34 am on Oct 20, 2007 (gmt 0)

10+ Year Member



Hi All,

I am on the look out for a solution that would test forms.

The script should automatically populate form fields, trigger the submit button etc.

Is this possible? How would I go about creating a PHP script that does this?

TIA

dreamcatcher

5:24 pm on Oct 20, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Isn`t this a form of spam?

dc

PHP_Chimp

7:36 pm on Oct 20, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Maybe you should give us a clue about what you want to test on the forms?
Are you testing the fact that they work?
Testing your field validation?
Something else.

HoboTraveler

5:39 pm on Oct 22, 2007 (gmt 0)

10+ Year Member



Hello,

Yes, I want to test the following:

1) Validation: Make sure the validations work ok
2) DB Insert: Check whether data is entered correctly into the MySQL database.

I need to generate a log of the two processes above and check for issues every 48 hours.

I was thinking we could insert data into the database through a CRON job but that would bypass the forms all together and is not really a test.

I would then run a separate script that would delete the test data that was inserted in the db above.

Is there a solution?

TIA

PHP_Chimp

7:27 pm on Oct 22, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



1) Validation: Make sure the validations work ok

assuming that there is no random need to shift your validation pattens then if it works for the first 1,2-20 tests then it will continue to work for those pattens. If you want to test for new vulnerabilities that you have not yet thought of then there is no test that you can design that will help.

2) DB Insert: Check whether data is entered correctly into the MySQL database.
Again if data is entered correctly during your tests then, accept for people entering data that doesnt meet you validation, there should be no reason for the data not to be entered correctly. If you are testing for problems with the connection with the database then you could have a log written from the
if (!$connection) {
// write log
// maybe email me
}

If you are looking to log all transactions in the database then you could either use the dbase to do it for have the data written to another file for you to check...however having everything written twice does seem like a little waste of resources.

HoboTraveler

5:07 pm on Oct 23, 2007 (gmt 0)

10+ Year Member



Yes, that was my question.

How do I go about creating the test? Do I need to parse forms? I don't think this is even possible?

TIA

PHP_Chimp

5:17 pm on Oct 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To test validation -
Once you have built your form, including any validation rules, you need to enter data and see if it passes your test.
i.e. if you are testing an email address using a regular expression then if me@test.com doesnt work then there is a problem with your rules.

To test if data is entered properly -
That is down to the validation as above.
If you are looking to log/get a mail if the database fails then you would need to add something like -


// assuming your connection is held in the variable $con
if (!$con) {
$body = 'your database is not working.'
// add whatever you want to the body
$body = wordwrap($body, 70);
mail('you@yourdomain.tld', 'database not working', $body);
// if you want to write the details to a log then look at the [url=http://uk2.php.net/manual/en/ref.filesystem.php]file[/url] functions
}

HoboTraveler

6:08 pm on Oct 23, 2007 (gmt 0)

10+ Year Member



There's an issue here. I do not want to manually enter anything.

I need to create a system that is triggered through a CRON, loads up a form on our server, enters the test data, and the form would proceed to the next step.

The test system would work as if it was a person entering data. I would allow the test system to have a relaxed permission set etc.

The first priority is how to get the test system work with forms?

Any ideas?

TIA

PHP_Chimp

7:04 pm on Oct 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Testing your validation rules only needs to be done once. So you could write the cron to do that...or you could just enter the data yourself.

i.e.
if you want to test that input isnt allowed a % in the string then you would need to write your cron to tell it to -
1- open the correct file
2- put a % in the correct field
3- let you know what the response is
Wouldnt it just be a lot faster to open the form and type a single character into that form? So manually you type the address into the browser and enter %, for the cron there is a lot more code.

To test my rules I wrote another page that had all combinations of things on it. So it has inputs that should pass and some that should fail. You can then check the output using something like -


$test_item = array('hello', 'hello%^&', 'hello again', 'hello again.');
// add whatever you want to test to this array
foreach ($test_item as $k => $v) {
if (preg_match($pattern, $v) == 1){
$t = "$v passed"
else {
$t = "$v failed";
}
echo $t;
}

Im sure that what you are after can be done, but I think it would actually take you longer to do than to manually check...so what is the point, other than as an academic exercise?
I dont understand why you want to automate this?
If you are really intent on automating this then I would have a look at designing your own spider. There are plenty of articles on the web about how to do it.