You are here

class EventsTest in Zircon Profile 8

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

Hierarchy

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

Expanded class hierarchy of EventsTest

File

vendor/behat/mink/driver-testsuite/tests/Js/EventsTest.php, line 7

Namespace

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

  /**
   * @group mouse-events
   */
  public function testClick() {
    $this
      ->getSession()
      ->visit($this
      ->pathTo('/js_test.html'));
    $clicker = $this
      ->getAssertSession()
      ->elementExists('css', '.elements div#clicker');
    $this
      ->assertEquals('not clicked', $clicker
      ->getText());
    $clicker
      ->click();
    $this
      ->assertEquals('single clicked', $clicker
      ->getText());
  }

  /**
   * @group mouse-events
   */
  public function testDoubleClick() {
    $this
      ->getSession()
      ->visit($this
      ->pathTo('/js_test.html'));
    $clicker = $this
      ->getAssertSession()
      ->elementExists('css', '.elements div#clicker');
    $this
      ->assertEquals('not clicked', $clicker
      ->getText());
    $clicker
      ->doubleClick();
    $this
      ->assertEquals('double clicked', $clicker
      ->getText());
  }

  /**
   * @group mouse-events
   */
  public function testRightClick() {
    $this
      ->getSession()
      ->visit($this
      ->pathTo('/js_test.html'));
    $clicker = $this
      ->getAssertSession()
      ->elementExists('css', '.elements div#clicker');
    $this
      ->assertEquals('not clicked', $clicker
      ->getText());
    $clicker
      ->rightClick();
    $this
      ->assertEquals('right clicked', $clicker
      ->getText());
  }

  /**
   * @group mouse-events
   */
  public function testFocus() {
    $this
      ->getSession()
      ->visit($this
      ->pathTo('/js_test.html'));
    $focusBlurDetector = $this
      ->getAssertSession()
      ->elementExists('css', '.elements input#focus-blur-detector');
    $this
      ->assertEquals('no action detected', $focusBlurDetector
      ->getValue());
    $focusBlurDetector
      ->focus();
    $this
      ->assertEquals('focused', $focusBlurDetector
      ->getValue());
  }

  /**
   * @group mouse-events
   * @depends testFocus
   */
  public function testBlur() {
    $this
      ->getSession()
      ->visit($this
      ->pathTo('/js_test.html'));
    $focusBlurDetector = $this
      ->getAssertSession()
      ->elementExists('css', '.elements input#focus-blur-detector');
    $this
      ->assertEquals('no action detected', $focusBlurDetector
      ->getValue());
    $focusBlurDetector
      ->blur();
    $this
      ->assertEquals('blured', $focusBlurDetector
      ->getValue());
  }

  /**
   * @group mouse-events
   */
  public function testMouseOver() {
    $this
      ->getSession()
      ->visit($this
      ->pathTo('/js_test.html'));
    $mouseOverDetector = $this
      ->getAssertSession()
      ->elementExists('css', '.elements div#mouseover-detector');
    $this
      ->assertEquals('no mouse action detected', $mouseOverDetector
      ->getText());
    $mouseOverDetector
      ->mouseOver();
    $this
      ->assertEquals('mouse overed', $mouseOverDetector
      ->getText());
  }

  /**
   * @dataProvider provideKeyboardEventsModifiers
   */
  public function testKeyboardEvents($modifier, $eventProperties) {
    $this
      ->getSession()
      ->visit($this
      ->pathTo('/js_test.html'));
    $webAssert = $this
      ->getAssertSession();
    $input1 = $webAssert
      ->elementExists('css', '.elements input.input.first');
    $input2 = $webAssert
      ->elementExists('css', '.elements input.input.second');
    $input3 = $webAssert
      ->elementExists('css', '.elements input.input.third');
    $event = $webAssert
      ->elementExists('css', '.elements .text-event');
    $input1
      ->keyDown('u', $modifier);
    $this
      ->assertEquals('key downed:' . $eventProperties, $event
      ->getText());
    $input2
      ->keyPress('r', $modifier);
    $this
      ->assertEquals('key pressed:114 / ' . $eventProperties, $event
      ->getText());
    $input3
      ->keyUp(78, $modifier);
    $this
      ->assertEquals('key upped:78 / ' . $eventProperties, $event
      ->getText());
  }
  public function provideKeyboardEventsModifiers() {
    return array(
      'none' => array(
        null,
        '0 / 0 / 0 / 0',
      ),
      'alt' => array(
        'alt',
        '1 / 0 / 0 / 0',
      ),
      // jQuery considers ctrl as being a metaKey in the normalized event
      'ctrl' => array(
        'ctrl',
        '0 / 1 / 0 / 1',
      ),
      'shift' => array(
        'shift',
        '0 / 0 / 1 / 0',
      ),
      'meta' => array(
        'meta',
        '0 / 0 / 0 / 1',
      ),
    );
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EventsTest::provideKeyboardEventsModifiers public function
EventsTest::testBlur public function @group mouse-events @depends testFocus
EventsTest::testClick public function @group mouse-events
EventsTest::testDoubleClick public function @group mouse-events
EventsTest::testFocus public function @group mouse-events
EventsTest::testKeyboardEvents public function @dataProvider provideKeyboardEventsModifiers
EventsTest::testMouseOver public function @group mouse-events
EventsTest::testRightClick public function @group mouse-events
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