Update core 8.3.0
This commit is contained in:
parent
da7a7918f8
commit
cd7a898e66
6144 changed files with 132297 additions and 87747 deletions
|
@ -2,6 +2,9 @@
|
|||
|
||||
namespace Drupal\FunctionalTests;
|
||||
|
||||
use Behat\Mink\Exception\ElementNotFoundException;
|
||||
use Behat\Mink\Exception\ExpectationException;
|
||||
use Behat\Mink\Selector\Xpath\Escaper;
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\Component\Utility\Xss;
|
||||
use Drupal\KernelTests\AssertLegacyTrait as BaseAssertLegacyTrait;
|
||||
|
@ -227,24 +230,27 @@ trait AssertLegacyTrait {
|
|||
}
|
||||
|
||||
/**
|
||||
* Asserts that a field exists with the given name and value.
|
||||
* Asserts that a field does not exist with the given name and value.
|
||||
*
|
||||
* @param string $name
|
||||
* Name of field to assert.
|
||||
* @param string $value
|
||||
* (optional) Value of the field to assert. You may pass in NULL (default)
|
||||
* to skip checking the actual value, while still checking that the field
|
||||
* exists.
|
||||
* (optional) Value for the field, to assert that the field's value on the
|
||||
* page does not match it. You may pass in NULL to skip checking the
|
||||
* value, while still checking that the field does not exist. However, the
|
||||
* default value ('') asserts that the field value is not an empty string.
|
||||
*
|
||||
* @deprecated Scheduled for removal in Drupal 9.0.0.
|
||||
* Use $this->assertSession()->fieldNotExists() or
|
||||
* $this->assertSession()->fieldValueNotEquals() instead.
|
||||
*/
|
||||
protected function assertNoFieldByName($name, $value = NULL) {
|
||||
$this->assertSession()->fieldNotExists($name);
|
||||
if ($value !== NULL) {
|
||||
protected function assertNoFieldByName($name, $value = '') {
|
||||
if ($this->getSession()->getPage()->findField($name) && isset($value)) {
|
||||
$this->assertSession()->fieldValueNotEquals($name, (string) $value);
|
||||
}
|
||||
else {
|
||||
$this->assertSession()->fieldNotExists($name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -258,12 +264,23 @@ trait AssertLegacyTrait {
|
|||
* However, the default value ('') asserts that the field value is an empty
|
||||
* string.
|
||||
*
|
||||
* @throws \Behat\Mink\Exception\ElementNotFoundException
|
||||
*
|
||||
* @deprecated Scheduled for removal in Drupal 9.0.0.
|
||||
* Use $this->assertSession()->fieldExists() or
|
||||
* $this->assertSession()->fieldValueEquals() instead.
|
||||
*/
|
||||
protected function assertFieldById($id, $value = NULL) {
|
||||
$this->assertFieldByName($id, $value);
|
||||
protected function assertFieldById($id, $value = '') {
|
||||
$xpath = $this->assertSession()->buildXPathQuery('//textarea[@id=:value]|//input[@id=:value]|//select[@id=:value]', [':value' => $id]);
|
||||
$field = $this->getSession()->getPage()->find('xpath', $xpath);
|
||||
|
||||
if (empty($field)) {
|
||||
throw new ElementNotFoundException($this->getSession()->getDriver(), 'form field', 'id', $field);
|
||||
}
|
||||
|
||||
if ($value !== NULL) {
|
||||
$this->assertEquals($value, $field->getValue());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -376,7 +393,7 @@ trait AssertLegacyTrait {
|
|||
* Link position counting from zero.
|
||||
*
|
||||
* @deprecated Scheduled for removal in Drupal 9.0.0.
|
||||
* Use $this->assertSession()->linkByHref() instead.
|
||||
* Use $this->assertSession()->linkByHrefExists() instead.
|
||||
*/
|
||||
protected function assertLinkByHref($href, $index = 0) {
|
||||
$this->assertSession()->linkByHrefExists($href, $index);
|
||||
|
@ -406,16 +423,26 @@ trait AssertLegacyTrait {
|
|||
* while still checking that the field doesn't exist. However, the default
|
||||
* value ('') asserts that the field value is not an empty string.
|
||||
*
|
||||
* @throws \Behat\Mink\Exception\ExpectationException
|
||||
*
|
||||
* @deprecated Scheduled for removal in Drupal 9.0.0.
|
||||
* Use $this->assertSession()->fieldNotExists() or
|
||||
* $this->assertSession()->fieldValueNotEquals() instead.
|
||||
*/
|
||||
protected function assertNoFieldById($id, $value = '') {
|
||||
if ($this->getSession()->getPage()->findField($id)) {
|
||||
$this->assertSession()->fieldValueNotEquals($id, (string) $value);
|
||||
$xpath = $this->assertSession()->buildXPathQuery('//textarea[@id=:value]|//input[@id=:value]|//select[@id=:value]', [':value' => $id]);
|
||||
$field = $this->getSession()->getPage()->find('xpath', $xpath);
|
||||
|
||||
// Return early if the field could not be found as expected.
|
||||
if ($field === NULL) {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
$this->assertSession()->fieldNotExists($id);
|
||||
|
||||
if (!isset($value)) {
|
||||
throw new ExpectationException(sprintf('Id "%s" appears on this page, but it should not.', $id), $this->getSession()->getDriver());
|
||||
}
|
||||
elseif ($value === $field->getValue()) {
|
||||
throw new ExpectationException(sprintf('Failed asserting that %s is not equal to %s', $field->getValue(), $value), $this->getSession()->getDriver());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -447,6 +474,21 @@ trait AssertLegacyTrait {
|
|||
return $this->assertSession()->optionExists($id, $option);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a select option with the visible text exists.
|
||||
*
|
||||
* @param string $id
|
||||
* The ID of the select field to assert.
|
||||
* @param string $text
|
||||
* The text for the option tag to assert.
|
||||
*
|
||||
* @deprecated Scheduled for removal in Drupal 9.0.0.
|
||||
* Use $this->assertSession()->optionExists() instead.
|
||||
*/
|
||||
protected function assertOptionByText($id, $text) {
|
||||
return $this->assertSession()->optionExists($id, $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a select option does NOT exist in the current page.
|
||||
*
|
||||
|
@ -509,6 +551,102 @@ trait AssertLegacyTrait {
|
|||
$this->assertSession()->checkboxNotChecked($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a field exists in the current page by the given XPath.
|
||||
*
|
||||
* @param string $xpath
|
||||
* XPath used to find the field.
|
||||
* @param string $value
|
||||
* (optional) Value of the field to assert. You may pass in NULL (default)
|
||||
* to skip checking the actual value, while still checking that the field
|
||||
* exists.
|
||||
* @param string $message
|
||||
* (optional) A message to display with the assertion. Do not translate
|
||||
* messages with t().
|
||||
*
|
||||
* @deprecated Scheduled for removal in Drupal 9.0.0.
|
||||
* Use $this->xpath() instead and check the values directly in the test.
|
||||
*/
|
||||
protected function assertFieldByXPath($xpath, $value = NULL, $message = '') {
|
||||
$fields = $this->xpath($xpath);
|
||||
|
||||
$this->assertFieldsByValue($fields, $value, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a field does not exist or its value does not match, by XPath.
|
||||
*
|
||||
* @param string $xpath
|
||||
* XPath used to find the field.
|
||||
* @param string $value
|
||||
* (optional) Value of the field, to assert that the field's value on the
|
||||
* page does not match it.
|
||||
* @param string $message
|
||||
* (optional) A message to display with the assertion. Do not translate
|
||||
* messages with t().
|
||||
*
|
||||
* @deprecated Scheduled for removal in Drupal 9.0.0.
|
||||
* Use $this->xpath() instead and assert that the result is empty.
|
||||
*/
|
||||
protected function assertNoFieldByXPath($xpath, $value = NULL, $message = '') {
|
||||
$fields = $this->xpath($xpath);
|
||||
|
||||
// If value specified then check array for match.
|
||||
$found = TRUE;
|
||||
if (isset($value)) {
|
||||
$found = FALSE;
|
||||
if ($fields) {
|
||||
foreach ($fields as $field) {
|
||||
if ($field->getAttribute('value') == $value) {
|
||||
$found = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->assertFalse($fields && $found, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a field exists in the current page with a given Xpath result.
|
||||
*
|
||||
* @param \Behat\Mink\Element\NodeElement[] $fields
|
||||
* Xml elements.
|
||||
* @param string $value
|
||||
* (optional) Value of the field to assert. You may pass in NULL (default) to skip
|
||||
* checking the actual value, while still checking that the field exists.
|
||||
* @param string $message
|
||||
* (optional) A message to display with the assertion. Do not translate
|
||||
* messages with t().
|
||||
*
|
||||
* @deprecated Scheduled for removal in Drupal 9.0.0.
|
||||
* Iterate over the fields yourself instead and directly check the values in
|
||||
* the test.
|
||||
*/
|
||||
protected function assertFieldsByValue($fields, $value = NULL, $message = '') {
|
||||
// If value specified then check array for match.
|
||||
$found = TRUE;
|
||||
if (isset($value)) {
|
||||
$found = FALSE;
|
||||
if ($fields) {
|
||||
foreach ($fields as $field) {
|
||||
if ($field->getAttribute('value') == $value) {
|
||||
// Input element with correct value.
|
||||
$found = TRUE;
|
||||
}
|
||||
elseif ($field->find('xpath', '//option[@value = ' . (new Escaper())->escapeLiteral($value) . ' and @selected = "selected"]')) {
|
||||
// Select element with an option.
|
||||
$found = TRUE;
|
||||
}
|
||||
elseif ($field->getText() == $value) {
|
||||
// Text area with correct text.
|
||||
$found = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->assertTrue($fields && $found, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Passes if the raw text IS found escaped on the loaded page, fail otherwise.
|
||||
*
|
||||
|
@ -552,6 +690,22 @@ trait AssertLegacyTrait {
|
|||
$this->assertSession()->responseMatches($pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggers a pass if the Perl regex pattern is not found in the raw content.
|
||||
*
|
||||
* @param string $pattern
|
||||
* Perl regex to look for including the regex delimiters.
|
||||
*
|
||||
* @deprecated Scheduled for removal in Drupal 9.0.0.
|
||||
* Use $this->assertSession()->responseNotMatches() instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2864262
|
||||
*/
|
||||
protected function assertNoPattern($pattern) {
|
||||
@trigger_error('assertNoPattern() is deprecated and scheduled for removal in Drupal 9.0.0. Use $this->assertSession()->responseNotMatches($pattern) instead. See https://www.drupal.org/node/2864262.', E_USER_DEPRECATED);
|
||||
$this->assertSession()->responseNotMatches($pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts whether an expected cache tag was present in the last response.
|
||||
*
|
||||
|
@ -565,6 +719,21 @@ trait AssertLegacyTrait {
|
|||
$this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', $expected_cache_tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that current response header equals value.
|
||||
*
|
||||
* @param string $name
|
||||
* Name of header to assert.
|
||||
* @param string $value
|
||||
* Value of the header to assert
|
||||
*
|
||||
* @deprecated Scheduled for removal in Drupal 9.0.0.
|
||||
* Use $this->assertSession()->responseHeaderEquals() instead.
|
||||
*/
|
||||
protected function assertHeader($name, $value) {
|
||||
$this->assertSession()->responseHeaderEquals($name, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns WebAssert object.
|
||||
*
|
||||
|
@ -599,8 +768,19 @@ trait AssertLegacyTrait {
|
|||
* @deprecated Scheduled for removal in Drupal 9.0.0.
|
||||
* Use $this->assertSession()->buildXPathQuery() instead.
|
||||
*/
|
||||
protected function buildXPathQuery($xpath, array $args = array()) {
|
||||
protected function buildXPathQuery($xpath, array $args = []) {
|
||||
return $this->assertSession()->buildXPathQuery($xpath, $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current raw content.
|
||||
*
|
||||
* @deprecated Scheduled for removal in Drupal 9.0.0.
|
||||
* Use $this->getSession()->getPage()->getContent() instead.
|
||||
*/
|
||||
protected function getRawContent() {
|
||||
@trigger_error('AssertLegacyTrait::getRawContent() is scheduled for removal in Drupal 9.0.0. Use $this->getSession()->getPage()->getContent() instead.', E_USER_DEPRECATED);
|
||||
return $this->getSession()->getPage()->getContent();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,9 +2,11 @@
|
|||
|
||||
namespace Drupal\FunctionalTests;
|
||||
|
||||
use Behat\Mink\Exception\ExpectationException;
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
use Drupal\Tests\Traits\Core\CronRunTrait;
|
||||
|
||||
/**
|
||||
* Tests BrowserTestBase functionality.
|
||||
|
@ -13,12 +15,14 @@ use Drupal\Tests\BrowserTestBase;
|
|||
*/
|
||||
class BrowserTestBaseTest extends BrowserTestBase {
|
||||
|
||||
use CronRunTrait;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('test_page_test', 'form_test', 'system_test');
|
||||
public static $modules = ['test_page_test', 'form_test', 'system_test'];
|
||||
|
||||
/**
|
||||
* Tests basic page test.
|
||||
|
@ -40,7 +44,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
|
|||
$this->assertNotContains('</html>', $text);
|
||||
|
||||
// Response includes cache tags that we can assert.
|
||||
$this->assertSession()->responseHeaderEquals('X-Drupal-Cache-Tags', 'rendered');
|
||||
$this->assertSession()->responseHeaderEquals('X-Drupal-Cache-Tags', 'http_response rendered');
|
||||
|
||||
// Test that we can read the JS settings.
|
||||
$js_settings = $this->getDrupalSettings();
|
||||
|
@ -55,9 +59,9 @@ class BrowserTestBaseTest extends BrowserTestBase {
|
|||
$this->assertSession()->pageTextContains('Hello Drupal');
|
||||
|
||||
// Test that setting headers with drupalGet() works.
|
||||
$this->drupalGet('system-test/header', array(), array(
|
||||
$this->drupalGet('system-test/header', [], [
|
||||
'Test-Header' => 'header value',
|
||||
));
|
||||
]);
|
||||
$returned_header = $this->getSession()->getResponseHeader('Test-Header');
|
||||
$this->assertSame('header value', $returned_header);
|
||||
}
|
||||
|
@ -74,12 +78,33 @@ class BrowserTestBaseTest extends BrowserTestBase {
|
|||
$this->assertSession()->elementExists('css', 'form#form-test-form-test-object');
|
||||
$this->assertSession()->fieldExists('bananas');
|
||||
|
||||
// Check that the hidden field exists and has a specific value.
|
||||
$this->assertSession()->hiddenFieldExists('strawberry');
|
||||
$this->assertSession()->hiddenFieldExists('red');
|
||||
$this->assertSession()->hiddenFieldExists('redstrawberryhiddenfield');
|
||||
$this->assertSession()->hiddenFieldValueNotEquals('strawberry', 'brown');
|
||||
$this->assertSession()->hiddenFieldValueEquals('strawberry', 'red');
|
||||
|
||||
// Check that a hidden field does not exist.
|
||||
$this->assertSession()->hiddenFieldNotExists('bananas');
|
||||
$this->assertSession()->hiddenFieldNotExists('pineapple');
|
||||
|
||||
$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);
|
||||
|
||||
// Test drupalPostForm().
|
||||
$edit = ['bananas' => 'red'];
|
||||
$this->drupalPostForm('form-test/object-builder', $edit, 'Save');
|
||||
$value = $config_factory->get('form_test.object')->get('bananas');
|
||||
$this->assertSame('red', $value);
|
||||
|
||||
$this->drupalPostForm('form-test/object-builder', NULL, 'Save');
|
||||
$value = $config_factory->get('form_test.object')->get('bananas');
|
||||
$this->assertSame('', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -103,14 +128,157 @@ class BrowserTestBaseTest extends BrowserTestBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Tests legacy asserts.
|
||||
* Tests linkExists() with pipe character (|) in locator.
|
||||
*
|
||||
* @see \Drupal\Tests\WebAssert::linkExists()
|
||||
*/
|
||||
public function testLegacyAsserts() {
|
||||
public function testPipeCharInLocator() {
|
||||
$this->drupalGet('test-pipe-char');
|
||||
$this->assertSession()->linkExists('foo|bar|baz');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests legacy text asserts.
|
||||
*/
|
||||
public function testLegacyTextAsserts() {
|
||||
$this->drupalGet('test-encoded');
|
||||
$dangerous = 'Bad html <script>alert(123);</script>';
|
||||
$sanitized = Html::escape($dangerous);
|
||||
$this->assertNoText($dangerous);
|
||||
$this->assertText($sanitized);
|
||||
|
||||
// Test getRawContent().
|
||||
$this->assertSame($this->getSession()->getPage()->getContent(), $this->getRawContent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests legacy field asserts.
|
||||
*/
|
||||
public function testLegacyFieldAsserts() {
|
||||
$this->drupalGet('test-field-xpath');
|
||||
$this->assertFieldsByValue($this->xpath("//h1[@class = 'page-title']"), NULL);
|
||||
$this->assertFieldsByValue($this->xpath('//table/tbody/tr[2]/td[1]'), 'one');
|
||||
$this->assertFieldByXPath('//table/tbody/tr[2]/td[1]', 'one');
|
||||
|
||||
$this->assertFieldsByValue($this->xpath("//input[@id = 'edit-name']"), 'Test name');
|
||||
$this->assertFieldByXPath("//input[@id = 'edit-name']", 'Test name');
|
||||
$this->assertFieldsByValue($this->xpath("//select[@id = 'edit-options']"), '2');
|
||||
$this->assertFieldByXPath("//select[@id = 'edit-options']", '2');
|
||||
|
||||
$this->assertNoFieldByXPath('//notexisting');
|
||||
$this->assertNoFieldByXPath("//input[@id = 'edit-name']", 'wrong value');
|
||||
|
||||
$this->assertNoFieldById('name');
|
||||
$this->assertNoFieldById('name', 'not the value');
|
||||
$this->assertNoFieldById('notexisting');
|
||||
$this->assertNoFieldById('notexisting', NULL);
|
||||
|
||||
// Test that the assertion fails correctly if no value is passed in.
|
||||
try {
|
||||
$this->assertNoFieldById('edit-description');
|
||||
$this->fail('The "description" field, with no value was not found.');
|
||||
}
|
||||
catch (ExpectationException $e) {
|
||||
$this->pass('The "description" field, with no value was found.');
|
||||
}
|
||||
|
||||
// Test that the assertion fails correctly if a NULL value is passed in.
|
||||
try {
|
||||
$this->assertNoFieldById('edit-name', NULL);
|
||||
$this->fail('The "name" field was not found.');
|
||||
}
|
||||
catch (ExpectationException $e) {
|
||||
$this->pass('The "name" field was found.');
|
||||
}
|
||||
|
||||
$this->assertFieldById('edit-name', NULL);
|
||||
$this->assertFieldById('edit-name', 'Test name');
|
||||
$this->assertFieldById('edit-description', NULL);
|
||||
$this->assertFieldById('edit-description');
|
||||
|
||||
// Test that the assertion fails correctly if no value is passed in.
|
||||
try {
|
||||
$this->assertFieldById('edit-name');
|
||||
$this->fail('The "edit-name" field with no value was found.');
|
||||
}
|
||||
catch (\PHPUnit_Framework_ExpectationFailedException $e) {
|
||||
$this->pass('The "edit-name" field with no value was not found.');
|
||||
}
|
||||
|
||||
// Test that the assertion fails correctly if NULL is passed in.
|
||||
try {
|
||||
$this->assertFieldById('name', NULL);
|
||||
$this->fail('The "name" field was found.');
|
||||
}
|
||||
catch (ExpectationException $e) {
|
||||
$this->pass('The "name" field was not found.');
|
||||
}
|
||||
|
||||
$this->assertNoFieldByName('name');
|
||||
$this->assertNoFieldByName('name', 'not the value');
|
||||
$this->assertNoFieldByName('notexisting');
|
||||
$this->assertNoFieldByName('notexisting', NULL);
|
||||
|
||||
// Test that the assertion fails correctly if no value is passed in.
|
||||
try {
|
||||
$this->assertNoFieldByName('description');
|
||||
$this->fail('The "description" field, with no value was not found.');
|
||||
}
|
||||
catch (ExpectationException $e) {
|
||||
$this->pass('The "description" field, with no value was found.');
|
||||
}
|
||||
|
||||
// Test that the assertion fails correctly if a NULL value is passed in.
|
||||
try {
|
||||
$this->assertNoFieldByName('name', NULL);
|
||||
$this->fail('The "name" field was not found.');
|
||||
}
|
||||
catch (ExpectationException $e) {
|
||||
$this->pass('The "name" field was found.');
|
||||
}
|
||||
|
||||
$this->assertOptionByText('options', 'one');
|
||||
try {
|
||||
$this->assertOptionByText('options', 'four');
|
||||
$this->fail('The select option "four" was found.');
|
||||
}
|
||||
catch (ExpectationException $e) {
|
||||
$this->pass($e->getMessage());
|
||||
}
|
||||
|
||||
$this->assertFieldById('edit-save', NULL);
|
||||
// Test that the assertion fails correctly if the field value is passed in
|
||||
// rather than the id.
|
||||
try {
|
||||
$this->assertFieldById('Save', NULL);
|
||||
$this->fail('The field with id of "Save" was found.');
|
||||
}
|
||||
catch (ExpectationException $e) {
|
||||
$this->pass($e->getMessage());
|
||||
}
|
||||
|
||||
$this->assertNoFieldById('Save', NULL);
|
||||
// Test that the assertion fails correctly if the id of an actual field is
|
||||
// passed in.
|
||||
try {
|
||||
$this->assertNoFieldById('edit-save', NULL);
|
||||
$this->fail('The field with id of "edit-save" was not found.');
|
||||
}
|
||||
catch (ExpectationException $e) {
|
||||
$this->pass($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the ::cronRun() method.
|
||||
*/
|
||||
public function testCronRun() {
|
||||
$last_cron_time = \Drupal::state()->get('system.cron_last');
|
||||
$this->cronRun();
|
||||
$this->assertSession()->statusCodeEquals(204);
|
||||
$next_cron_time = \Drupal::state()->get('system.cron_last');
|
||||
|
||||
$this->assertGreaterThan($last_cron_time, $next_cron_time);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,6 +17,6 @@ class SchemaConfigListenerTest extends BrowserTestBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = array('config_test');
|
||||
public static $modules = ['config_test'];
|
||||
|
||||
}
|
||||
|
|
149
web/core/tests/Drupal/FunctionalTests/Datetime/TimestampTest.php
Normal file
149
web/core/tests/Drupal/FunctionalTests/Datetime/TimestampTest.php
Normal file
|
@ -0,0 +1,149 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\FunctionalTests\Datetime;
|
||||
|
||||
use Drupal\Core\Datetime\DrupalDateTime;
|
||||
use Drupal\Core\Datetime\Entity\DateFormat;
|
||||
use Drupal\Core\Entity\Entity\EntityFormDisplay;
|
||||
use Drupal\Core\Entity\Entity\EntityViewDisplay;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests the functionality of Timestamp core field UI.
|
||||
*
|
||||
* @group field
|
||||
*/
|
||||
class TimestampTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* An array of display options to pass to entity_get_display().
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $displayOptions;
|
||||
|
||||
/**
|
||||
* A field storage to use in this test class.
|
||||
*
|
||||
* @var \Drupal\field\Entity\FieldStorageConfig
|
||||
*/
|
||||
protected $fieldStorage;
|
||||
|
||||
/**
|
||||
* The field used in this test class.
|
||||
*
|
||||
* @var \Drupal\field\Entity\FieldConfig
|
||||
*/
|
||||
protected $field;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['node', 'entity_test', 'field_ui'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$web_user = $this->drupalCreateUser([
|
||||
'access content',
|
||||
'view test entity',
|
||||
'administer entity_test content',
|
||||
'administer entity_test form display',
|
||||
'administer content types',
|
||||
'administer node fields',
|
||||
]);
|
||||
|
||||
$this->drupalLogin($web_user);
|
||||
$field_name = 'field_timestamp';
|
||||
$type = 'timestamp';
|
||||
$widget_type = 'datetime_timestamp';
|
||||
$formatter_type = 'timestamp';
|
||||
|
||||
$this->fieldStorage = FieldStorageConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'entity_test',
|
||||
'type' => $type,
|
||||
]);
|
||||
$this->fieldStorage->save();
|
||||
$this->field = FieldConfig::create([
|
||||
'field_storage' => $this->fieldStorage,
|
||||
'bundle' => 'entity_test',
|
||||
'required' => TRUE,
|
||||
]);
|
||||
$this->field->save();
|
||||
|
||||
EntityFormDisplay::load('entity_test.entity_test.default')
|
||||
->setComponent($field_name, ['type' => $widget_type])
|
||||
->save();
|
||||
|
||||
$this->displayOptions = [
|
||||
'type' => $formatter_type,
|
||||
'label' => 'hidden',
|
||||
];
|
||||
|
||||
EntityViewDisplay::create([
|
||||
'targetEntityType' => $this->field->getTargetEntityTypeId(),
|
||||
'bundle' => $this->field->getTargetBundle(),
|
||||
'mode' => 'full',
|
||||
'status' => TRUE,
|
||||
])->setComponent($field_name, $this->displayOptions)
|
||||
->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the "datetime_timestamp" widget.
|
||||
*/
|
||||
public function testWidget() {
|
||||
// Build up a date in the UTC timezone.
|
||||
$value = '2012-12-31 00:00:00';
|
||||
$date = new DrupalDateTime($value, 'UTC');
|
||||
|
||||
// Update the timezone to the system default.
|
||||
$date->setTimezone(timezone_open(drupal_get_user_timezone()));
|
||||
|
||||
// Display creation form.
|
||||
$this->drupalGet('entity_test/add');
|
||||
|
||||
// Make sure the "datetime_timestamp" widget is on the page.
|
||||
$fields = $this->xpath('//div[contains(@class, "field--widget-datetime-timestamp") and @id="edit-field-timestamp-wrapper"]');
|
||||
$this->assertEquals(1, count($fields));
|
||||
|
||||
// Look for the widget elements and make sure they are empty.
|
||||
$this->assertSession()->fieldExists('field_timestamp[0][value][date]');
|
||||
$this->assertSession()->fieldValueEquals('field_timestamp[0][value][date]', '');
|
||||
$this->assertSession()->fieldExists('field_timestamp[0][value][time]');
|
||||
$this->assertSession()->fieldValueEquals('field_timestamp[0][value][time]', '');
|
||||
|
||||
// Submit the date.
|
||||
$date_format = DateFormat::load('html_date')->getPattern();
|
||||
$time_format = DateFormat::load('html_time')->getPattern();
|
||||
|
||||
$edit = [
|
||||
'field_timestamp[0][value][date]' => $date->format($date_format),
|
||||
'field_timestamp[0][value][time]' => $date->format($time_format),
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, 'Save');
|
||||
|
||||
// Make sure the submitted date is set as the default in the widget.
|
||||
$this->assertSession()->fieldExists('field_timestamp[0][value][date]');
|
||||
$this->assertSession()->fieldValueEquals('field_timestamp[0][value][date]', $date->format($date_format));
|
||||
$this->assertSession()->fieldExists('field_timestamp[0][value][time]');
|
||||
$this->assertSession()->fieldValueEquals('field_timestamp[0][value][time]', $date->format($time_format));
|
||||
|
||||
// Make sure the entity was saved.
|
||||
preg_match('|entity_test/manage/(\d+)|', $this->getSession()->getCurrentUrl(), $match);
|
||||
$id = $match[1];
|
||||
$this->assertSession()->pageTextContains(sprintf('entity_test %s has been created.', $id));
|
||||
|
||||
// Make sure the timestamp is output properly with the default formatter.
|
||||
$medium = DateFormat::load('medium')->getPattern();
|
||||
$this->drupalGet('entity_test/' . $id);
|
||||
$this->assertSession()->pageTextContains($date->format($medium));
|
||||
}
|
||||
|
||||
}
|
|
@ -2,8 +2,6 @@
|
|||
|
||||
namespace Drupal\FunctionalTests\Entity;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\ContentEntityStorageInterface;
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
|
@ -14,7 +12,7 @@ use Drupal\Tests\BrowserTestBase;
|
|||
*
|
||||
* @group Entity
|
||||
*/
|
||||
class ContentEntityFormCorrectUserInputMappingOnFieldDeltaElementsTest extends BrowserTestBase {
|
||||
class ContentEntityFormCorrectUserInputMappingOnFieldDeltaElementsTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* The ID of the type of the entity under test.
|
||||
|
@ -86,10 +84,10 @@ class ContentEntityFormCorrectUserInputMappingOnFieldDeltaElementsTest extends B
|
|||
$this->drupalGet($this->entityTypeId . '/manage/' . $entity->id() . '/edit');
|
||||
|
||||
// Rearrange the field items.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
"$this->fieldName[0][_weight]" => 0,
|
||||
"$this->fieldName[1][_weight]" => -1,
|
||||
);
|
||||
];
|
||||
// Executing an ajax call is important before saving as it will trigger
|
||||
// form state caching and so if for any reasons the form is rebuilt with
|
||||
// the entity built based on the user submitted values with already
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\FunctionalTests;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Test for BrowserTestBase::getTestMethodCaller() in child classes.
|
||||
*
|
||||
* @group browsertestbase
|
||||
*/
|
||||
class GetTestMethodCallerExtendsTest extends GetTestMethodCallerTest {
|
||||
|
||||
/**
|
||||
* A test method that is not present in the parent class.
|
||||
*/
|
||||
public function testGetTestMethodCallerChildClass() {
|
||||
$method_caller = $this->getTestMethodCaller();
|
||||
$expected = [
|
||||
'file' => __FILE__,
|
||||
'line' => 18,
|
||||
'function' => __CLASS__ . '->' . __FUNCTION__ . '()',
|
||||
'class' => BrowserTestBase::class,
|
||||
'object' => $this,
|
||||
'type' => '->',
|
||||
'args' => [],
|
||||
];
|
||||
$this->assertEquals($expected, $method_caller);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\FunctionalTests;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Explicit test for BrowserTestBase::getTestMethodCaller().
|
||||
*
|
||||
* @group browsertestbase
|
||||
*/
|
||||
class GetTestMethodCallerTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Tests BrowserTestBase::getTestMethodCaller().
|
||||
*/
|
||||
public function testGetTestMethodCaller() {
|
||||
$method_caller = $this->getTestMethodCaller();
|
||||
$expected = [
|
||||
'file' => __FILE__,
|
||||
'line' => 18,
|
||||
'function' => __CLASS__ . '->' . __FUNCTION__ . '()',
|
||||
'class' => BrowserTestBase::class,
|
||||
'object' => $this,
|
||||
'type' => '->',
|
||||
'args' => [],
|
||||
];
|
||||
$this->assertEquals($expected, $method_caller);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\FunctionalTests\Routing;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests incoming path case insensitivity.
|
||||
*
|
||||
* @group routing
|
||||
*/
|
||||
class CaseInsensitivePathTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['system', 'views', 'node', 'system_test'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
\Drupal::state()->set('system_test.module_hidden', FALSE);
|
||||
$this->createContentType(['type' => 'page']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests mixed case paths.
|
||||
*/
|
||||
public function testMixedCasePaths() {
|
||||
// Tests paths defined by routes from standard modules as anonymous.
|
||||
$this->drupalGet('user/login');
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
$this->assertSession()->pageTextMatches('/Log in/');
|
||||
$this->drupalGet('User/Login');
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
$this->assertSession()->pageTextMatches('/Log in/');
|
||||
|
||||
// Tests paths defined by routes from the Views module.
|
||||
$admin = $this->drupalCreateUser(['access administration pages', 'administer nodes', 'access content overview']);
|
||||
$this->drupalLogin($admin);
|
||||
|
||||
$this->drupalGet('admin/content');
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
$this->assertSession()->pageTextMatches('/Content/');
|
||||
$this->drupalGet('Admin/Content');
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
$this->assertSession()->pageTextMatches('/Content/');
|
||||
|
||||
// Tests paths with query arguments.
|
||||
|
||||
// Make sure our node title doesn't exist.
|
||||
$this->drupalGet('admin/content');
|
||||
$this->assertSession()->linkNotExists('FooBarBaz');
|
||||
$this->assertSession()->linkNotExists('foobarbaz');
|
||||
|
||||
// Create a node, and make sure it shows up on admin/content.
|
||||
$node = $this->createNode([
|
||||
'title' => 'FooBarBaz',
|
||||
'type' => 'page',
|
||||
]);
|
||||
|
||||
$this->drupalGet('admin/content', [
|
||||
'query' => [
|
||||
'title' => 'FooBarBaz'
|
||||
]
|
||||
]);
|
||||
|
||||
$this->assertSession()->linkExists('FooBarBaz');
|
||||
$this->assertSession()->linkByHrefExists($node->toUrl()->toString());
|
||||
|
||||
// Make sure the path is case-insensitive, and query case is preserved.
|
||||
|
||||
$this->drupalGet('Admin/Content', [
|
||||
'query' => [
|
||||
'title' => 'FooBarBaz'
|
||||
]
|
||||
]);
|
||||
|
||||
$this->assertSession()->linkExists('FooBarBaz');
|
||||
$this->assertSession()->linkByHrefExists($node->toUrl()->toString());
|
||||
$this->assertSession()->fieldValueEquals('edit-title', 'FooBarBaz');
|
||||
// Check that we can access the node with a mixed case path.
|
||||
$this->drupalGet('NOdE/' . $node->id());
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
$this->assertSession()->pageTextMatches('/FooBarBaz/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests paths with slugs.
|
||||
*/
|
||||
public function testPathsWithArguments() {
|
||||
$this->drupalGet('system-test/echo/foobarbaz');
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
$this->assertSession()->pageTextMatches('/foobarbaz/');
|
||||
$this->assertSession()->pageTextNotMatches('/FooBarBaz/');
|
||||
|
||||
$this->drupalGet('system-test/echo/FooBarBaz');
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
$this->assertSession()->pageTextMatches('/FooBarBaz/');
|
||||
$this->assertSession()->pageTextNotMatches('/foobarbaz/');
|
||||
|
||||
// Test utf-8 characters in the route path.
|
||||
$this->drupalGet('/system-test/Ȅchȏ/meΦω/ABc123');
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
$this->assertSession()->pageTextMatches('/ABc123/');
|
||||
$this->drupalGet('/system-test/ȅchȎ/MEΦΩ/ABc123');
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
$this->assertSession()->pageTextMatches('/ABc123/');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\FunctionalTests\Routing;
|
||||
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests url generation and routing for route paths with encoded characters.
|
||||
*
|
||||
* @group routing
|
||||
*/
|
||||
class PathEncodedTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['system', 'path_encoded_test'];
|
||||
|
||||
public function testGetEncoded() {
|
||||
$route_paths = [
|
||||
'path_encoded_test.colon' => '/hi/llamma:party',
|
||||
'path_encoded_test.atsign' => '/bloggy/@Dries',
|
||||
'path_encoded_test.parens' => '/cat(box)',
|
||||
];
|
||||
foreach ($route_paths as $route_name => $path) {
|
||||
$this->drupalGet(Url::fromRoute($route_name));
|
||||
$this->assertSession()->pageTextContains('PathEncodedTestController works');
|
||||
}
|
||||
}
|
||||
|
||||
public function testAliasToEncoded() {
|
||||
$route_paths = [
|
||||
'path_encoded_test.colon' => '/hi/llamma:party',
|
||||
'path_encoded_test.atsign' => '/bloggy/@Dries',
|
||||
'path_encoded_test.parens' => '/cat(box)',
|
||||
];
|
||||
/** @var \Drupal\Core\Path\AliasStorageInterface $alias_storage */
|
||||
$alias_storage = $this->container->get('path.alias_storage');
|
||||
$aliases = [];
|
||||
foreach ($route_paths as $route_name => $path) {
|
||||
$aliases[$route_name] = $this->randomMachineName();
|
||||
$alias_storage->save($path, '/' . $aliases[$route_name]);
|
||||
}
|
||||
foreach ($route_paths as $route_name => $path) {
|
||||
// The alias may be only a suffix of the generated path when the test is
|
||||
// run with Drupal installed in a subdirectory.
|
||||
$this->assertRegExp('@/' . rawurlencode($aliases[$route_name]) . '$@', Url::fromRoute($route_name)->toString());
|
||||
$this->drupalGet(Url::fromRoute($route_name));
|
||||
$this->assertSession()->pageTextContains('PathEncodedTestController works');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue