CheckboxTest.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace Behat\Mink\Tests\Driver\Form;
  3. use Behat\Mink\Tests\Driver\TestCase;
  4. class CheckboxTest extends TestCase
  5. {
  6. public function testManipulate()
  7. {
  8. $this->getSession()->visit($this->pathTo('advanced_form.html'));
  9. $checkbox = $this->getAssertSession()->fieldExists('agreement');
  10. $this->assertNull($checkbox->getValue());
  11. $this->assertFalse($checkbox->isChecked());
  12. $checkbox->check();
  13. $this->assertEquals('yes', $checkbox->getValue());
  14. $this->assertTrue($checkbox->isChecked());
  15. $checkbox->uncheck();
  16. $this->assertNull($checkbox->getValue());
  17. $this->assertFalse($checkbox->isChecked());
  18. }
  19. public function testSetValue()
  20. {
  21. $this->getSession()->visit($this->pathTo('advanced_form.html'));
  22. $checkbox = $this->getAssertSession()->fieldExists('agreement');
  23. $this->assertNull($checkbox->getValue());
  24. $this->assertFalse($checkbox->isChecked());
  25. $checkbox->setValue(true);
  26. $this->assertEquals('yes', $checkbox->getValue());
  27. $this->assertTrue($checkbox->isChecked());
  28. $checkbox->setValue(false);
  29. $this->assertNull($checkbox->getValue());
  30. $this->assertFalse($checkbox->isChecked());
  31. }
  32. public function testCheckboxMultiple()
  33. {
  34. $this->getSession()->visit($this->pathTo('/multicheckbox_form.html'));
  35. $webAssert = $this->getAssertSession();
  36. $this->assertEquals('Multicheckbox Test', $webAssert->elementExists('css', 'h1')->getText());
  37. $updateMail = $webAssert->elementExists('css', '[name="mail_types[]"][value="update"]');
  38. $spamMail = $webAssert->elementExists('css', '[name="mail_types[]"][value="spam"]');
  39. $this->assertEquals('update', $updateMail->getValue());
  40. $this->assertNull($spamMail->getValue());
  41. $this->assertTrue($updateMail->isChecked());
  42. $this->assertFalse($spamMail->isChecked());
  43. $updateMail->uncheck();
  44. $this->assertFalse($updateMail->isChecked());
  45. $this->assertFalse($spamMail->isChecked());
  46. $spamMail->check();
  47. $this->assertFalse($updateMail->isChecked());
  48. $this->assertTrue($spamMail->isChecked());
  49. }
  50. }