Well, I think what you're looking for is the type
function that simulates entering data in the input
html fields.
For example:
You have the following html code, where there are the input
s of email and password and the Login button
<form class="form-horizontal" role="form" method="POST" action="{{ url('login') }}">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="form-group ">
<label class="col-md-4 control-label">Email</label>
<div class="col-md-6">
{!! Form::text('email',null,['class'=>'form-control','placeholder'=>'Ej:email','required']) !!}
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Contraseña</label>
<div class="col-md-6">
{!! Form::password('password',['class'=>'form-control','placeholder'=>'Ingrese su contraseña',"required"]) !!}
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-primary">Login</button>
</div>
</div>
</form>
You can do a test function in the following way.
public function testLogin()
{
$this->visit('/login');//pagina de login
$this->type('[email protected]', 'email');//email es el name del input.
$this->type('contraseña', 'password');//password es el name del input.
$this->press('Login');//Login es el contenido del button.
$this->seePageIs('/home');// pagina de redireccion.
}
you execute phpunit
in your console, within your project and ready.
For this function to run correctly, the password and the email must belong to a user in the database, in addition to the functionality of the login must be complete.