You are here

class JavascriptEvaluationTest in Zircon Profile 8

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

Hierarchy

Expanded class hierarchy of JavascriptEvaluationTest

File

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

Namespace

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

  /**
   * Tests, that `wait` method returns check result after exit.
   */
  public function testWaitReturnValue() {
    $this
      ->getSession()
      ->visit($this
      ->pathTo('/js_test.html'));
    $found = $this
      ->getSession()
      ->wait(5000, '$("#draggable").length == 1');
    $this
      ->assertTrue($found);
  }
  public function testWait() {
    $this
      ->getSession()
      ->visit($this
      ->pathTo('/js_test.html'));
    $waitable = $this
      ->findById('waitable');
    $waitable
      ->click();
    $this
      ->getSession()
      ->wait(3000, '$("#waitable").has("div").length > 0');
    $this
      ->assertEquals('arrived', $this
      ->getAssertSession()
      ->elementExists('css', '#waitable > div')
      ->getText());
    $waitable
      ->click();
    $this
      ->getSession()
      ->wait(3000, 'false');
    $this
      ->assertEquals('timeout', $this
      ->getAssertSession()
      ->elementExists('css', '#waitable > div')
      ->getText());
  }

  /**
   * @dataProvider provideExecutedScript
   */
  public function testExecuteScript($script) {
    $this
      ->getSession()
      ->visit($this
      ->pathTo('/index.html'));
    $this
      ->getSession()
      ->executeScript($script);
    sleep(1);
    $heading = $this
      ->getAssertSession()
      ->elementExists('css', 'h1');
    $this
      ->assertEquals('Hello world', $heading
      ->getText());
  }
  public function provideExecutedScript() {
    return array(
      array(
        'document.querySelector("h1").textContent = "Hello world"',
      ),
      array(
        'document.querySelector("h1").textContent = "Hello world";',
      ),
      array(
        'function () {document.querySelector("h1").textContent = "Hello world";}()',
      ),
      array(
        'function () {document.querySelector("h1").textContent = "Hello world";}();',
      ),
      array(
        '(function () {document.querySelector("h1").textContent = "Hello world";})()',
      ),
      array(
        '(function () {document.querySelector("h1").textContent = "Hello world";})();',
      ),
    );
  }

  /**
   * @dataProvider provideEvaluatedScript
   */
  public function testEvaluateJavascript($script) {
    $this
      ->getSession()
      ->visit($this
      ->pathTo('/index.html'));
    $this
      ->assertSame(2, $this
      ->getSession()
      ->evaluateScript($script));
  }
  public function provideEvaluatedScript() {
    return array(
      array(
        '1 + 1',
      ),
      array(
        '1 + 1;',
      ),
      array(
        'return 1 + 1',
      ),
      array(
        'return 1 + 1;',
      ),
      array(
        'function () {return 1+1;}()',
      ),
      array(
        '(function () {return 1+1;})()',
      ),
      array(
        'return function () { return 1+1;}()',
      ),
      array(
        'return (function () {return 1+1;})()',
      ),
    );
  }

}

Members

Namesort descending Modifiers Type Description Overrides
JavascriptEvaluationTest::provideEvaluatedScript public function
JavascriptEvaluationTest::provideExecutedScript public function
JavascriptEvaluationTest::testEvaluateJavascript public function @dataProvider provideEvaluatedScript
JavascriptEvaluationTest::testExecuteScript public function @dataProvider provideExecutedScript
JavascriptEvaluationTest::testWait public function
JavascriptEvaluationTest::testWaitReturnValue public function Tests, that `wait` method returns check result after exit.
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