我正在使用phpunit启动我的测试,所以,我对如何动态测试事物有疑问。我动态地创建了一个表格,如下图所示
以下是我的观点:
<div class="panel-body">
@if(Session::has('success'))
<div class="alert alert-success">{{Session::get('success')}}</div>
@endif
<table class="table">
<th>Unity Name</th>
<th>Phone Number</th>
<th>Actions</th>
<tbody>
@foreach($companies as $company)
<tr>
<td>{{$company->name}}</td>
<td>{{$company->owner_number}}</td>
<td>
<a href="/admin/company/{{$company->id}}" class="btn btn-default fa fa-newspaper-o"></a>
<a href="/admin/company/{{$company->id}}/clients" class="btn btn-default fa fa-users"></a>
<a href="company/{{$company->id}}/edit" class="btn btn-default fa fa-pencil-square-o"></a>
{{Form::open(['method' => 'DELETE', 'url'=>'/admin/company/'.$company->id, 'style' => 'display:inline'])}}
<button type="submit" class="btn btn-default fa fa-trash-o"></button>
{{Form::close()}}
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
那么,如果我以前没有标签ID,我怎样才能测试href标签?
答案 0 :(得分:0)
我在Symfony项目中做了一些像这样的测试。
在开发环境中,我在dev数据库中插入一些数据。完成此步骤后,我将启动功能测试。在这些测试中,我分析了标签的内容。以下是您的数据示例:
$client = static::createClient();
$crawler = $client->request('GET', '/yourUrl');
$node = $crawler->filter('#show-company-1');
self::assertNotEmpty($node, "Node #show-company-1 does not exists");
self::assertEmpty( $node->html(), "#show-company-1 content is not empty");
self::assertContains('/admin/company/1', $node->attr('href'), "a#show-company-1.href has not a good value");
在请求之前,您可以添加一些逻辑来确定公司的ID。