Laravel 5.4 PHPunit测试无法访问的字段(使用的名称/ id attirbute)

时间:2017-06-21 15:38:34

标签: php phpunit laravel-5.4 domcrawler

我根据Laracast / Integreted 测试Laravel完全按照名称属性显示 there。每页一个表格。

我在前两个字段到达的表单上有一些单元测试但在第三个字段上是一个textarea,名称="输入"。这是视图html



<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>
&#13;
&#13;
&#13;

运行phpunit代码时

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');
}

我得到了

    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

还在type()中使用了所有可能的选择器,例如id,class 但是没有任何东西可以到达最后两个textarea字段。请指导我解决这个问题。

0 个答案:

没有答案