Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #557 from stof/checkbox_tests

Added tests covering the checkbox usage with setValue and getValue
  • Loading branch information...
commit a1b7d498fffb57d3c1f153ba1ba03cbb4f2794dd 2 parents 67d624c + e42110f
@stof stof authored
View
76 driver-testsuite/tests/Form/CheckboxTest.php
@@ -0,0 +1,76 @@
+<?php
+
+namespace Behat\Mink\Tests\Driver\Form;
+
+use Behat\Mink\Tests\Driver\TestCase;
+
+class CheckboxTest extends TestCase
+{
+ public function testManipulate()
+ {
+ $this->getSession()->visit($this->pathTo('advanced_form.html'));
+
+ $checkbox = $this->getAssertSession()->fieldExists('agreement');
+
+ $this->assertFalse($checkbox->getValue());
+ $this->assertFalse($checkbox->isChecked());
+
+ $checkbox->check();
+
+ $this->assertTrue($checkbox->getValue());
+ $this->assertTrue($checkbox->isChecked());
+
+ $checkbox->uncheck();
+
+ $this->assertFalse($checkbox->getValue());
+ $this->assertFalse($checkbox->isChecked());
+ }
+
+ public function testSetValue()
+ {
+ $this->getSession()->visit($this->pathTo('advanced_form.html'));
+
+ $checkbox = $this->getAssertSession()->fieldExists('agreement');
+
+ $this->assertFalse($checkbox->getValue());
+ $this->assertFalse($checkbox->isChecked());
+
+ $checkbox->setValue(true);
+
+ $this->assertTrue($checkbox->getValue());
+ $this->assertTrue($checkbox->isChecked());
+
+ $checkbox->setValue(false);
+
+ $this->assertFalse($checkbox->getValue());
+ $this->assertFalse($checkbox->isChecked());
+ }
+
+ public function testCheckboxMultiple()
+ {
+ $this->getSession()->visit($this->pathTo('/multicheckbox_form.html'));
+
+ $page = $this->getSession()->getPage();
+ $this->assertEquals('Multicheckbox Test', $page->find('css', 'h1')->getText());
+
+ $updateMail = $page->find('css', '[name="mail_types[]"][value="update"]');
+ $spamMail = $page->find('css', '[name="mail_types[]"][value="spam"]');
+
+ $this->assertNotNull($updateMail);
+ $this->assertNotNull($spamMail);
+
+ $this->assertTrue($updateMail->getValue());
+ $this->assertFalse($spamMail->getValue());
+
+ $this->assertTrue($updateMail->isChecked());
+ $this->assertFalse($spamMail->isChecked());
+
+ $updateMail->uncheck();
+ $this->assertFalse($updateMail->isChecked());
+ $this->assertFalse($spamMail->isChecked());
+
+ $spamMail->check();
+ $this->assertFalse($updateMail->isChecked());
+ $this->assertTrue($spamMail->isChecked());
+ }
+}
View
28 driver-testsuite/tests/Form/GeneralTest.php
@@ -232,34 +232,6 @@ public function testAdvancedForm()
}
}
- public function testCheckboxMultiple()
- {
- $this->getSession()->visit($this->pathTo('/multicheckbox_form.html'));
-
- $page = $this->getSession()->getPage();
- $this->assertEquals('Multicheckbox Test', $page->find('css', 'h1')->getText());
-
- $updateMail = $page->find('css', '[name="mail_types[]"][value="update"]');
- $spamMail = $page->find('css', '[name="mail_types[]"][value="spam"]');
-
- $this->assertNotNull($updateMail);
- $this->assertNotNull($spamMail);
-
- $this->assertTrue($updateMail->getValue());
- $this->assertFalse($spamMail->getValue());
-
- $this->assertTrue($updateMail->isChecked());
- $this->assertFalse($spamMail->isChecked());
-
- $updateMail->uncheck();
- $this->assertFalse($updateMail->isChecked());
- $this->assertFalse($spamMail->isChecked());
-
- $spamMail->check();
- $this->assertFalse($updateMail->isChecked());
- $this->assertTrue($spamMail->isChecked());
- }
-
public function testMultiInput()
{
$this->getSession()->visit($this->pathTo('/multi_input_form.html'));
View
11 driver-testsuite/tests/TestCase.php
@@ -5,6 +5,7 @@
use Behat\Mink\Exception\UnsupportedDriverActionException;
use Behat\Mink\Mink;
use Behat\Mink\Session;
+use Behat\Mink\WebAssert;
abstract class TestCase extends \PHPUnit_Framework_TestCase
{
@@ -85,6 +86,16 @@ protected function getSession()
}
/**
+ * Returns assert session.
+ *
+ * @return WebAssert
+ */
+ protected function getAssertSession()
+ {
+ return self::$mink->assertSession('sess');
+ }
+
+ /**
* Map remote file path.
*
* @param string $file File path.
Please sign in to comment.
Something went wrong with that request. Please try again.