文本字段名称带有方括号([)的PHP单元
问题描述:
我正在使用Laracasts \ Integrated库(与PHPUNIT)测试一个Web项目.
I am testing a web project using Laracasts\Integrated library (with PHPUNIT).
我有以下HTML表单:
I have a following HTML form:
<input type="text" name = "company[0][name]" id="comp_0" />
我有以下测试案例:
/** @test **/
public function add_new()
{
$this->type('New Company' , 'company[0][name]');
}
我收到以下错误:
Symfony\Component\CssSelector\Exception\SyntaxErrorException: Expected identifier or "*", but <number at 20> found.
我正在搜索并尝试很多...但是我无法获得解决方案.
I am searching and trying alot ... but i am not able to get the solution for it.
答
解决方案很简单:
/** @test **/
public function add_this()
{
$this->storeInput('company[0][name]' , 'New Company Here On Nepal' ,true);
}
public function storeInput($element, $text, $force = false)
{
if ($force) {
$this->inputs[$element] = $text;
return $this;
}
else {
return parent::storeInput($element, $text);
}
}