RadioTest.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace Behat\Mink\Tests\Driver\Form;
  3. use Behat\Mink\Tests\Driver\TestCase;
  4. class RadioTest extends TestCase
  5. {
  6. protected function setUp()
  7. {
  8. $this->getSession()->visit($this->pathTo('radio.html'));
  9. }
  10. public function testIsChecked()
  11. {
  12. $option = $this->findById('first');
  13. $option2 = $this->findById('second');
  14. $this->assertTrue($option->isChecked());
  15. $this->assertFalse($option2->isChecked());
  16. $option2->selectOption('updated');
  17. $this->assertFalse($option->isChecked());
  18. $this->assertTrue($option2->isChecked());
  19. }
  20. public function testSelectOption()
  21. {
  22. $option = $this->findById('first');
  23. $this->assertEquals('set', $option->getValue());
  24. $option->selectOption('updated');
  25. $this->assertEquals('updated', $option->getValue());
  26. $option->selectOption('set');
  27. $this->assertEquals('set', $option->getValue());
  28. }
  29. public function testSetValue()
  30. {
  31. $option = $this->findById('first');
  32. $this->assertEquals('set', $option->getValue());
  33. $option->setValue('updated');
  34. $this->assertEquals('updated', $option->getValue());
  35. $this->assertFalse($option->isChecked());
  36. }
  37. public function testSameNameInMultipleForms()
  38. {
  39. $option1 = $this->findById('reused_form1');
  40. $option2 = $this->findById('reused_form2');
  41. $this->assertEquals('test2', $option1->getValue());
  42. $this->assertEquals('test3', $option2->getValue());
  43. $option1->selectOption('test');
  44. $this->assertEquals('test', $option1->getValue());
  45. $this->assertEquals('test3', $option2->getValue());
  46. }
  47. /**
  48. * @see https://github.com/Behat/MinkSahiDriver/issues/32
  49. */
  50. public function testSetValueXPathEscaping()
  51. {
  52. $session = $this->getSession();
  53. $session->visit($this->pathTo('/advanced_form.html'));
  54. $page = $session->getPage();
  55. $sex = $page->find('xpath', '//*[@name = "sex"]'."\n|\n".'//*[@id = "sex"]');
  56. $this->assertNotNull($sex, 'xpath with line ending works');
  57. $sex->setValue('m');
  58. $this->assertEquals('m', $sex->getValue(), 'no double xpath escaping during radio button value change');
  59. }
  60. }