diff --git a/tests/Behat/Mink/Driver/JavascriptDriverTest.php b/tests/Behat/Mink/Driver/JavascriptDriverTest.php index 826a7f837..432db37ac 100644 --- a/tests/Behat/Mink/Driver/JavascriptDriverTest.php +++ b/tests/Behat/Mink/Driver/JavascriptDriverTest.php @@ -383,4 +383,94 @@ public function testWindowMaximize() $this->assertTrue($session->evaluateScript($script)); } + + /** + * @dataProvider setValueChangeEventDataProvider + * @group change-event-detector + */ + public function testSetValueChangeEvent($elementId, $elementValue) + { + $this->getSession()->visit($this->pathTo('/element_change_detector.html')); + $page = $this->getSession()->getPage(); + + $input = $page->findById($elementId); + $this->assertNull($page->findById($elementId.'-result')); + + $input->setValue($elementValue); + $this->assertElementChangeCount($elementId); + } + + public function setValueChangeEventDataProvider() + { + return array( + 'input default' => array('the-input-default', 'some value'), + 'input text' => array('the-input-text', 'some value'), + 'input email' => array('the-email', 'some value'), + 'select' => array('the-select', '30'), + 'textarea' => array('the-textarea', 'some value'), + 'file' => array('the-file', 'some value'), + ); + } + + /** + * @dataProvider selectOptionChangeEventDataProvider + * @group change-event-detector + */ + public function testSelectOptionChangeEvent($elementId, $elementValue) + { + $this->getSession()->visit($this->pathTo('/element_change_detector.html')); + $page = $this->getSession()->getPage(); + + $input = $page->findById($elementId); + $this->assertNull($page->findById($elementId.'-result')); + + $input->selectOption($elementValue); + $this->assertElementChangeCount($elementId); + } + + public function selectOptionChangeEventDataProvider() + { + return array( + 'select' => array('the-select', '30'), + 'radio' => array('the-radio-m', 'm'), + ); + } + + /** + * @group change-event-detector + */ + public function testCheckChangeEvent() + { + $this->getSession()->visit($this->pathTo('/element_change_detector.html')); + $page = $this->getSession()->getPage(); + + $checkbox = $page->findById('the-unchecked-checkbox'); + $this->assertNull($page->findById('the-unchecked-checkbox-result')); + + $checkbox->check(); + $this->assertElementChangeCount('the-unchecked-checkbox'); + } + + /** + * @group change-event-detector + */ + public function testUncheckChangeEvent() + { + $this->getSession()->visit($this->pathTo('/element_change_detector.html')); + $page = $this->getSession()->getPage(); + + $checkbox = $page->findById('the-checked-checkbox'); + $this->assertNull($page->findById('the-checked-checkbox-result')); + + $checkbox->uncheck(); + $this->assertElementChangeCount('the-checked-checkbox'); + } + + protected function assertElementChangeCount($elementId) + { + $counterElement = $this->getSession()->getPage()->findById($elementId.'-result'); + $actualCount = null === $counterElement ? 0 : $counterElement->getText(); + + $this->assertEquals('1', $actualCount); + } } diff --git a/tests/Behat/Mink/Driver/web-fixtures/element_change_detector.html b/tests/Behat/Mink/Driver/web-fixtures/element_change_detector.html new file mode 100644 index 000000000..b6b388f0b --- /dev/null +++ b/tests/Behat/Mink/Driver/web-fixtures/element_change_detector.html @@ -0,0 +1,60 @@ + + +
+