function TestController::page

Same name in this branch
  1. 11.x core/modules/system/tests/modules/jswebassert_test/src/Controller/TestController.php \Drupal\jswebassert_test\Controller\TestController::page()
Same name in other branches
  1. 9 core/modules/system/tests/modules/js_webassert_test/src/Controller/TestController.php \Drupal\js_webassert_test\Controller\TestController::page()
  2. 10 core/modules/system/tests/modules/js_webassert_test/src/Controller/TestController.php \Drupal\js_webassert_test\Controller\TestController::page()
1 string reference to 'TestController::page'
js_webassert_test.routing.yml in core/modules/system/tests/modules/js_webassert_test/js_webassert_test.routing.yml
core/modules/system/tests/modules/js_webassert_test/js_webassert_test.routing.yml

File

core/modules/system/tests/modules/js_webassert_test/src/Controller/TestController.php, line 9

Class

TestController

Namespace

Drupal\js_webassert_test\Controller

Code

public function page() {
    $markup = <<<JS
<script>
var timesRun = 0;
var interval = setInterval(function() {
  timesRun += 1;
  // Clear the interval after 1.1 seconds as this is shorter than the 10 seconds
  // JSWebAssert::waitForElementVisible() waits for.
  if (timesRun === 1100) {
    clearInterval(interval);
  }
  var p = document.createElement("p");
  var txt = document.createTextNode("New Text!! ".concat(timesRun));
  p.setAttribute("id", "test_text");
  p.appendChild(txt);

  var div = document.getElementById("test_container");
  div.replaceChild(p, div.childNodes[0]);
}, 1);
</script>
<div id="test_container">
  <p id="test_text"></p>
</div>
JS;
    return [
        // Javascript should not be injected into a page this way unless in test
        // code.
'#markup' => Markup::create($markup),
    ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.