Update to Drupal 8.2.0. For more information, see https://www.drupal.org/project/drupal/releases/8.2.0
This commit is contained in:
parent
2f563ab520
commit
f1c8716f57
1732 changed files with 52334 additions and 11780 deletions
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Drupal\FunctionalTests;
|
||||
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\Component\Utility\Xss;
|
||||
use Drupal\KernelTests\AssertLegacyTrait as BaseAssertLegacyTrait;
|
||||
|
||||
/**
|
||||
|
@ -53,10 +55,17 @@ trait AssertLegacyTrait {
|
|||
* Plain text to look for.
|
||||
*
|
||||
* @deprecated Scheduled for removal in Drupal 9.0.0.
|
||||
* Use $this->assertSession()->pageTextContains() or
|
||||
* $this->assertSession()->responseContains() instead.
|
||||
* Use instead:
|
||||
* - $this->assertSession()->responseContains() for non-HTML responses,
|
||||
* like XML or Json.
|
||||
* - $this->assertSession()->pageTextContains() for HTML responses. Unlike
|
||||
* the deprecated assertText(), the passed text should be HTML decoded,
|
||||
* exactly as a human sees it in the browser.
|
||||
*/
|
||||
protected function assertText($text) {
|
||||
// Cast MarkupInterface to string.
|
||||
$text = (string) $text;
|
||||
|
||||
$content_type = $this->getSession()->getResponseHeader('Content-type');
|
||||
// In case of a Non-HTML response (example: XML) check the original
|
||||
// response.
|
||||
|
@ -64,7 +73,7 @@ trait AssertLegacyTrait {
|
|||
$this->assertSession()->responseContains($text);
|
||||
}
|
||||
else {
|
||||
$this->assertSession()->pageTextContains($text);
|
||||
$this->assertTextHelper($text, FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,10 +87,17 @@ trait AssertLegacyTrait {
|
|||
* Plain text to look for.
|
||||
*
|
||||
* @deprecated Scheduled for removal in Drupal 9.0.0.
|
||||
* Use $this->assertSession()->pageTextNotContains() or
|
||||
* $this->assertSession()->responseNotContains() instead.
|
||||
* Use instead:
|
||||
* - $this->assertSession()->responseNotContains() for non-HTML responses,
|
||||
* like XML or Json.
|
||||
* - $this->assertSession()->pageTextNotContains() for HTML responses.
|
||||
* Unlike the deprecated assertNoText(), the passed text should be HTML
|
||||
* decoded, exactly as a human sees it in the browser.
|
||||
*/
|
||||
protected function assertNoText($text) {
|
||||
// Cast MarkupInterface to string.
|
||||
$text = (string) $text;
|
||||
|
||||
$content_type = $this->getSession()->getResponseHeader('Content-type');
|
||||
// In case of a Non-HTML response (example: XML) check the original
|
||||
// response.
|
||||
|
@ -89,10 +105,40 @@ trait AssertLegacyTrait {
|
|||
$this->assertSession()->responseNotContains($text);
|
||||
}
|
||||
else {
|
||||
$this->assertSession()->pageTextNotContains($text);
|
||||
$this->assertTextHelper($text);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper for assertText and assertNoText.
|
||||
*
|
||||
* @param string $text
|
||||
* Plain text to look for.
|
||||
* @param bool $not_exists
|
||||
* (optional) TRUE if this text should not exist, FALSE if it should.
|
||||
* Defaults to TRUE.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE on pass, FALSE on fail.
|
||||
*/
|
||||
protected function assertTextHelper($text, $not_exists = TRUE) {
|
||||
$args = ['@text' => $text];
|
||||
$message = $not_exists ? new FormattableMarkup('"@text" not found', $args) : new FormattableMarkup('"@text" found', $args);
|
||||
|
||||
$raw_content = $this->getSession()->getPage()->getContent();
|
||||
// Trying to simulate what the user sees, given that it removes all text
|
||||
// inside the head tags, removes inline Javascript, fix all HTML entities,
|
||||
// removes dangerous protocols and filtering out all HTML tags, as they are
|
||||
// not visible in a normal browser.
|
||||
$raw_content = preg_replace('@<head>(.+?)</head>@si', '', $raw_content);
|
||||
$page_text = Xss::filter($raw_content, []);
|
||||
|
||||
$actual = $not_exists == (strpos($page_text, (string) $text) === FALSE);
|
||||
$this->assertTrue($actual, $message);
|
||||
|
||||
return $actual;
|
||||
}
|
||||
|
||||
/**
|
||||
* Passes if the text is found ONLY ONCE on the text version of the page.
|
||||
*
|
||||
|
|
116
core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php
Normal file
116
core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php
Normal file
|
@ -0,0 +1,116 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\FunctionalTests;
|
||||
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests BrowserTestBase functionality.
|
||||
*
|
||||
* @group browsertestbase
|
||||
*/
|
||||
class BrowserTestBaseTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('test_page_test', 'form_test', 'system_test');
|
||||
|
||||
/**
|
||||
* Tests basic page test.
|
||||
*/
|
||||
public function testGoTo() {
|
||||
$account = $this->drupalCreateUser();
|
||||
$this->drupalLogin($account);
|
||||
|
||||
// Visit a Drupal page that requires login.
|
||||
$this->drupalGet('test-page');
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
|
||||
// Test page contains some text.
|
||||
$this->assertSession()->pageTextContains('Test page text.');
|
||||
|
||||
// Check that returned plain text is correct.
|
||||
$text = $this->getTextContent();
|
||||
$this->assertContains('Test page text.', $text);
|
||||
$this->assertNotContains('</html>', $text);
|
||||
|
||||
// Response includes cache tags that we can assert.
|
||||
$this->assertSession()->responseHeaderEquals('X-Drupal-Cache-Tags', 'rendered');
|
||||
|
||||
// Test that we can read the JS settings.
|
||||
$js_settings = $this->getDrupalSettings();
|
||||
$this->assertSame('azAZ09();.,\\\/-_{}', $js_settings['test-setting']);
|
||||
|
||||
// Test drupalGet with a url object.
|
||||
$url = Url::fromRoute('test_page_test.render_title');
|
||||
$this->drupalGet($url);
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
|
||||
// Test page contains some text.
|
||||
$this->assertSession()->pageTextContains('Hello Drupal');
|
||||
|
||||
// Test that setting headers with drupalGet() works.
|
||||
$this->drupalGet('system-test/header', array(), array(
|
||||
'Test-Header' => 'header value',
|
||||
));
|
||||
$returned_header = $this->getSession()->getResponseHeader('Test-Header');
|
||||
$this->assertSame('header value', $returned_header);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests basic form functionality.
|
||||
*/
|
||||
public function testForm() {
|
||||
// Ensure the proper response code for a _form route.
|
||||
$this->drupalGet('form-test/object-builder');
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
|
||||
// Ensure the form and text field exist.
|
||||
$this->assertSession()->elementExists('css', 'form#form-test-form-test-object');
|
||||
$this->assertSession()->fieldExists('bananas');
|
||||
|
||||
$edit = ['bananas' => 'green'];
|
||||
$this->submitForm($edit, 'Save', 'form-test-form-test-object');
|
||||
|
||||
$config_factory = $this->container->get('config.factory');
|
||||
$value = $config_factory->get('form_test.object')->get('bananas');
|
||||
$this->assertSame('green', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests clickLink() functionality.
|
||||
*/
|
||||
public function testClickLink() {
|
||||
$this->drupalGet('test-page');
|
||||
$this->clickLink('Visually identical test links');
|
||||
$this->assertContains('user/login', $this->getSession()->getCurrentUrl());
|
||||
$this->drupalGet('test-page');
|
||||
$this->clickLink('Visually identical test links', 0);
|
||||
$this->assertContains('user/login', $this->getSession()->getCurrentUrl());
|
||||
$this->drupalGet('test-page');
|
||||
$this->clickLink('Visually identical test links', 1);
|
||||
$this->assertContains('user/register', $this->getSession()->getCurrentUrl());
|
||||
}
|
||||
|
||||
public function testError() {
|
||||
$this->setExpectedException('\Exception', 'User notice: foo');
|
||||
$this->drupalGet('test-error');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests legacy asserts.
|
||||
*/
|
||||
public function testLegacyAsserts() {
|
||||
$this->drupalGet('test-encoded');
|
||||
$dangerous = 'Bad html <script>alert(123);</script>';
|
||||
$sanitized = Html::escape($dangerous);
|
||||
$this->assertNoText($dangerous);
|
||||
$this->assertText($sanitized);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\FunctionalTests\Core\Config;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
use Drupal\Tests\Traits\Core\Config\SchemaConfigListenerTestTrait;
|
||||
|
||||
/**
|
||||
* Tests the functionality of ConfigSchemaChecker in KernelTestBase tests.
|
||||
*
|
||||
* @group config
|
||||
*/
|
||||
class SchemaConfigListenerTest extends BrowserTestBase {
|
||||
|
||||
use SchemaConfigListenerTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = array('config_test');
|
||||
|
||||
}
|
Reference in a new issue