You are here

class ChangeEventTest in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/behat/mink/driver-testsuite/tests/Js/ChangeEventTest.php \Behat\Mink\Tests\Driver\Js\ChangeEventTest

@group slow

Hierarchy

  • class \Behat\Mink\Tests\Driver\TestCase extends \Behat\Mink\Tests\Driver\PHPUnit_Framework_TestCase

Expanded class hierarchy of ChangeEventTest

File

vendor/behat/mink/driver-testsuite/tests/Js/ChangeEventTest.php, line 10

Namespace

Behat\Mink\Tests\Driver\Js
View source
class ChangeEventTest extends TestCase {

  /**
   * 'change' event should be fired after selecting an <option> in a <select>.
   *
   * TODO check whether this test is redundant with other change event tests.
   */
  public function testIssue255() {
    $session = $this
      ->getSession();
    $session
      ->visit($this
      ->pathTo('/issue255.html'));
    $session
      ->getPage()
      ->selectFieldOption('foo_select', 'Option 3');
    $session
      ->wait(2000, '$("#output_foo_select").text() != ""');
    $this
      ->assertEquals('onChangeSelect', $this
      ->getAssertSession()
      ->elementExists('css', '#output_foo_select')
      ->getText());
  }
  public function testIssue178() {
    $session = $this
      ->getSession();
    $session
      ->visit($this
      ->pathTo('/issue178.html'));
    $this
      ->findById('source')
      ->setValue('foo');
    $this
      ->assertEquals('foo', $this
      ->findById('target')
      ->getText());
  }

  /**
   * @dataProvider setValueChangeEventDataProvider
   * @group change-event-detector
   */
  public function testSetValueChangeEvent($elementId, $valueForEmpty, $valueForFilled = '') {
    $this
      ->getSession()
      ->visit($this
      ->pathTo('/element_change_detector.html'));
    $page = $this
      ->getSession()
      ->getPage();
    $input = $this
      ->findById($elementId);
    $this
      ->assertNull($page
      ->findById($elementId . '-result'));

    // Verify setting value, when control is initially empty.
    $input
      ->setValue($valueForEmpty);
    $this
      ->assertElementChangeCount($elementId, 'initial value setting triggers change event');
    if ($valueForFilled) {

      // Verify setting value, when control already has a value.
      $this
        ->findById('results')
        ->click();
      $input
        ->setValue($valueForFilled);
      $this
        ->assertElementChangeCount($elementId, 'value change triggers change event');
    }
  }
  public function setValueChangeEventDataProvider() {
    return array(
      'input default' => array(
        'the-input-default',
        'from empty',
        'from existing',
      ),
      'input text' => array(
        'the-input-text',
        'from empty',
        'from existing',
      ),
      'input email' => array(
        'the-email',
        'from empty',
        'from existing',
      ),
      'textarea' => array(
        'the-textarea',
        'from empty',
        'from existing',
      ),
      'file' => array(
        'the-file',
        'from empty',
        'from existing',
      ),
      'select' => array(
        'the-select',
        '30',
      ),
      'radio' => array(
        'the-radio-m',
        'm',
      ),
    );
  }

  /**
   * @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 = $this
      ->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',
      ),
    );
  }

  /**
   * @dataProvider checkboxTestWayDataProvider
   * @group change-event-detector
   */
  public function testCheckChangeEvent($useSetValue) {
    $this
      ->getSession()
      ->visit($this
      ->pathTo('/element_change_detector.html'));
    $page = $this
      ->getSession()
      ->getPage();
    $checkbox = $this
      ->findById('the-unchecked-checkbox');
    $this
      ->assertNull($page
      ->findById('the-unchecked-checkbox-result'));
    if ($useSetValue) {
      $checkbox
        ->setValue(true);
    }
    else {
      $checkbox
        ->check();
    }
    $this
      ->assertElementChangeCount('the-unchecked-checkbox');
  }

  /**
   * @dataProvider checkboxTestWayDataProvider
   * @group change-event-detector
   */
  public function testUncheckChangeEvent($useSetValue) {
    $this
      ->getSession()
      ->visit($this
      ->pathTo('/element_change_detector.html'));
    $page = $this
      ->getSession()
      ->getPage();
    $checkbox = $this
      ->findById('the-checked-checkbox');
    $this
      ->assertNull($page
      ->findById('the-checked-checkbox-result'));
    if ($useSetValue) {
      $checkbox
        ->setValue(false);
    }
    else {
      $checkbox
        ->uncheck();
    }
    $this
      ->assertElementChangeCount('the-checked-checkbox');
  }
  public function checkboxTestWayDataProvider() {
    return array(
      array(
        true,
      ),
      array(
        false,
      ),
    );
  }
  private function assertElementChangeCount($elementId, $message = '') {
    $counterElement = $this
      ->getSession()
      ->getPage()
      ->findById($elementId . '-result');
    $actualCount = null === $counterElement ? 0 : $counterElement
      ->getText();
    $this
      ->assertEquals('1', $actualCount, $message);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ChangeEventTest::assertElementChangeCount private function
ChangeEventTest::checkboxTestWayDataProvider public function
ChangeEventTest::selectOptionChangeEventDataProvider public function
ChangeEventTest::setValueChangeEventDataProvider public function
ChangeEventTest::testCheckChangeEvent public function @dataProvider checkboxTestWayDataProvider @group change-event-detector
ChangeEventTest::testIssue178 public function
ChangeEventTest::testIssue255 public function 'change' event should be fired after selecting an <option> in a <select>.
ChangeEventTest::testSelectOptionChangeEvent public function @dataProvider selectOptionChangeEventDataProvider @group change-event-detector
ChangeEventTest::testSetValueChangeEvent public function @dataProvider setValueChangeEventDataProvider @group change-event-detector
ChangeEventTest::testUncheckChangeEvent public function @dataProvider checkboxTestWayDataProvider @group change-event-detector
TestCase::$config private static property
TestCase::$mink private static property Mink session manager.
TestCase::checkRequirements protected function
TestCase::createDriver protected function Creates a new driver instance.
TestCase::findById protected function
TestCase::getAssertSession protected function Returns assert session.
TestCase::getConfig private static function
TestCase::getSession protected function Returns session.
TestCase::mapRemoteFilePath protected function Map remote file path.
TestCase::onNotSuccessfulTest protected function
TestCase::pathTo protected function
TestCase::safePageWait protected function Waits for a condition to be true, considering than it is successful for drivers not supporting wait().
TestCase::setUpBeforeClass public static function Initializes the test case.
TestCase::tearDown protected function