upgrades core to 8.4.2
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Drupal\FunctionalTests;
|
||||
|
||||
use Behat\Mink\Exception\ElementNotFoundException;
|
||||
use Behat\Mink\Element\NodeElement;
|
||||
use Behat\Mink\Exception\ExpectationException;
|
||||
use Behat\Mink\Selector\Xpath\Escaper;
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
@@ -220,13 +220,11 @@ trait AssertLegacyTrait {
|
||||
*
|
||||
* @deprecated Scheduled for removal in Drupal 9.0.0.
|
||||
* Use $this->assertSession()->fieldExists() or
|
||||
* $this->assertSession()->buttonExists() or
|
||||
* $this->assertSession()->fieldValueEquals() instead.
|
||||
*/
|
||||
protected function assertFieldByName($name, $value = NULL) {
|
||||
$this->assertSession()->fieldExists($name);
|
||||
if ($value !== NULL) {
|
||||
$this->assertSession()->fieldValueEquals($name, (string) $value);
|
||||
}
|
||||
$this->assertFieldByXPath($this->constructFieldXpath('name', $name), $value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -242,15 +240,11 @@ trait AssertLegacyTrait {
|
||||
*
|
||||
* @deprecated Scheduled for removal in Drupal 9.0.0.
|
||||
* Use $this->assertSession()->fieldNotExists() or
|
||||
* $this->assertSession()->buttonNotExists() or
|
||||
* $this->assertSession()->fieldValueNotEquals() instead.
|
||||
*/
|
||||
protected function assertNoFieldByName($name, $value = '') {
|
||||
if ($this->getSession()->getPage()->findField($name) && isset($value)) {
|
||||
$this->assertSession()->fieldValueNotEquals($name, (string) $value);
|
||||
}
|
||||
else {
|
||||
$this->assertSession()->fieldNotExists($name);
|
||||
}
|
||||
$this->assertNoFieldByXPath($this->constructFieldXpath('name', $name), $value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -268,19 +262,11 @@ trait AssertLegacyTrait {
|
||||
*
|
||||
* @deprecated Scheduled for removal in Drupal 9.0.0.
|
||||
* Use $this->assertSession()->fieldExists() or
|
||||
* $this->assertSession()->buttonExists() or
|
||||
* $this->assertSession()->fieldValueEquals() instead.
|
||||
*/
|
||||
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());
|
||||
}
|
||||
$this->assertFieldByXPath($this->constructFieldXpath('id', $id), $value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -290,23 +276,25 @@ trait AssertLegacyTrait {
|
||||
* Name or ID of field to assert.
|
||||
*
|
||||
* @deprecated Scheduled for removal in Drupal 9.0.0.
|
||||
* Use $this->assertSession()->fieldExists() instead.
|
||||
* Use $this->assertSession()->fieldExists() or
|
||||
* $this->assertSession()->buttonExists() instead.
|
||||
*/
|
||||
protected function assertField($field) {
|
||||
$this->assertSession()->fieldExists($field);
|
||||
$this->assertFieldByXPath($this->constructFieldXpath('name', $field) . '|' . $this->constructFieldXpath('id', $field));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a field exists with the given name or ID does NOT exist.
|
||||
* Asserts that a field does NOT exist with the given name or ID.
|
||||
*
|
||||
* @param string $field
|
||||
* Name or ID of field to assert.
|
||||
*
|
||||
* @deprecated Scheduled for removal in Drupal 9.0.0.
|
||||
* Use $this->assertSession()->fieldNotExists() instead.
|
||||
* Use $this->assertSession()->fieldNotExists() or
|
||||
* $this->assertSession()->buttonNotExists() instead.
|
||||
*/
|
||||
protected function assertNoField($field) {
|
||||
$this->assertSession()->fieldNotExists($field);
|
||||
$this->assertNoFieldByXPath($this->constructFieldXpath('name', $field) . '|' . $this->constructFieldXpath('id', $field));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -427,23 +415,11 @@ trait AssertLegacyTrait {
|
||||
*
|
||||
* @deprecated Scheduled for removal in Drupal 9.0.0.
|
||||
* Use $this->assertSession()->fieldNotExists() or
|
||||
* $this->assertSession()->buttonNotExists() or
|
||||
* $this->assertSession()->fieldValueNotEquals() instead.
|
||||
*/
|
||||
protected function assertNoFieldById($id, $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;
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
$this->assertNoFieldByXPath($this->constructFieldXpath('id', $id), $value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -585,25 +561,32 @@ trait AssertLegacyTrait {
|
||||
* (optional) A message to display with the assertion. Do not translate
|
||||
* messages with t().
|
||||
*
|
||||
* @throws \Behat\Mink\Exception\ExpectationException
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
if (!empty($fields)) {
|
||||
if (isset($value)) {
|
||||
$found = FALSE;
|
||||
try {
|
||||
$this->assertFieldsByValue($fields, $value);
|
||||
$found = TRUE;
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
}
|
||||
|
||||
if ($found) {
|
||||
throw new ExpectationException(sprintf('The field resulting from %s was found with the provided value %s.', $xpath, $value), $this->getSession()->getDriver());
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new ExpectationException(sprintf('The field resulting from %s was found.', $xpath), $this->getSession()->getDriver());
|
||||
}
|
||||
}
|
||||
return $this->assertFalse($fields && $found, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -629,7 +612,15 @@ trait AssertLegacyTrait {
|
||||
$found = FALSE;
|
||||
if ($fields) {
|
||||
foreach ($fields as $field) {
|
||||
if ($field->getAttribute('value') == $value) {
|
||||
if ($field->getAttribute('type') == 'checkbox') {
|
||||
if (is_bool($value)) {
|
||||
$found = $field->isChecked() == $value;
|
||||
}
|
||||
else {
|
||||
$found = TRUE;
|
||||
}
|
||||
}
|
||||
elseif ($field->getAttribute('value') == $value) {
|
||||
// Input element with correct value.
|
||||
$found = TRUE;
|
||||
}
|
||||
@@ -637,8 +628,12 @@ trait AssertLegacyTrait {
|
||||
// Select element with an option.
|
||||
$found = TRUE;
|
||||
}
|
||||
elseif ($field->getText() == $value) {
|
||||
// Text area with correct text.
|
||||
elseif ($field->getTagName() === 'textarea' && $field->getValue() == $value) {
|
||||
// Text area with correct text. Use getValue() here because
|
||||
// getText() would remove any newlines in the value.
|
||||
$found = TRUE;
|
||||
}
|
||||
elseif ($field->getTagName() !== 'input' && $field->getText() == $value) {
|
||||
$found = TRUE;
|
||||
}
|
||||
}
|
||||
@@ -719,6 +714,22 @@ trait AssertLegacyTrait {
|
||||
$this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', $expected_cache_tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts whether an expected cache tag was absent in the last response.
|
||||
*
|
||||
* @param string $cache_tag
|
||||
* The cache tag to check.
|
||||
*
|
||||
* @deprecated Scheduled for removal in Drupal 9.0.0.
|
||||
* Use $this->assertSession()->responseHeaderNotContains() instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2864029
|
||||
*/
|
||||
protected function assertNoCacheTag($cache_tag) {
|
||||
@trigger_error('assertNoCacheTag() is deprecated and scheduled for removal in Drupal 9.0.0. Use $this->assertSession()->responseHeaderNotContains() instead. See https://www.drupal.org/node/2864029.', E_USER_DEPRECATED);
|
||||
$this->assertSession()->responseHeaderNotContains('X-Drupal-Cache-Tags', $cache_tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that current response header equals value.
|
||||
*
|
||||
@@ -772,6 +783,25 @@ trait AssertLegacyTrait {
|
||||
return $this->assertSession()->buildXPathQuery($xpath, $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper: Constructs an XPath for the given set of attributes and value.
|
||||
*
|
||||
* @param string $attribute
|
||||
* Field attributes.
|
||||
* @param string $value
|
||||
* Value of field.
|
||||
*
|
||||
* @return string
|
||||
* XPath for specified values.
|
||||
*
|
||||
* @deprecated Scheduled for removal in Drupal 9.0.0.
|
||||
* Use $this->getSession()->getPage()->findField() instead.
|
||||
*/
|
||||
protected function constructFieldXpath($attribute, $value) {
|
||||
$xpath = '//textarea[@' . $attribute . '=:value]|//input[@' . $attribute . '=:value]|//select[@' . $attribute . '=:value]';
|
||||
return $this->buildXPathQuery($xpath, [':value' => $value]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current raw content.
|
||||
*
|
||||
@@ -783,4 +813,21 @@ trait AssertLegacyTrait {
|
||||
return $this->getSession()->getPage()->getContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all option elements, including nested options, in a select.
|
||||
*
|
||||
* @param \Behat\Mink\Element\NodeElement $element
|
||||
* The element for which to get the options.
|
||||
*
|
||||
* @return \Behat\Mink\Element\NodeElement[]
|
||||
* Option elements in select.
|
||||
*
|
||||
* @deprecated Scheduled for removal in Drupal 9.0.0.
|
||||
* Use $element->findAll('xpath', 'option') instead.
|
||||
*/
|
||||
protected function getAllOptions(NodeElement $element) {
|
||||
@trigger_error('AssertLegacyTrait::getAllOptions() is scheduled for removal in Drupal 9.0.0. Use $element->findAll(\'xpath\', \'option\') instead.', E_USER_DEPRECATED);
|
||||
return $element->findAll('xpath', '//option');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Drupal\FunctionalTests;
|
||||
|
||||
use Behat\Mink\Exception\ExpectationException;
|
||||
use Drupal\Component\Serialization\Json;
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
@@ -98,13 +99,18 @@ class BrowserTestBaseTest extends BrowserTestBase {
|
||||
|
||||
// Test drupalPostForm().
|
||||
$edit = ['bananas' => 'red'];
|
||||
$this->drupalPostForm('form-test/object-builder', $edit, 'Save');
|
||||
$result = $this->drupalPostForm('form-test/object-builder', $edit, 'Save');
|
||||
$this->assertSame($this->getSession()->getPage()->getContent(), $result);
|
||||
$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);
|
||||
|
||||
// Test drupalPostForm() with no-html response.
|
||||
$values = Json::decode($this->drupalPostForm('form_test/form-state-values-clean', [], t('Submit')));
|
||||
$this->assertTrue(1000, $values['beer']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -137,6 +143,48 @@ class BrowserTestBaseTest extends BrowserTestBase {
|
||||
$this->assertSession()->linkExists('foo|bar|baz');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests linkExistsExact() functionality.
|
||||
*
|
||||
* @see \Drupal\Tests\WebAssert::linkExistsExact()
|
||||
*/
|
||||
public function testLinkExistsExact() {
|
||||
$this->drupalGet('test-pipe-char');
|
||||
$this->assertSession()->linkExistsExact('foo|bar|baz');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests linkExistsExact() functionality fail.
|
||||
*
|
||||
* @see \Drupal\Tests\WebAssert::linkExistsExact()
|
||||
*/
|
||||
public function testInvalidLinkExistsExact() {
|
||||
$this->drupalGet('test-pipe-char');
|
||||
$this->setExpectedException(ExpectationException::class, 'Link with label foo|bar found');
|
||||
$this->assertSession()->linkExistsExact('foo|bar');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests linkNotExistsExact() functionality.
|
||||
*
|
||||
* @see \Drupal\Tests\WebAssert::linkNotExistsExact()
|
||||
*/
|
||||
public function testLinkNotExistsExact() {
|
||||
$this->drupalGet('test-pipe-char');
|
||||
$this->assertSession()->linkNotExistsExact('foo|bar');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests linkNotExistsExact() functionality fail.
|
||||
*
|
||||
* @see \Drupal\Tests\WebAssert::linkNotExistsExact()
|
||||
*/
|
||||
public function testInvalidLinkNotExistsExact() {
|
||||
$this->drupalGet('test-pipe-char');
|
||||
$this->setExpectedException(ExpectationException::class, 'Link with label foo|bar|baz not found');
|
||||
$this->assertSession()->linkNotExistsExact('foo|bar|baz');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests legacy text asserts.
|
||||
*/
|
||||
@@ -181,7 +229,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
|
||||
$this->assertNoFieldByXPath("//input[@id = 'edit-name']");
|
||||
$this->fail('The "edit-name" field was not found.');
|
||||
}
|
||||
catch (\PHPUnit_Framework_ExpectationFailedException $e) {
|
||||
catch (ExpectationException $e) {
|
||||
$this->pass('assertNoFieldByXPath correctly failed. The "edit-name" field was found.');
|
||||
}
|
||||
|
||||
@@ -197,7 +245,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
|
||||
/**
|
||||
* Tests legacy field asserts using textfields.
|
||||
*/
|
||||
public function testLegacyFieldAssertsWithTextfields() {
|
||||
public function testLegacyFieldAssertsForTextfields() {
|
||||
$this->drupalGet('test-field-xpath');
|
||||
|
||||
// *** 1. assertNoField().
|
||||
@@ -230,7 +278,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
|
||||
$this->assertField('invalid_name_and_id');
|
||||
$this->fail('The "invalid_name_and_id" field was found.');
|
||||
}
|
||||
catch (ExpectationException $e) {
|
||||
catch (\PHPUnit_Framework_ExpectationFailedException $e) {
|
||||
$this->pass('assertField correctly failed. The "invalid_name_and_id" field was not found.');
|
||||
}
|
||||
|
||||
@@ -319,7 +367,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
|
||||
$this->assertFieldByName('non-existing-name');
|
||||
$this->fail('The "non-existing-name" field was found.');
|
||||
}
|
||||
catch (ExpectationException $e) {
|
||||
catch (\PHPUnit_Framework_ExpectationFailedException $e) {
|
||||
$this->pass('The "non-existing-name" field was not found');
|
||||
}
|
||||
|
||||
@@ -328,15 +376,18 @@ class BrowserTestBaseTest extends BrowserTestBase {
|
||||
$this->assertFieldByName('name', 'not the value');
|
||||
$this->fail('The "name" field with incorrect value was found.');
|
||||
}
|
||||
catch (ExpectationException $e) {
|
||||
catch (\PHPUnit_Framework_ExpectationFailedException $e) {
|
||||
$this->pass('assertFieldByName correctly failed. The "name" field with incorrect value was not found.');
|
||||
}
|
||||
|
||||
// Test that text areas can contain new lines.
|
||||
$this->assertFieldsByValue($this->xpath("//textarea[@id = 'edit-test-textarea-with-newline']"), "Test text with\nnewline");
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests legacy field asserts on other types of field.
|
||||
* Tests legacy field asserts for options field type.
|
||||
*/
|
||||
public function testLegacyFieldAssertsWithNonTextfields() {
|
||||
public function testLegacyFieldAssertsForOptions() {
|
||||
$this->drupalGet('test-field-xpath');
|
||||
|
||||
// Option field type.
|
||||
@@ -384,7 +435,17 @@ class BrowserTestBaseTest extends BrowserTestBase {
|
||||
$this->pass($e->getMessage());
|
||||
}
|
||||
|
||||
// Button field type.
|
||||
// Test \Drupal\FunctionalTests\AssertLegacyTrait::getAllOptions.
|
||||
$this->drupalGet('/form-test/select');
|
||||
$this->assertCount(6, $this->getAllOptions($this->cssSelect('select[name="opt_groups"]')[0]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests legacy field asserts for button field type.
|
||||
*/
|
||||
public function testLegacyFieldAssertsForButton() {
|
||||
$this->drupalGet('test-field-xpath');
|
||||
|
||||
$this->assertFieldById('edit-save', NULL);
|
||||
// Test that the assertion fails correctly if the field value is passed in
|
||||
// rather than the id.
|
||||
@@ -392,7 +453,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
|
||||
$this->assertFieldById('Save', NULL);
|
||||
$this->fail('The field with id of "Save" was found.');
|
||||
}
|
||||
catch (ExpectationException $e) {
|
||||
catch (\PHPUnit_Framework_ExpectationFailedException $e) {
|
||||
$this->pass($e->getMessage());
|
||||
}
|
||||
|
||||
@@ -407,7 +468,27 @@ class BrowserTestBaseTest extends BrowserTestBase {
|
||||
$this->pass($e->getMessage());
|
||||
}
|
||||
|
||||
// Checkbox field type.
|
||||
// Test that multiple fields with the same name are validated correctly.
|
||||
$this->assertFieldByName('duplicate_button', 'Duplicate button 1');
|
||||
$this->assertFieldByName('duplicate_button', 'Duplicate button 2');
|
||||
$this->assertNoFieldByName('duplicate_button', 'Rabbit');
|
||||
|
||||
try {
|
||||
$this->assertNoFieldByName('duplicate_button', 'Duplicate button 2');
|
||||
$this->fail('The "duplicate_button" field with the value Duplicate button 2 was not found.');
|
||||
}
|
||||
catch (ExpectationException $e) {
|
||||
$this->pass('assertNoFieldByName correctly failed. The "duplicate_button" field with the value Duplicate button 2 was found.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests legacy field asserts for checkbox field type.
|
||||
*/
|
||||
public function testLegacyFieldAssertsForCheckbox() {
|
||||
$this->drupalGet('test-field-xpath');
|
||||
|
||||
// Part 1 - Test by name.
|
||||
// Test that checkboxes are found/not found correctly by name, when using
|
||||
// TRUE or FALSE to match their 'checked' state.
|
||||
$this->assertFieldByName('checkbox_enabled', TRUE);
|
||||
@@ -420,17 +501,13 @@ class BrowserTestBaseTest extends BrowserTestBase {
|
||||
$this->assertFieldByName('checkbox_enabled', NULL);
|
||||
$this->assertFieldByName('checkbox_disabled', NULL);
|
||||
|
||||
// Test that checkboxes are found/not found correctly by ID, when using
|
||||
// TRUE or FALSE to match their 'checked' state.
|
||||
$this->assertFieldById('edit-checkbox-enabled', TRUE);
|
||||
$this->assertFieldById('edit-checkbox-disabled', FALSE);
|
||||
$this->assertNoFieldById('edit-checkbox-enabled', FALSE);
|
||||
$this->assertNoFieldById('edit-checkbox-disabled', TRUE);
|
||||
// Test that checkboxes are found by name when passing no second parameter.
|
||||
$this->assertFieldByName('checkbox_enabled');
|
||||
$this->assertFieldByName('checkbox_disabled');
|
||||
|
||||
// Test that checkboxes are found by by ID, when using NULL to ignore the
|
||||
// 'checked' state.
|
||||
$this->assertFieldById('edit-checkbox-enabled', NULL);
|
||||
$this->assertFieldById('edit-checkbox-disabled', NULL);
|
||||
// Test that we have legacy support.
|
||||
$this->assertFieldByName('checkbox_enabled', '1');
|
||||
$this->assertFieldByName('checkbox_disabled', '');
|
||||
|
||||
// Test that the assertion fails correctly when using NULL to ignore state.
|
||||
try {
|
||||
@@ -441,6 +518,27 @@ class BrowserTestBaseTest extends BrowserTestBase {
|
||||
$this->pass('assertNoFieldByName failed correctly. The "checkbox_enabled" field was found using NULL value.');
|
||||
}
|
||||
|
||||
// Part 2 - Test by ID.
|
||||
// Test that checkboxes are found/not found correctly by ID, when using
|
||||
// TRUE or FALSE to match their 'checked' state.
|
||||
$this->assertFieldById('edit-checkbox-enabled', TRUE);
|
||||
$this->assertFieldById('edit-checkbox-disabled', FALSE);
|
||||
$this->assertNoFieldById('edit-checkbox-enabled', FALSE);
|
||||
$this->assertNoFieldById('edit-checkbox-disabled', TRUE);
|
||||
|
||||
// Test that checkboxes are found by ID, when using NULL to ignore the
|
||||
// 'checked' state.
|
||||
$this->assertFieldById('edit-checkbox-enabled', NULL);
|
||||
$this->assertFieldById('edit-checkbox-disabled', NULL);
|
||||
|
||||
// Test that checkboxes are found by ID when passing no second parameter.
|
||||
$this->assertFieldById('edit-checkbox-enabled');
|
||||
$this->assertFieldById('edit-checkbox-disabled');
|
||||
|
||||
// Test that we have legacy support.
|
||||
$this->assertFieldById('edit-checkbox-enabled', '1');
|
||||
$this->assertFieldById('edit-checkbox-disabled', '');
|
||||
|
||||
// Test that the assertion fails correctly when using NULL to ignore state.
|
||||
try {
|
||||
$this->assertNoFieldById('edit-checkbox-disabled', NULL);
|
||||
@@ -450,7 +548,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
|
||||
$this->pass('assertNoFieldById failed correctly. The "edit-checkbox-disabled" field was found by ID using NULL value.');
|
||||
}
|
||||
|
||||
// Test the specific 'checked' assertions.
|
||||
// Part 3 - Test the specific 'checked' assertions.
|
||||
$this->assertFieldChecked('edit-checkbox-enabled');
|
||||
$this->assertNoFieldChecked('edit-checkbox-disabled');
|
||||
|
||||
@@ -517,4 +615,22 @@ class BrowserTestBaseTest extends BrowserTestBase {
|
||||
$this->assertEquals('Australia/Sydney', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the ::checkForMetaRefresh() method.
|
||||
*/
|
||||
public function testCheckForMetaRefresh() {
|
||||
// Disable following redirects in the client.
|
||||
$this->getSession()->getDriver()->getClient()->followRedirects(FALSE);
|
||||
// Set the maximumMetaRefreshCount to zero to make sure the redirect doesn't
|
||||
// happen when doing a drupalGet.
|
||||
$this->maximumMetaRefreshCount = 0;
|
||||
$this->drupalGet('test-meta-refresh');
|
||||
$this->assertNotEmpty($this->cssSelect('meta[http-equiv="refresh"]'));
|
||||
// Allow one redirect to happen.
|
||||
$this->maximumMetaRefreshCount = 1;
|
||||
$this->checkForMetaRefresh();
|
||||
// Check that we are now on the test page.
|
||||
$this->assertSession()->pageTextContains('Test page text.');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+6
-4
@@ -75,10 +75,12 @@ class ContentEntityFormCorrectUserInputMappingOnFieldDeltaElementsTest extends B
|
||||
$storage = $this->container->get('entity_type.manager')->getStorage($this->entityTypeId);
|
||||
|
||||
/** @var ContentEntityInterface $entity */
|
||||
$entity = $storage->create([$this->fieldName => [
|
||||
['shape' => 'rectangle', 'color' => 'green'],
|
||||
['shape' => 'circle', 'color' => 'blue'],
|
||||
]]);
|
||||
$entity = $storage->create([
|
||||
$this->fieldName => [
|
||||
['shape' => 'rectangle', 'color' => 'green'],
|
||||
['shape' => 'circle', 'color' => 'blue'],
|
||||
],
|
||||
]);
|
||||
$entity->save();
|
||||
|
||||
$this->drupalGet($this->entityTypeId . '/manage/' . $entity->id() . '/edit');
|
||||
|
||||
+164
@@ -0,0 +1,164 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\FunctionalTests\Entity;
|
||||
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
use Drupal\Tests\TestFileCreationTrait;
|
||||
|
||||
/**
|
||||
* Tests field validation filtering on content entity forms.
|
||||
*
|
||||
* @group Entity
|
||||
*/
|
||||
class ContentEntityFormFieldValidationFilteringTest extends BrowserTestBase {
|
||||
|
||||
use TestFileCreationTrait;
|
||||
|
||||
/**
|
||||
* The ID of the type of the entity under test.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $entityTypeId;
|
||||
|
||||
/**
|
||||
* The single-valued field name being tested with the entity type.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $fieldNameSingle;
|
||||
|
||||
/**
|
||||
* The multi-valued field name being tested with the entity type.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $fieldNameMultiple;
|
||||
|
||||
/**
|
||||
* The name of the file field being tested with the entity type.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $fieldNameFile;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['entity_test', 'field_test', 'file', 'image'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$web_user = $this->drupalCreateUser(['administer entity_test content']);
|
||||
$this->drupalLogin($web_user);
|
||||
|
||||
// Create two fields of field type "test_field", one with single cardinality
|
||||
// and one with unlimited cardinality on the entity type "entity_test". It
|
||||
// is important to use this field type because its default widget has a
|
||||
// custom \Drupal\Core\Field\WidgetInterface::errorElement() implementation.
|
||||
$this->entityTypeId = 'entity_test';
|
||||
$this->fieldNameSingle = 'test_single';
|
||||
$this->fieldNameMultiple = 'test_multiple';
|
||||
$this->fieldNameFile = 'test_file';
|
||||
|
||||
FieldStorageConfig::create([
|
||||
'field_name' => $this->fieldNameSingle,
|
||||
'entity_type' => $this->entityTypeId,
|
||||
'type' => 'test_field',
|
||||
'cardinality' => 1,
|
||||
])->save();
|
||||
FieldConfig::create([
|
||||
'entity_type' => $this->entityTypeId,
|
||||
'field_name' => $this->fieldNameSingle,
|
||||
'bundle' => $this->entityTypeId,
|
||||
'label' => 'Test single',
|
||||
'required' => TRUE,
|
||||
'translatable' => FALSE,
|
||||
])->save();
|
||||
|
||||
FieldStorageConfig::create([
|
||||
'field_name' => $this->fieldNameMultiple,
|
||||
'entity_type' => $this->entityTypeId,
|
||||
'type' => 'test_field',
|
||||
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
|
||||
])->save();
|
||||
FieldConfig::create([
|
||||
'entity_type' => $this->entityTypeId,
|
||||
'field_name' => $this->fieldNameMultiple,
|
||||
'bundle' => $this->entityTypeId,
|
||||
'label' => 'Test multiple',
|
||||
'translatable' => FALSE,
|
||||
])->save();
|
||||
|
||||
// Also create a file field to test its '#limit_validation_errors'
|
||||
// implementation.
|
||||
FieldStorageConfig::create([
|
||||
'field_name' => $this->fieldNameFile,
|
||||
'entity_type' => $this->entityTypeId,
|
||||
'type' => 'file',
|
||||
'cardinality' => 1,
|
||||
])->save();
|
||||
FieldConfig::create([
|
||||
'entity_type' => $this->entityTypeId,
|
||||
'field_name' => $this->fieldNameFile,
|
||||
'bundle' => $this->entityTypeId,
|
||||
'label' => 'Test file',
|
||||
'translatable' => FALSE,
|
||||
])->save();
|
||||
|
||||
|
||||
entity_get_form_display($this->entityTypeId, $this->entityTypeId, 'default')
|
||||
->setComponent($this->fieldNameSingle, ['type' => 'test_field_widget'])
|
||||
->setComponent($this->fieldNameMultiple, ['type' => 'test_field_widget'])
|
||||
->setComponent($this->fieldNameFile, ['type' => 'file_generic'])
|
||||
->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests field widgets with #limit_validation_errors.
|
||||
*/
|
||||
public function testFieldWidgetsWithLimitedValidationErrors() {
|
||||
$assert_session = $this->assertSession();
|
||||
$this->drupalGet($this->entityTypeId . '/add');
|
||||
|
||||
// The 'Test multiple' field is the only multi-valued field in the form, so
|
||||
// try to add a new item for it. This tests the '#limit_validation_errors'
|
||||
// property set by \Drupal\Core\Field\WidgetBase::formMultipleElements().
|
||||
$assert_session->elementsCount('css', 'div#edit-test-multiple-wrapper div.form-type-textfield input', 1);
|
||||
$this->drupalPostForm(NULL, [], 'Add another item');
|
||||
$assert_session->elementsCount('css', 'div#edit-test-multiple-wrapper div.form-type-textfield input', 2);
|
||||
|
||||
// Now try to upload a file. This tests the '#limit_validation_errors'
|
||||
// property set by
|
||||
// \Drupal\file\Plugin\Field\FieldWidget\FileWidget::process().
|
||||
$text_file = current($this->getTestFiles('text'));
|
||||
$edit = [
|
||||
'files[test_file_0]' => drupal_realpath($text_file->uri)
|
||||
];
|
||||
$assert_session->elementNotExists('css', 'input#edit-test-file-0-remove-button');
|
||||
$this->drupalPostForm(NULL, $edit, 'Upload');
|
||||
$assert_session->elementExists('css', 'input#edit-test-file-0-remove-button');
|
||||
|
||||
// Make the 'Test multiple' field required and check that adding another
|
||||
// item throws a validation error.
|
||||
$field_config = FieldConfig::loadByName($this->entityTypeId, $this->entityTypeId, $this->fieldNameMultiple);
|
||||
$field_config->setRequired(TRUE);
|
||||
$field_config->save();
|
||||
|
||||
$this->drupalPostForm($this->entityTypeId . '/add', [], 'Add another item');
|
||||
$assert_session->pageTextContains('Test multiple (value 1) field is required.');
|
||||
|
||||
// Check that saving the form without entering any value for the required
|
||||
// field still throws the proper validation errors.
|
||||
$this->drupalPostForm(NULL, [], 'Save');
|
||||
$assert_session->pageTextContains('Test single field is required.');
|
||||
$assert_session->pageTextContains('Test multiple (value 1) field is required.');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Drupal\FunctionalTests\HttpKernel;
|
||||
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
@@ -72,6 +73,19 @@ class CorsIntegrationTest extends BrowserTestBase {
|
||||
$this->drupalGet('/test-page', [], ['Origin' => 'http://example.com']);
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
$this->assertSession()->responseHeaderEquals('Access-Control-Allow-Origin', 'http://example.com');
|
||||
|
||||
// Verify POST still functions with 'Origin' header set to site's domain.
|
||||
$origin = \Drupal::request()->getSchemeAndHttpHost();
|
||||
|
||||
/** @var \GuzzleHttp\ClientInterface $httpClient */
|
||||
$httpClient = $this->getSession()->getDriver()->getClient()->getClient();
|
||||
$url = Url::fromUri('base:/test-page');
|
||||
$response = $httpClient->request('POST', $url->setAbsolute()->toString(), [
|
||||
'headers' => [
|
||||
'Origin' => $origin,
|
||||
]
|
||||
]);
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
use Drupal\Tests\TestFileCreationTrait;
|
||||
|
||||
|
||||
/**
|
||||
* Base class for image manipulation testing.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\FunctionalTests\Theme;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests the Bartik theme.
|
||||
*
|
||||
* @group bartik
|
||||
*/
|
||||
class BartikTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->assertTrue($this->container->get('theme_installer')->install(['bartik']));
|
||||
$this->container->get('config.factory')
|
||||
->getEditable('system.theme')
|
||||
->set('default', 'bartik')
|
||||
->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the Bartik theme always adds its message CSS and Classy's.
|
||||
*
|
||||
* @see bartik.libraries.yml
|
||||
* @see classy.info.yml
|
||||
*/
|
||||
public function testRegressionMissingMessagesCss() {
|
||||
$this->drupalGet('');
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
$this->assertSession()->responseContains('bartik/css/components/messages.css');
|
||||
$this->assertSession()->responseContains('classy/css/components/messages.css');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\FunctionalTests\Theme;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests the classy theme.
|
||||
*
|
||||
* @group classy
|
||||
*/
|
||||
class ClassyTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->assertTrue($this->container->get('theme_installer')->install(['classy']));
|
||||
$this->container->get('config.factory')
|
||||
->getEditable('system.theme')
|
||||
->set('default', 'classy')
|
||||
->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the Classy theme always adds its message CSS.
|
||||
*
|
||||
* @see classy.info.yml
|
||||
*/
|
||||
public function testRegressionMissingMessagesCss() {
|
||||
$this->drupalGet('');
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
$this->assertSession()->responseContains('classy/css/components/messages.css');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,436 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\FunctionalTests\Update;
|
||||
|
||||
use Behat\Mink\Driver\GoutteDriver;
|
||||
use Behat\Mink\Mink;
|
||||
use Behat\Mink\Selector\SelectorsHandler;
|
||||
use Behat\Mink\Session;
|
||||
use Drupal\Component\Utility\Crypt;
|
||||
use Drupal\Core\Test\TestRunnerKernel;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
use Drupal\Tests\HiddenFieldSelector;
|
||||
use Drupal\Tests\SchemaCheckTestTrait;
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\Core\Language\Language;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\user\Entity\User;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* Provides a base class for writing an update test.
|
||||
*
|
||||
* To write an update test:
|
||||
* - Write the hook_update_N() implementations that you are testing.
|
||||
* - Create one or more database dump files, which will set the database to the
|
||||
* "before updates" state. Normally, these will add some configuration data to
|
||||
* the database, set up some tables/fields, etc.
|
||||
* - Create a class that extends this class.
|
||||
* - In your setUp() method, point the $this->databaseDumpFiles variable to the
|
||||
* database dump files, and then call parent::setUp() to run the base setUp()
|
||||
* method in this class.
|
||||
* - In your test method, call $this->runUpdates() to run the necessary updates,
|
||||
* and then use test assertions to verify that the result is what you expect.
|
||||
* - In order to test both with a "bare" database dump as well as with a
|
||||
* database dump filled with content, extend your update path test class with
|
||||
* a new test class that overrides the bare database dump. Refer to
|
||||
* UpdatePathTestBaseFilledTest for an example.
|
||||
*
|
||||
* @ingroup update_api
|
||||
*
|
||||
* @see hook_update_N()
|
||||
*/
|
||||
abstract class UpdatePathTestBase extends BrowserTestBase {
|
||||
|
||||
use SchemaCheckTestTrait;
|
||||
|
||||
/**
|
||||
* Modules to enable after the database is loaded.
|
||||
*/
|
||||
protected static $modules = [];
|
||||
|
||||
/**
|
||||
* The file path(s) to the dumped database(s) to load into the child site.
|
||||
*
|
||||
* The file system/tests/fixtures/update/drupal-8.bare.standard.php.gz is
|
||||
* normally included first -- this sets up the base database from a bare
|
||||
* standard Drupal installation.
|
||||
*
|
||||
* The file system/tests/fixtures/update/drupal-8.filled.standard.php.gz
|
||||
* can also be used in case we want to test with a database filled with
|
||||
* content, and with all core modules enabled.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $databaseDumpFiles = [];
|
||||
|
||||
/**
|
||||
* The install profile used in the database dump file.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $installProfile = 'standard';
|
||||
|
||||
/**
|
||||
* Flag that indicates whether the child site has been updated.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $upgradedSite = FALSE;
|
||||
|
||||
/**
|
||||
* Array of errors triggered during the update process.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $upgradeErrors = [];
|
||||
|
||||
/**
|
||||
* Array of modules loaded when the test starts.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $loadedModules = [];
|
||||
|
||||
/**
|
||||
* Flag to indicate whether zlib is installed or not.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $zlibInstalled = TRUE;
|
||||
|
||||
/**
|
||||
* Flag to indicate whether there are pending updates or not.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $pendingUpdates = TRUE;
|
||||
|
||||
/**
|
||||
* The update URL.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $updateUrl;
|
||||
|
||||
/**
|
||||
* Disable strict config schema checking.
|
||||
*
|
||||
* The schema is verified at the end of running the update.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $strictConfigSchema = FALSE;
|
||||
|
||||
/**
|
||||
* Fail the test if there are failed updates.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $checkFailedUpdates = TRUE;
|
||||
|
||||
/**
|
||||
* Constructs an UpdatePathTestCase object.
|
||||
*
|
||||
* @param $test_id
|
||||
* (optional) The ID of the test. Tests with the same id are reported
|
||||
* together.
|
||||
*/
|
||||
public function __construct($test_id = NULL) {
|
||||
parent::__construct($test_id);
|
||||
$this->zlibInstalled = function_exists('gzopen');
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides WebTestBase::setUp() for update testing.
|
||||
*
|
||||
* The main difference in this method is that rather than performing the
|
||||
* installation via the installer, a database is loaded. Additional work is
|
||||
* then needed to set various things such as the config directories and the
|
||||
* container that would normally be done via the installer.
|
||||
*/
|
||||
protected function setUp() {
|
||||
$request = Request::createFromGlobals();
|
||||
|
||||
// Boot up Drupal into a state where calling the database API is possible.
|
||||
// This is used to initialize the database system, so we can load the dump
|
||||
// files.
|
||||
$autoloader = require $this->root . '/autoload.php';
|
||||
$kernel = TestRunnerKernel::createFromRequest($request, $autoloader);
|
||||
$kernel->loadLegacyIncludes();
|
||||
|
||||
$this->changeDatabasePrefix();
|
||||
$this->runDbTasks();
|
||||
// Allow classes to set database dump files.
|
||||
$this->setDatabaseDumpFiles();
|
||||
|
||||
// We are going to set a missing zlib requirement property for usage
|
||||
// during the performUpgrade() and tearDown() methods. Also set that the
|
||||
// tests failed.
|
||||
if (!$this->zlibInstalled) {
|
||||
parent::setUp();
|
||||
return;
|
||||
}
|
||||
// Set the update url. This must be set here rather than in
|
||||
// self::__construct() or the old URL generator will leak additional test
|
||||
// sites.
|
||||
$this->updateUrl = Url::fromRoute('system.db_update');
|
||||
|
||||
$this->setupBaseUrl();
|
||||
|
||||
// Install Drupal test site.
|
||||
$this->prepareEnvironment();
|
||||
$this->installDrupal();
|
||||
|
||||
// Add the config directories to settings.php.
|
||||
drupal_install_config_directories();
|
||||
|
||||
// Set the container. parent::rebuildAll() would normally do this, but this
|
||||
// not safe to do here, because the database has not been updated yet.
|
||||
$this->container = \Drupal::getContainer();
|
||||
|
||||
$this->replaceUser1();
|
||||
|
||||
require_once \Drupal::root() . '/core/includes/update.inc';
|
||||
|
||||
// Setup Mink.
|
||||
$session = $this->initMink();
|
||||
|
||||
$cookies = $this->extractCookiesFromRequest(\Drupal::request());
|
||||
foreach ($cookies as $cookie_name => $values) {
|
||||
foreach ($values as $value) {
|
||||
$session->setCookie($cookie_name, $value);
|
||||
}
|
||||
}
|
||||
|
||||
// Set up the browser test output file.
|
||||
$this->initBrowserOutputFile();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function installDrupal() {
|
||||
$this->initUserSession();
|
||||
$this->prepareSettings();
|
||||
$this->doInstall();
|
||||
$this->initSettings();
|
||||
|
||||
$request = Request::createFromGlobals();
|
||||
$container = $this->initKernel($request);
|
||||
$this->initConfig($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doInstall() {
|
||||
$this->runDbTasks();
|
||||
// Allow classes to set database dump files.
|
||||
$this->setDatabaseDumpFiles();
|
||||
|
||||
// Load the database(s).
|
||||
foreach ($this->databaseDumpFiles as $file) {
|
||||
if (substr($file, -3) == '.gz') {
|
||||
$file = "compress.zlib://$file";
|
||||
}
|
||||
require $file;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function initMink() {
|
||||
$driver = $this->getDefaultDriverInstance();
|
||||
|
||||
if ($driver instanceof GoutteDriver) {
|
||||
// Turn off curl timeout. Having a timeout is not a problem in a normal
|
||||
// test running, but it is a problem when debugging. Also, disable SSL
|
||||
// peer verification so that testing under HTTPS always works.
|
||||
/** @var \GuzzleHttp\Client $client */
|
||||
$client = $this->container->get('http_client_factory')->fromOptions([
|
||||
'timeout' => NULL,
|
||||
'verify' => FALSE,
|
||||
]);
|
||||
|
||||
// Inject a Guzzle middleware to generate debug output for every request
|
||||
// performed in the test.
|
||||
$handler_stack = $client->getConfig('handler');
|
||||
$handler_stack->push($this->getResponseLogHandler());
|
||||
|
||||
$driver->getClient()->setClient($client);
|
||||
}
|
||||
|
||||
$selectors_handler = new SelectorsHandler([
|
||||
'hidden_field_selector' => new HiddenFieldSelector()
|
||||
]);
|
||||
$session = new Session($driver, $selectors_handler);
|
||||
$this->mink = new Mink();
|
||||
$this->mink->registerSession('default', $session);
|
||||
$this->mink->setDefaultSessionName('default');
|
||||
$this->registerSessions();
|
||||
|
||||
return $session;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set database dump files to be used.
|
||||
*/
|
||||
abstract protected function setDatabaseDumpFiles();
|
||||
|
||||
/**
|
||||
* Add settings that are missed since the installer isn't run.
|
||||
*/
|
||||
protected function prepareSettings() {
|
||||
parent::prepareSettings();
|
||||
|
||||
// Remember the profile which was used.
|
||||
$settings['settings']['install_profile'] = (object) [
|
||||
'value' => $this->installProfile,
|
||||
'required' => TRUE,
|
||||
];
|
||||
// Generate a hash salt.
|
||||
$settings['settings']['hash_salt'] = (object) [
|
||||
'value' => Crypt::randomBytesBase64(55),
|
||||
'required' => TRUE,
|
||||
];
|
||||
|
||||
// Since the installer isn't run, add the database settings here too.
|
||||
$settings['databases']['default'] = (object) [
|
||||
'value' => Database::getConnectionInfo(),
|
||||
'required' => TRUE,
|
||||
];
|
||||
|
||||
$this->writeSettings($settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to run pending database updates.
|
||||
*/
|
||||
protected function runUpdates() {
|
||||
if (!$this->zlibInstalled) {
|
||||
$this->fail('Missing zlib requirement for update tests.');
|
||||
return FALSE;
|
||||
}
|
||||
// The site might be broken at the time so logging in using the UI might
|
||||
// not work, so we use the API itself.
|
||||
drupal_rewrite_settings([
|
||||
'settings' => [
|
||||
'update_free_access' => (object) [
|
||||
'value' => TRUE,
|
||||
'required' => TRUE,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->drupalGet($this->updateUrl);
|
||||
$this->clickLink(t('Continue'));
|
||||
|
||||
$this->doSelectionTest();
|
||||
// Run the update hooks.
|
||||
$this->clickLink(t('Apply pending updates'));
|
||||
$this->checkForMetaRefresh();
|
||||
|
||||
// Ensure there are no failed updates.
|
||||
if ($this->checkFailedUpdates) {
|
||||
$this->assertNoRaw('<strong>' . t('Failed:') . '</strong>');
|
||||
|
||||
// Ensure that there are no pending updates.
|
||||
foreach (['update', 'post_update'] as $update_type) {
|
||||
switch ($update_type) {
|
||||
case 'update':
|
||||
$all_updates = update_get_update_list();
|
||||
break;
|
||||
case 'post_update':
|
||||
$all_updates = \Drupal::service('update.post_update_registry')->getPendingUpdateInformation();
|
||||
break;
|
||||
}
|
||||
foreach ($all_updates as $module => $updates) {
|
||||
if (!empty($updates['pending'])) {
|
||||
foreach (array_keys($updates['pending']) as $update_name) {
|
||||
$this->fail("The $update_name() update function from the $module module did not run.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Reset the static cache of drupal_get_installed_schema_version() so that
|
||||
// more complex update path testing works.
|
||||
drupal_static_reset('drupal_get_installed_schema_version');
|
||||
|
||||
// The config schema can be incorrect while the update functions are being
|
||||
// executed. But once the update has been completed, it needs to be valid
|
||||
// again. Assert the schema of all configuration objects now.
|
||||
$names = $this->container->get('config.storage')->listAll();
|
||||
/** @var \Drupal\Core\Config\TypedConfigManagerInterface $typed_config */
|
||||
$typed_config = $this->container->get('config.typed');
|
||||
$typed_config->clearCachedDefinitions();
|
||||
foreach ($names as $name) {
|
||||
$config = $this->config($name);
|
||||
$this->assertConfigSchema($typed_config, $name, $config->get());
|
||||
}
|
||||
|
||||
// Ensure that the update hooks updated all entity schema.
|
||||
$needs_updates = \Drupal::entityDefinitionUpdateManager()->needsUpdates();
|
||||
$this->assertFalse($needs_updates, 'After all updates ran, entity schema is up to date.');
|
||||
if ($needs_updates) {
|
||||
foreach (\Drupal::entityDefinitionUpdateManager()
|
||||
->getChangeSummary() as $entity_type_id => $summary) {
|
||||
foreach ($summary as $message) {
|
||||
$this->fail($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the install database tasks for the driver used by the test runner.
|
||||
*/
|
||||
protected function runDbTasks() {
|
||||
// Create a minimal container so that t() works.
|
||||
// @see install_begin_request()
|
||||
$container = new ContainerBuilder();
|
||||
$container->setParameter('language.default_values', Language::$defaultValues);
|
||||
$container
|
||||
->register('language.default', 'Drupal\Core\Language\LanguageDefault')
|
||||
->addArgument('%language.default_values%');
|
||||
$container
|
||||
->register('string_translation', 'Drupal\Core\StringTranslation\TranslationManager')
|
||||
->addArgument(new Reference('language.default'));
|
||||
\Drupal::setContainer($container);
|
||||
|
||||
require_once __DIR__ . '/../../../../includes/install.inc';
|
||||
$connection = Database::getConnection();
|
||||
$errors = db_installer_object($connection->driver())->runTasks();
|
||||
if (!empty($errors)) {
|
||||
$this->fail('Failed to run installer database tasks: ' . implode(', ', $errors));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace User 1 with the user created here.
|
||||
*/
|
||||
protected function replaceUser1() {
|
||||
/** @var \Drupal\user\UserInterface $account */
|
||||
// @todo: Saving the account before the update is problematic.
|
||||
// https://www.drupal.org/node/2560237
|
||||
$account = User::load(1);
|
||||
$account->setPassword($this->rootUser->pass_raw);
|
||||
$account->setEmail($this->rootUser->getEmail());
|
||||
$account->setUsername($this->rootUser->getUsername());
|
||||
$account->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the selection page.
|
||||
*/
|
||||
protected function doSelectionTest() {
|
||||
// No-op. Tests wishing to do test the selection page or the general
|
||||
// update.php environment before running update.php can override this method
|
||||
// and implement their required tests.
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\FunctionalTests\Update;
|
||||
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
|
||||
/**
|
||||
* Tests the update path base class.
|
||||
*
|
||||
* @group Update
|
||||
*/
|
||||
class UpdatePathTestBaseTest extends UpdatePathTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $modules = ['update_test_schema'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setDatabaseDumpFiles() {
|
||||
$this->databaseDumpFiles = [
|
||||
__DIR__ . '/../../../../modules/system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
|
||||
__DIR__ . '/../../../../modules/system/tests/fixtures/update/drupal-8.update-test-schema-enabled.php',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the database was properly loaded.
|
||||
*/
|
||||
public function testDatabaseLoaded() {
|
||||
foreach (['user', 'node', 'system', 'update_test_schema'] as $module) {
|
||||
$this->assertEqual(drupal_get_installed_schema_version($module), 8000, SafeMarkup::format('Module @module schema is 8000', ['@module' => $module]));
|
||||
}
|
||||
|
||||
// Ensure that all {router} entries can be unserialized. If they cannot be
|
||||
// unserialized a notice will be thrown by PHP.
|
||||
|
||||
$result = \Drupal::database()->query("SELECT name, route from {router}")->fetchAllKeyed(0, 1);
|
||||
// For the purpose of fetching the notices and displaying more helpful error
|
||||
// messages, let's override the error handler temporarily.
|
||||
set_error_handler(function ($severity, $message, $filename, $lineno) {
|
||||
throw new \ErrorException($message, 0, $severity, $filename, $lineno);
|
||||
});
|
||||
foreach ($result as $route_name => $route) {
|
||||
try {
|
||||
unserialize($route);
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$this->fail(sprintf('Error "%s" while unserializing route %s', $e->getMessage(), Html::escape($route_name)));
|
||||
}
|
||||
}
|
||||
restore_error_handler();
|
||||
|
||||
// Before accessing the site we need to run updates first or the site might
|
||||
// be broken.
|
||||
$this->runUpdates();
|
||||
$this->assertEqual(\Drupal::config('system.site')->get('name'), 'Site-Install');
|
||||
$this->drupalGet('<front>');
|
||||
$this->assertText('Site-Install');
|
||||
|
||||
// Ensure that the database tasks have been run during set up. Neither MySQL
|
||||
// nor SQLite make changes that are testable.
|
||||
$database = $this->container->get('database');
|
||||
if ($database->driver() == 'pgsql') {
|
||||
$this->assertEqual('on', $database->query("SHOW standard_conforming_strings")->fetchField());
|
||||
$this->assertEqual('escape', $database->query("SHOW bytea_output")->fetchField());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that updates are properly run.
|
||||
*/
|
||||
public function testUpdateHookN() {
|
||||
// Increment the schema version.
|
||||
\Drupal::state()->set('update_test_schema_version', 8001);
|
||||
$this->runUpdates();
|
||||
|
||||
$select = \Drupal::database()->select('watchdog');
|
||||
$select->orderBy('wid', 'DESC');
|
||||
$select->range(0, 5);
|
||||
$select->fields('watchdog', ['message']);
|
||||
|
||||
$container_cannot_be_saved_messages = array_filter(iterator_to_array($select->execute()), function ($row) {
|
||||
return strpos($row->message, 'Container cannot be saved to cache.') !== FALSE;
|
||||
});
|
||||
$this->assertEqual([], $container_cannot_be_saved_messages);
|
||||
|
||||
// Ensure schema has changed.
|
||||
$this->assertEqual(drupal_get_installed_schema_version('update_test_schema', TRUE), 8001);
|
||||
// Ensure the index was added for column a.
|
||||
$this->assertTrue(db_index_exists('update_test_schema_table', 'test'), 'Version 8001 of the update_test_schema module is installed.');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user