diff --git a/core/modules/simpletest/src/BrowserTestBase.php b/core/modules/simpletest/src/BrowserTestBase.php index 0fe90f1..e917829 100644 --- a/core/modules/simpletest/src/BrowserTestBase.php +++ b/core/modules/simpletest/src/BrowserTestBase.php @@ -248,10 +248,14 @@ protected function initMink() { $this->mink->setDefaultSessionName('default'); $this->registerSessions(); - // Fire up the first request to the front page in order to be able to set - // a cookie later. - // @fixme This is done to circumvent: - // WebDriver\Exception\UnableToSetCookie: {"errorMessage":"Unable to set Cookie: no URL has been loaded yet","request":{"headers":{"Accept":"application/json;charset=UTF-8","Content-Length":"164","Content-Type":"application/json;charset=UTF-8","Host":"127.0.0.1:8910"},"httpVersion":"1.1","method":"POST","post":"{\"cookie\":{\"name\":\"SIMPLETEST_USER_AGENT\",\"value\":\"simpletest472558;1441488302;55eb5dae78eeb7.36607058;IxhRvB7dhbDAMurfBshqgUwEOpAPPKybnJMv0JgaG8Q\",\"secure\":false}}","url":"/cookie","urlParsed":{"anchor":"","query":"","file":"cookie","directory":"/","path":"/cookie","relative":"/cookie","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/cookie","queryKey":{},"chunks":["cookie"]},"urlOriginal":"/session/91aef6b0-5414-11e5-9028-67c7fcbbdc3b/cookie"}} + // According to the W3C WebDriver specification a cookie can only be set if + // the cookie domain is equal to the domain of the active document. When the + // browser starts up the active document is not our domain but 'about:blank' + // or similar. To be able to set our User-Agent and Xdebug cookies at the + // start of the test we now do a request to the front page so the active + // document matches the domain. + // @see https://w3c.github.io/webdriver/webdriver-spec.html#add-cookie + // @see https://www.w3.org/Bugs/Public/show_bug.cgi?id=20975 $session = $this->getSession(); $session->visit($this->baseUrl); diff --git a/core/modules/simpletest/tests/src/FunctionalJavascript/BrowserWithJavascriptTest.php b/core/modules/simpletest/tests/src/FunctionalJavascript/BrowserWithJavascriptTest.php index 81d8425..188cd7e 100644 --- a/core/modules/simpletest/tests/src/FunctionalJavascript/BrowserWithJavascriptTest.php +++ b/core/modules/simpletest/tests/src/FunctionalJavascript/BrowserWithJavascriptTest.php @@ -5,7 +5,7 @@ use Drupal\FunctionalJavascriptTests\JavascriptTestBase; /** - * Tests a browser with javascript. + * Tests if we can execute JavaScript in the browser. * * @group javascript */ @@ -16,7 +16,6 @@ public function testJavascript() { $session = $this->getSession(); $session->resizeWindow(400, 300); - $session->wait(1000, 'false'); $javascript = <<evaluateScript($javascript); - $this->assertEquals(400, $pageSize["width"]); - $this->assertEquals(300, $pageSize["height"]); + $result = $session->wait(1000, $javascript); + $this->assertTrue($result); } } diff --git a/core/modules/toolbar/tests/src/FunctionalJavascript/ToolbarIntegrationTest.php b/core/modules/toolbar/tests/src/FunctionalJavascript/ToolbarIntegrationTest.php index 8428643..c22443c 100644 --- a/core/modules/toolbar/tests/src/FunctionalJavascript/ToolbarIntegrationTest.php +++ b/core/modules/toolbar/tests/src/FunctionalJavascript/ToolbarIntegrationTest.php @@ -5,7 +5,7 @@ use Drupal\FunctionalJavascriptTests\JavascriptTestBase; /** - * Basic toolbar testing. + * Tests the JavaScript functionality of the toolbar. * * @group toolbar */ @@ -16,6 +16,9 @@ class ToolbarIntegrationTest extends JavascriptTestBase { */ public static $modules = ['toolbar', 'node']; + /** + * Tests if the toolbar can be toggled with JavaScript. + */ public function testToolbarToggling() { $admin_user = $this->drupalCreateUser([ 'access toolbar', diff --git a/core/tests/Drupal/FunctionalJavascriptTests/JavascriptTestBase.php b/core/tests/Drupal/FunctionalJavascriptTests/JavascriptTestBase.php index e95fa49..00daa43 100644 --- a/core/tests/Drupal/FunctionalJavascriptTests/JavascriptTestBase.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/JavascriptTestBase.php @@ -3,14 +3,12 @@ namespace Drupal\FunctionalJavascriptTests; use Drupal\simpletest\BrowserTestBase; -use GuzzleHttp\Exception\ConnectException; use Zumba\Mink\Driver\PhantomJSDriver; /** - * Runs a browser test using phantomJS. + * Runs a browser test using PhantomJS. * - * Use this test baseclass if you want to test expected behaviour of some - * JavaScript. + * Base class for testing browser interaction implemented in JavaScript. */ abstract class JavascriptTestBase extends BrowserTestBase { @@ -23,7 +21,7 @@ * {@inheritdoc} */ protected function initMink() { - // Setup some template cache using by the phantomjs mink driver. + // Set up the template cache used by the PhantomJS mink driver. $path = $this->tempFilesDirectory . DIRECTORY_SEPARATOR . 'browsertestbase-templatecache'; $this->minkDefaultDriverArgs = [ 'http://127.0.0.1:8510', diff --git a/core/tests/README.md b/core/tests/README.md index df091f3..dfd1154 100644 --- a/core/tests/README.md +++ b/core/tests/README.md @@ -1,14 +1,15 @@ # Running tests -## Function tests +## Functional tests -* Start phantomjs: -``` -phantomjs --ssl-protocol=any --ignore-ssl-errors=true vendor/jcalderonzumba/gastonjs/src/Client/main.js 8510 1024 768 2>&1 >> /dev/null & -``` -* Run the function tests: -``` -export SIMPLETEST_DB='mysql://root@localhost/dev_d8' -export SIMPLETEST_BASE_URL='http://d8.dev' -vendor/bin/phpunit -c core core/modules/simpletest/tests/src/Functional/BrowserTestBaseTest.php -``` +* Start PhantomJS: + ``` + phantomjs --ssl-protocol=any --ignore-ssl-errors=true ./vendor/jcalderonzumba/gastonjs/src/Client/main.js 8510 1024 768 2>&1 >> /dev/null & + ``` +* Run the functional tests: + ``` + export SIMPLETEST_DB='mysql://root@localhost/dev_d8' + export SIMPLETEST_BASE_URL='http://d8.dev' + ./vendor/bin/phpunit -c core --testsuite functional + ./vendor/bin/phpunit -c core --testsuite functional-javascript + ```