Permalink
Browse files

Merge pull request #554 from stof/radio_tests

Added tests for the handling of radio buttons in the driver suite
  • Loading branch information...
2 parents 187d21e + 958bc47 commit 74e880b1a15336239c5ba0dde7d864e3f5150435 @stof stof committed May 17, 2014
@@ -434,20 +434,4 @@ public function testSubmitEmptyTextarea()
$this->assertContains($searchString, $pageContent);
}
}
-
- /**
- * @see https://github.com/Behat/MinkSahiDriver/issues/32
- */
- public function testSetValueXPathEscaping()
- {
- $session = $this->getSession();
- $session->visit($this->pathTo('/advanced_form.html'));
- $page = $session->getPage();
-
- $sex = $page->find('xpath', '//*[@name = "sex"]' . "\n|\n" . '//*[@id = "sex"]');
- $this->assertNotNull($sex, 'xpath with line ending works');
-
- $sex->setValue('m');
- $this->assertEquals('m', $sex->getValue(), 'no double xpath escaping during radio button value change');
- }
}
@@ -0,0 +1,92 @@
+<?php
+
+namespace Behat\Mink\Tests\Driver\Form;
+
+use Behat\Mink\Tests\Driver\TestCase;
+
+class RadioTest extends TestCase
+{
+ protected function setUp()
+ {
+ $this->getSession()->visit($this->pathTo('radio.html'));
+ }
+
+ public function testIsChecked()
+ {
+ $option = $this->getSession()->getPage()->findById('first');
+ $option2 = $this->getSession()->getPage()->findById('second');
+
+ $this->assertNotNull($option);
+ $this->assertNotNull($option2);
+
+ $this->assertTrue($option->isChecked());
+ $this->assertFalse($option2->isChecked());
+
+ $option2->selectOption('updated');
+
+ $this->assertFalse($option->isChecked());
+ $this->assertTrue($option2->isChecked());
+ }
+
+ public function testSelectOption()
+ {
+ $option = $this->getSession()->getPage()->findById('first');
+ $this->assertNotNull($option);
+
+ $this->assertEquals('set', $option->getValue());
+
+ $option->selectOption('updated');
+
+ $this->assertEquals('updated', $option->getValue());
+
+ $option->selectOption('set');
+
+ $this->assertEquals('set', $option->getValue());
+ }
+
+ public function testSetValue()
+ {
+ $option = $this->getSession()->getPage()->findById('first');
+ $this->assertNotNull($option);
+
+ $this->assertEquals('set', $option->getValue());
+
+ $option->setValue('updated');
+
+ $this->assertEquals('updated', $option->getValue());
+ $this->assertFalse($option->isChecked());
+ }
+
+ public function testSameNameInMultipleForms()
+ {
+ $option1 = $this->getSession()->getPage()->findById('reused_form1');
+ $option2 = $this->getSession()->getPage()->findById('reused_form2');
+
+ $this->assertNotNull($option1);
+ $this->assertNotNull($option2);
+
+ $this->assertEquals('test2', $option1->getValue());
+ $this->assertEquals('test3', $option2->getValue());
+
+ $option1->selectOption('test');
+
+ $this->assertEquals('test', $option1->getValue());
+ $this->assertEquals('test3', $option2->getValue());
+ }
+
+ /**
+ * @see https://github.com/Behat/MinkSahiDriver/issues/32
+ */
+ public function testSetValueXPathEscaping()
+ {
+ $session = $this->getSession();
+ $session->visit($this->pathTo('/advanced_form.html'));
+ $page = $session->getPage();
+
+ $sex = $page->find('xpath', '//*[@name = "sex"]' . "\n|\n" . '//*[@id = "sex"]');
+ $this->assertNotNull($sex, 'xpath with line ending works');
+
+ $sex->setValue('m');
+ $this->assertEquals('m', $sex->getValue(), 'no double xpath escaping during radio button value change');
+ }
+}
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>Radio group</title>
+</head>
+<body>
+ <form id="form1">
+ <input name="group1" type="radio" value="set" id="first" checked="checked">
+ <input name="group1" type="radio" value="updated" id="second">
+
+ <input name="reused" type="radio" value="test" id="reused_form1">
+ <input name="reused" type="radio" value="test2" id="reused2_form1" checked="checked">
+ </form>
+
+ <form id="form2">
+ <input name="reused" type="radio" value="test3" id="reused_form2" checked="checked">
+ <input name="reused" type="radio" value="test4" id="reused2_form2">
+ </form>
+</body>
+</html>

0 comments on commit 74e880b

Please sign in to comment.