HoverTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace Behat\Mink\Tests\Driver\Css;
  3. use Behat\Mink\Tests\Driver\TestCase;
  4. class HoverTest extends TestCase
  5. {
  6. /**
  7. * @group mouse-events
  8. */
  9. public function testMouseOverHover()
  10. {
  11. $this->getSession()->visit($this->pathTo('/css_mouse_events.html'));
  12. $this->findById('reset-square')->mouseOver();
  13. $this->assertActionSquareHeight(100);
  14. $this->findById('action-square')->mouseOver();
  15. $this->assertActionSquareHeight(200);
  16. }
  17. /**
  18. * @group mouse-events
  19. * @depends testMouseOverHover
  20. */
  21. public function testClickHover()
  22. {
  23. $this->getSession()->visit($this->pathTo('/css_mouse_events.html'));
  24. $this->findById('reset-square')->mouseOver();
  25. $this->assertActionSquareHeight(100);
  26. $this->findById('action-square')->click();
  27. $this->assertActionSquareHeight(200);
  28. }
  29. /**
  30. * @group mouse-events
  31. * @depends testMouseOverHover
  32. */
  33. public function testDoubleClickHover()
  34. {
  35. $this->getSession()->visit($this->pathTo('/css_mouse_events.html'));
  36. $this->findById('reset-square')->mouseOver();
  37. $this->assertActionSquareHeight(100);
  38. $this->findById('action-square')->doubleClick();
  39. $this->assertActionSquareHeight(200);
  40. }
  41. /**
  42. * @group mouse-events
  43. * @depends testMouseOverHover
  44. */
  45. public function testRightClickHover()
  46. {
  47. $this->getSession()->visit($this->pathTo('/css_mouse_events.html'));
  48. $this->findById('reset-square')->mouseOver();
  49. $this->assertActionSquareHeight(100);
  50. $this->findById('action-square')->rightClick();
  51. $this->assertActionSquareHeight(200);
  52. }
  53. private function assertActionSquareHeight($expected)
  54. {
  55. $this->assertEquals(
  56. $expected,
  57. $this->getSession()->evaluateScript("return window.$('#action-square').height();"),
  58. 'Mouse is located over the object when mouse-related action is performed'
  59. );
  60. }
  61. }