3

I want to create a test which will directly post data to a Laravel page to test it handling bad data.

I can run an acceptance test starting at the page with the form on, call $I->click('Search'); and the page processes the data as expected.

Reading the introduction to Functional Tests on the Codeception website, it states

In simple terms we set $_REQUEST, $_GET and $_POST variables, then we execute your script inside a test, we receive output, and then we test it.

This sounds ideal, set an array of POST data and fire it directly at the processing page. But I can't find any documentation for it. I've played with sendAjaxPostRequest but it's not passing anything to $_POST.

Is there a way I can test the pages in isolation like this?

2 Answers 2

4

Turns out the solution lies with the Codeception REST module.

Adding this to the functional.suite.yml file allows you to write:

$I = new TestGuy($scenario);
$I->wantTo('check a page is resistant to POST injection');
$I->sendPOST(
    'search',
    array(
        'startDate' => '2013-07-03',
        'endDate' => '2013-07-10',
        'exec' => 'some dodgy commands',
    ));
$I->see('Search results');
$I->dontSee('Dodgy command executed');

A little clunky, but it allows testing of a single page.

Sign up to request clarification or add additional context in comments.

Comments

-3

From the manual @ http://codeception.com/docs/04-AcceptanceTests

$I->submitForm('#update_form', array('user' => array(
     'name' => 'Miles',
     'email' => 'Davis',
     'gender' => 'm'
)));

2 Comments

That relies on the preceding page with the form. If I could do something like that but specify the target instead of relying on a form selector, then I could test it in isolation.
Hm, I got no solution for you. Maybe you should knock on some doors @codeception for this...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.