Laravel 5.4 PHPunit testing Unavailable field (using name / id attirbute)

I am testing Laravel according to Laracast / Integreted , exactly the same as the attribute of the attribute there . And one form per page.

I have multiple unit test on a form where the first two fields are reached, but on the third field, which is a text field with name = "input". Here is the html view

<form method="POST" action="/problem/add">
          {{ csrf_field() }}

          <div class="row">
              <div class="col-md-6">
                <div class="form-group">
                  <label>Problem Title</label>
                  <input name="title" type="text" class="form-control pull-right" style="width: 100%;" placeholder="Give a title">
                  </input>
                </div>
              </div>
              <!-- /.col -->

              <div class="col-md-6">
                <div class="form-group">
                  <label>Select a contest</label>
                  <select name="contest_id" class="form-control" data-placeholder="Select a Contest" style="width: 100%;">

                  @foreach($contests as $contest)
                    @if(isset($addToContest) && $contest==$addToContest)
                      <option selected="selected" value="{{ $contest->id }}">{{ $contest->title }}</option>
                    @else
                      <option value="{{ $contest->id }}">{{ $contest->title }}</option>
                    @endif

                  @endforeach

                  </select>

                </div>
              </div>
            </div>
              <!-- /.col -->


              <div class="col-md-12">
                <div class="form-group">
                  <label>Problem Description:</label>
                    <textarea name="description" class="textarea description" placeholder="Place some Description" style="width: 100%; height: 200px; font-size: 14px; line-height: 18px; border: 1px solid #dddddd; padding: 10px;"></textarea>
                </div>
                <!-- /.form group -->
              </div>
              <!-- /.col-->
            <div class="row">
              <div class="col-md-6">
                <div class="form-group">
                  <label>Sample Input:</label>
                    <textarea id="input" name="input" class="textarea input" placeholder="Place Sample Input" style="width: 100%; height: 200px; font-size: 14px; line-height: 18px; border: 1px solid #dddddd; padding: 10px;"></textarea>
                </div>
                <!-- /.form group -->
              </div>
              <!-- /.col-->

              <div class="col-md-6">
                <div class="form-group"> 
                  <label>Sample Output:</label>
                    <textarea id="output" name="output" class="textarea output" placeholder="Place Sample Output" style="width: 100%; height: 200px; font-size: 14px; line-height: 18px; border: 1px solid #dddddd; padding: 10px;"></textarea>
                </div>
                <!-- /.form group -->
              </div>
              <!-- /.col-->
            </div>
            <!-- /.row -->

            <div class="box-footer">
                <button type="submit" class="btn bg-olive btn-flat ">Create</button>
                <button type="reset" class="btn bg-orange btn-flat ">Cancel</button>
            </div>

            </div>

          </form>
      

Run codeHide result


When running phpunit code

public function testCreateContest()
{
    $this->visit('/admin_login')
        ->type('admin@admin.com', 'email')
        ->type('123456', 'password')
        ->press('Login')
        ->see('Admin')
        ->onPage('/admin_home')
        ->visit('/create_contest')
        ->see('Create New Contest')
        ->type('Contest Test', 'title')
        ->type('21/06/2017 0:00 - 25/06/2017 23:59','start_end_time')
        ->type('Test Contest Description','description')
        ->press('Create')
        ->see('Add Problem')
        ->submitForm('Create', [
            'title' => 'Test Problem',
            'description' => 'Test Problem Description',
            'input' => 'Test Input', //Here the test fails
            'output' => 'Test Output',

            ])
        ->see('Problem added to the contest');
}

      

I get

    There was 1 error:

1) Tests\Unit\CreateContestTest::testCreateContest
InvalidArgumentException: Unreachable field "input"

D:\SoftProjects\CodeCuet\vendor\symfony\dom-crawler\Symfony\Component\DomCrawler\FormFieldRegistry.php:89
D:\SoftProjects\CodeCuet\vendor\symfony\dom-crawler\Symfony\Component\DomCrawler\FormFieldRegistry.php:126
D:\SoftProjects\CodeCuet\vendor\symfony\dom-crawler\Symfony\Component\DomCrawler\Form.php:76
D:\SoftProjects\CodeCuet\vendor\laracasts\integrated\src\Extensions\IntegrationTrait.php:380
D:\SoftProjects\CodeCuet\vendor\laracasts\integrated\src\Extensions\Goutte.php:52
D:\SoftProjects\CodeCuet\tests\Unit\CreateContestTest.php:36

      

I've also used all the possible type () selector like id, class but nothing can reach the last two textarea fields. Please guide me with any solution or explanation for this problem.

+3


source to share





All Articles