summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLee Rowlands2017-08-25 06:58:39 (GMT)
committerLee Rowlands2017-08-25 06:58:39 (GMT)
commit6496b03d5418e2e3bddeff9e4d36a0b01a265071 (patch)
treebb3f1e38773ed5e016ec3d735132e59540f6ce39
parent401bd662cb145b01374fc3b84c8ccc6854c6ebc1 (diff)
Issue #2827014 by michielnugter, Lendude, marcoscano, dawehner, cilefen, larowlan, xjm, droplet, alexpott, Wim Leers: Throw an exception when testing status code or response headers in functional JavaScript tests
-rw-r--r--core/modules/media/tests/src/FunctionalJavascript/MediaSourceTestBase.php1
-rw-r--r--core/modules/media/tests/src/FunctionalJavascript/MediaUiJavascriptTest.php5
-rw-r--r--core/tests/Drupal/FunctionalJavascriptTests/Core/Session/SessionTest.php3
-rw-r--r--core/tests/Drupal/FunctionalJavascriptTests/JavascriptTestBase.php4
-rw-r--r--core/tests/Drupal/FunctionalJavascriptTests/LegacyJavascriptTestBase.php20
-rw-r--r--core/tests/Drupal/FunctionalJavascriptTests/WebDriverWebAssert.php58
-rw-r--r--core/tests/Drupal/Tests/BrowserTestBase.php2
7 files changed, 81 insertions, 12 deletions
diff --git a/core/modules/media/tests/src/FunctionalJavascript/MediaSourceTestBase.php b/core/modules/media/tests/src/FunctionalJavascript/MediaSourceTestBase.php
index c6ea4ec..ce0f185 100644
--- a/core/modules/media/tests/src/FunctionalJavascript/MediaSourceTestBase.php
+++ b/core/modules/media/tests/src/FunctionalJavascript/MediaSourceTestBase.php
@@ -123,7 +123,6 @@ abstract class MediaSourceTestBase extends MediaJavascriptTestBase {
// Save the form to create the type.
$page->pressButton('Save');
- $assert_session->statusCodeEquals(200);
$assert_session->pageTextContains('The media type ' . $media_type_id . ' has been added.');
$this->drupalGet('admin/structure/media');
$assert_session->pageTextContains($media_type_id);
diff --git a/core/modules/media/tests/src/FunctionalJavascript/MediaUiJavascriptTest.php b/core/modules/media/tests/src/FunctionalJavascript/MediaUiJavascriptTest.php
index 38a6227..981da61 100644
--- a/core/modules/media/tests/src/FunctionalJavascript/MediaUiJavascriptTest.php
+++ b/core/modules/media/tests/src/FunctionalJavascript/MediaUiJavascriptTest.php
@@ -54,7 +54,6 @@ class MediaUiJavascriptTest extends MediaJavascriptTestBase {
$assert_session = $this->assertSession();
$this->drupalGet('admin/structure/media');
- $assert_session->statusCodeEquals(200);
$assert_session->pageTextContains('No media types available. Add media type.');
$assert_session->linkExists('Add media type');
@@ -69,10 +68,8 @@ class MediaUiJavascriptTest extends MediaJavascriptTestBase {
$this->assertJsCondition("jQuery('.form-item-source-configuration-test-config-value').length > 0;");
$page->fillField('description', $description);
$page->pressButton('Save');
- $assert_session->statusCodeEquals(200);
$assert_session->pageTextContains('The media type ' . $name . ' has been added.');
$this->drupalGet('admin/structure/media');
- $assert_session->statusCodeEquals(200);
$assert_session->pageTextContains($name);
$assert_session->pageTextContains($description);
@@ -142,7 +139,7 @@ class MediaUiJavascriptTest extends MediaJavascriptTestBase {
$page->uncheckField('options[status]');
$page->checkField('options[queue_thumbnail_downloads]');
$page->pressButton('Save');
- $assert_session->statusCodeEquals(200);
+ $assert_session->pageTextContains("The media type $new_name has been updated.");
// Test if edit worked and if new field values have been saved as expected.
$this->drupalGet('admin/structure/media/manage/' . $this->testMediaType->id());
diff --git a/core/tests/Drupal/FunctionalJavascriptTests/Core/Session/SessionTest.php b/core/tests/Drupal/FunctionalJavascriptTests/Core/Session/SessionTest.php
index e02e0df..fa2d541 100644
--- a/core/tests/Drupal/FunctionalJavascriptTests/Core/Session/SessionTest.php
+++ b/core/tests/Drupal/FunctionalJavascriptTests/Core/Session/SessionTest.php
@@ -48,13 +48,10 @@ class SessionTest extends JavascriptTestBase {
// number of times.
$this->drupalGet('<front>');
- $session_assert = $this->assertSession();
-
$page = $this->getSession()->getPage();
for ($i = 0; $i < 25; $i++) {
$page->clickLink('Link to front page');
- $session_assert->statusCodeEquals(200);
}
}
diff --git a/core/tests/Drupal/FunctionalJavascriptTests/JavascriptTestBase.php b/core/tests/Drupal/FunctionalJavascriptTests/JavascriptTestBase.php
index d5156ee..8aa46c7 100644
--- a/core/tests/Drupal/FunctionalJavascriptTests/JavascriptTestBase.php
+++ b/core/tests/Drupal/FunctionalJavascriptTests/JavascriptTestBase.php
@@ -7,7 +7,7 @@ use Zumba\GastonJS\Exception\DeadClient;
use Zumba\Mink\Driver\PhantomJSDriver;
/**
- * Runs a browser test using PhantomJS.
+ * Runs a browser test using a driver that supports Javascript.
*
* Base class for testing browser interaction implemented in JavaScript.
*/
@@ -142,7 +142,7 @@ abstract class JavascriptTestBase extends BrowserTestBase {
* {@inheritdoc}
*/
public function assertSession($name = NULL) {
- return new JSWebAssert($this->getSession($name), $this->baseUrl);
+ return new WebDriverWebAssert($this->getSession($name), $this->baseUrl);
}
/**
diff --git a/core/tests/Drupal/FunctionalJavascriptTests/LegacyJavascriptTestBase.php b/core/tests/Drupal/FunctionalJavascriptTests/LegacyJavascriptTestBase.php
new file mode 100644
index 0000000..7cef5b8
--- /dev/null
+++ b/core/tests/Drupal/FunctionalJavascriptTests/LegacyJavascriptTestBase.php
@@ -0,0 +1,20 @@
+<?php
+
+namespace Drupal\FunctionalJavascriptTests;
+
+/**
+ * Runs a browser test using PhantomJS.
+ *
+ * Base class for testing browser interaction implemented in JavaScript.
+ */
+abstract class LegacyJavascriptTestBase extends JavascriptTestBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ public function assertSession($name = NULL) {
+ // Return a WebAssert that supports status code and header assertions.
+ return new JSWebAssert($this->getSession($name), $this->baseUrl);
+ }
+
+}
diff --git a/core/tests/Drupal/FunctionalJavascriptTests/WebDriverWebAssert.php b/core/tests/Drupal/FunctionalJavascriptTests/WebDriverWebAssert.php
new file mode 100644
index 0000000..16b1281
--- /dev/null
+++ b/core/tests/Drupal/FunctionalJavascriptTests/WebDriverWebAssert.php
@@ -0,0 +1,58 @@
+<?php
+
+namespace Drupal\FunctionalJavascriptTests;
+
+/**
+ * Defines a JSWebAssert with no support for status code and header assertions.
+ */
+class WebDriverWebAssert extends JSWebAssert {
+
+ /**
+ * The use of statusCodeEquals() is not available.
+ *
+ * @param int $code
+ * The status code.
+ */
+ public function statusCodeEquals($code) {
+ @trigger_error('Support for statusCodeEquals is to be dropped from Javascript tests. See https://www.drupal.org/node/2857562.');
+ parent::statusCodeEquals($code);
+ }
+
+ /**
+ * The use of statusCodeNotEquals() is not available.
+ *
+ * @param int $code
+ * The status code.
+ */
+ public function statusCodeNotEquals($code) {
+ @trigger_error('Support for statusCodeNotEquals is to be dropped from Javascript tests. See https://www.drupal.org/node/2857562.');
+ parent::statusCodeNotEquals($code);
+ }
+
+ /**
+ * The use of responseHeaderEquals() is not available.
+ *
+ * @param string $name
+ * The name of the header.
+ * @param string $value
+ * The value to check the header against.
+ */
+ public function responseHeaderEquals($name, $value) {
+ @trigger_error('Support for responseHeaderEquals is to be dropped from Javascript tests. See https://www.drupal.org/node/2857562.');
+ parent::responseHeaderEquals($name, $value);
+ }
+
+ /**
+ * The use of responseHeaderNotEquals() is not available.
+ *
+ * @param string $name
+ * The name of the header.
+ * @param string $value
+ * The value to check the header against.
+ */
+ public function responseHeaderNotEquals($name, $value) {
+ @trigger_error('Support for responseHeaderNotEquals is to be dropped from Javascript tests. See https://www.drupal.org/node/2857562.');
+ parent::responseHeaderNotEquals($name, $value);
+ }
+
+}
diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php
index bd50c23..8ad783a 100644
--- a/core/tests/Drupal/Tests/BrowserTestBase.php
+++ b/core/tests/Drupal/Tests/BrowserTestBase.php
@@ -736,7 +736,6 @@ abstract class BrowserTestBase extends TestCase {
}
$this->drupalGet('user/login');
- $this->assertSession()->statusCodeEquals(200);
$this->submitForm([
'name' => $account->getUsername(),
'pass' => $account->passRaw,
@@ -761,7 +760,6 @@ abstract class BrowserTestBase extends TestCase {
// screen.
$assert_session = $this->assertSession();
$this->drupalGet('user/logout', ['query' => ['destination' => 'user']]);
- $assert_session->statusCodeEquals(200);
$assert_session->fieldExists('name');
$assert_session->fieldExists('pass');