我正在为我在 Laravel 5.1 中编写的表单编写一些测试,但我收到一条错误消息:
Symfony\Component\CssSelector\Exception\SyntaxErrorException: Expected identifier or "*", but <number "1" at 11> found.
问题是我为某些字段使用了“数组”名称。
这是一系列问题,我使用问题 ID 来映射答案:
<label>Your answer for question 1?
<textarea name="question[1]"></textarea>
<label>
<label>Your answer for question 2?
<textarea name="question[2]"></textarea>
<label>
然后我的测试看起来像这样:
$response = $this->actingAs($user)
->visit('/application/project/1/1')
->type('This is a new title', 'title')
->type('My Question one Answer', 'question[1]')
->press('Save & Next Page');
我假设我需要以不同的方式呈现question[1]
,但我不知道如何做。
最佳答案
解决此问题的一种方法是使用 submitForm
方法。
$input = [
'title' => 'This is my new title',
'question[1]' => 'My Question one answer'
];
$response = $this->actingAs($user)
->visit('/application/project/1/1')
->submitForm('Save & Next Page', $input);
希望这对您有所帮助!
关于php - 数组作为 Laravel 5.1 中的输入名称测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32547908/