jeudi 3 décembre 2015

How to alter a hidden field within a TestCase in Laravel 5?

I have the following Test in which I'm needing to alter the value of a hidden input field, before submitting.

How can I alter the hidden _token field before submitting?

public function it_fails_to_submit_aun_invalid_token_post()
{
    // Given I am a not authenticated user (guest)

    // And I visit the homepage

    $this->visit('/auth/login');

    // And I fill the login form
    $this->type('test@example.org', 'email')
         ->type('password', 'password');

    // TODO: HERE Change the _token field value to simulate invalidation/tampering
    // Would be something similar to:
    // $this->type('INVALID TOKEN', '_token');
    // But this doesn't work because of (apparently) the DOM lib limitations inherited by TestCase

    $this->click('Login');

    // Then I should see an invalid token message
    $this->see('please submit your form again');
}

The full test code on the github project is here

Aucun commentaire:

Enregistrer un commentaire