Symfony 2 Crawler表单提交显示错误“LogicException:无法在”input“标记上提交。”

时间:2012-10-30 06:05:01

标签: symfony phpunit functional-testing

让我们说,我有一个表格:

<form action="test.php" method="post">
    <input type="text" name="myinput" value="3" />
    <button>Submit</button>
</form>

这是我对Crawler的过滤和测试:

$client = static::createClient();
$crawler = $client->request('GET', 'test.php');

$filter = 'button';
$buttonNode = $crawler->selectButton($crawler->filter($filter));
$this->assertEquals(1, $buttonNode->count()); // this works

$form = $buttonNode->form(); // This shows error "LogicException: Unable to submit on a "input" tag."
$client->submit($form);

2 个答案:

答案 0 :(得分:2)

我认为问题出在按钮的定义中。我将重命名它只是为了更好地理解并在那里添加类型:

<button type="submit">SubmitLabel</button>

然后它应该像我这样工作:

$client = static::createClient();
$crawler = $client->request('GET', 'test.php');

$buttonCrawlerNode = $crawler->selectButton('SubmitLabel');      
$form = $buttonCrawlerNode->form();
$client->submit($form);

答案 1 :(得分:0)

您需要找到类似我question的方式。

或者它仅用于一次测试而不是很多测试,您可以使用casperJS