简体   繁体   English

如何使用Laravel Application测试“取消选中”复选框字段?

[英]How can I “uncheck” a checkbox field with Laravel Application testing?

In Laravel 5.1 according to http://laravel.com/docs/5.1/testing#interacting-with-your-application I can use: 在Laravel 5.1中根据http://laravel.com/docs/5.1/testing#interacting-with-your-application我可以使用:

$this->visit('/register')
     ->type('Taylor', 'name')
     ->check('terms')
     ->press('Register')
     ->seePageIs('/dashboard');

But is there any way to uncheck a checkbox? 但有没有办法取消选中复选框? (No matter if it is checked or not). (无论是否检查)。

Thanks 谢谢

You can make use of the underlying DOM crawler (Symfony). 您可以使用底层DOM爬虫(Symfony)。

  • you reference the form by the text on the submit button 您可以通过提交按钮上的文本引用表单
  • you can check or uncheck elements 您可以选中或取消选中元素
  • finally you submit the form 最后你提交表格

     $form = $this->getForm('SUBMIT'); $form['single_cb']->untick(); $form['multiple_cb'][0]->untick(); $form['multiple_cb'][1]->tick(); $form['multiple_cb'][2]->tick(); $this->makeRequestUsingForm($form); 

你现在也可以使用

$this->uncheck('#my-checkbox');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM