【问题标题】:Testing Symfony 2 form that contains html data测试包含 html 数据的 Symfony 2 表单
【发布时间】:2013-06-10 11:01:14
【问题描述】:

假设页面http://test.intra具有以下表单代码:

<form>
<textarea id="description" name="description">&lt;p&gt;Hello&lt;/p&gt;</textarea>
<input type="submit" name="submit_save" id='submit_btn' value="Save">
</form>

description field 在浏览器上提交,值为&amp;lt;p&amp;gt;Hello&amp;lt;/p&amp;gt

但使用以下代码:

$crawler = $client->request('GET', 'http://test.intra');     
/* $client is a instance of \Symfony\Bundle\FrameworkBundle\Client ] 
 * $crawler is a instance of \Symfony\Component\DomCrawler\Crawler
*/

$domForm = $crawler->filter('form');
$domForm = $domForm->selectButton('submit_btn');
$this->client->submit($form);

description field 以值&amp;amp;lt;p&amp;amp;gt; &amp;amp;lt;/p&amp;amp;gt; 提交

客户端 [\Symfony\Bundle\FrameworkBundle\Client] 应该在调用提交之前解码表单数据吗?我错过了什么吗?

谢谢

【问题讨论】:

    标签: html forms symfony web-crawler richtext


    【解决方案1】:

    我不完全确定您在问什么,但我注意到您的代码不正确。

    $crawler = $client->request('GET', 'http://test.intra');
    
    $domForm = $crawler->filter('form')->form();
    $crawler = $this->client->submit($domForm);
    

    现在您可以在 $crawler 上检查您的断言了。

    $this->assertTrue($this->client->getResponse()->isSuccessful());
    

    【讨论】:

      猜你喜欢
      • 2015-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多