samedi 7 novembre 2015

Laravel 5.1 PHPunit form testing fails everytime

I have a test set up like this

use WithoutMiddleware;
public function test_it_submits_forms()
{
   $this->visit('/admin/menu/samples/')
        ->click('New Sample')
        ->seePageIs('/admin/menu/samples/new/create')
        ->type('name','test1')
        ->type('slug','test2')
        ->press('add')
        ->onPage('/admin/menu/samples');
}

and the file I am testing like this.

{!! Form::open(['url' => 'admin/menu/samples/', 'method' => 'POST']) !!}
<div class="row"><div class="form-group col-xs-8 col-md-7 {!! $errors->has('name') ? 'has-
error' : '' !!}">


    {!! Form::label('name', 'Name:') !!}
    {!! Form::text('name', null,['class' => 'form-control']) !!}
    {!! $errors->first('name', '<span class="help-block">:message</span>')!!}
</div>

<div class="form-group col-xs-8 col-md-7">
    {!! Form::label('introduction', 'Introduction:') !!}
    {!! Form::textarea('introduction',null, ['class' => 'form-control']) !!}
</div>
<div class="form-group col-xs-8 col-md-7">
    {!! Form::label('description', 'Description:') !!}
    {!! Form::textarea('description',null, ['class' => 'form-control']) !!}
</div>
<div class="form-group col-xs-8 col-md-7 {!! $errors->has('slug') ? 'has-error' : '' !!}">
    {!! Form::label('slug', 'URL:') !!}
    {!! Form::text('slug',null, ['class' => 'form-control']) !!}
    {!! $errors->first('slug', '<span class="help-block">:message</span>') !!}
</div>
<div class="form-group col-xs-8 col-md-7">
    {!! Form::label('available_from', 'Available from:') !!}
    {!! Form::date('available_from', \Carbon\Carbon::now(), ['class' => 'form-control2']) !!}
</div>
<div class="form-group col-xs-8 col-md-7">
    {!! Form::label('available_until', 'Available until:') !!}
    {!! Form::date('available_until', \Carbon\Carbon::now(), ['class' => 'form-control2']) !!}
</div> 
<div class="form-group col-xs-8 col-md-7">
    {!! Form::label('needs_auth', 'Needs authentication:') !!}
    {!! Form::checkbox('needs_auth', 'value', false) !!}
</div>
<div class="form-group col-xs-8 col-md-7">
    {!! Form::label('is_active', 'Active:') !!}
    {!! Form::checkbox('is_active', 'value', false) !!}
</div>
<div class="form-group col-xs-8 col-md-7">
    <h3>Add a scenario</h3>  
    {!! Form::select('scenario_id',($scenario), null,           
['id'=>'scenario_id','placeholder' => 'Select one...']) !!}

</div>
<div class="form-group col-xs-8 col-md-7">
    {!! Form::submit('Add', ['class' => 'btn btn-primary']) !!}
</div>

{!! Form::close() !!}

The test throws undefined variable errors on both of the variables $errors in form elements name and slug ( they just light up the form if something is not filled properly).

 Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'Undefined varia...', '/home/vagrant/C...', 9, Array)

Going forward, if I remove the error checking then ->type('name','test1')

1) CreateSampleTest::test_it_submits_forms
InvalidArgumentException: Nothing matched the filter [test1] CSS query  provided for [http://localhost/admin/menu/samples/new/create]

Could anyone tell why and how to fix this?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire