Update Composer, update everything
This commit is contained in:
parent
ea3e94409f
commit
dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions
File diff suppressed because it is too large
Load diff
|
@ -2,34 +2,18 @@
|
|||
|
||||
namespace Drupal\simpletest;
|
||||
|
||||
use Drupal\Component\Render\MarkupInterface;
|
||||
use Drupal\Tests\AssertHelperTrait as BaseAssertHelperTrait;
|
||||
|
||||
/**
|
||||
* Provides helper methods for assertions.
|
||||
*
|
||||
* @deprecated in Drupal 8.4.x. Will be removed before Drupal 9.0.0. Use
|
||||
* Drupal\Tests\AssertHelperTrait instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2884454
|
||||
*/
|
||||
trait AssertHelperTrait {
|
||||
|
||||
/**
|
||||
* Casts MarkupInterface objects into strings.
|
||||
*
|
||||
* @param string|array $value
|
||||
* The value to act on.
|
||||
*
|
||||
* @return mixed
|
||||
* The input value, with MarkupInterface objects casted to string.
|
||||
*/
|
||||
protected static function castSafeStrings($value) {
|
||||
if ($value instanceof MarkupInterface) {
|
||||
$value = (string) $value;
|
||||
}
|
||||
if (is_array($value)) {
|
||||
array_walk_recursive($value, function (&$item) {
|
||||
if ($item instanceof MarkupInterface) {
|
||||
$item = (string) $item;
|
||||
}
|
||||
});
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
use BaseAssertHelperTrait;
|
||||
|
||||
}
|
||||
|
|
|
@ -2,66 +2,20 @@
|
|||
|
||||
namespace Drupal\simpletest;
|
||||
|
||||
use Drupal\block\Entity\Block;
|
||||
use Drupal\Tests\block\Traits\BlockCreationTrait as BaseBlockCreationTrait;
|
||||
|
||||
/**
|
||||
* Provides methods to create and place block with default settings.
|
||||
*
|
||||
* This trait is meant to be used only by test classes.
|
||||
*
|
||||
* @deprecated in Drupal 8.4.x. Will be removed before Drupal 9.0.0. Use
|
||||
* \Drupal\Tests\block\Traits\BlockCreationTrait instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2884454
|
||||
*/
|
||||
trait BlockCreationTrait {
|
||||
|
||||
/**
|
||||
* Creates a block instance based on default settings.
|
||||
*
|
||||
* @param string $plugin_id
|
||||
* The plugin ID of the block type for this block instance.
|
||||
* @param array $settings
|
||||
* (optional) An associative array of settings for the block entity.
|
||||
* Override the defaults by specifying the key and value in the array, for
|
||||
* example:
|
||||
* @code
|
||||
* $this->drupalPlaceBlock('system_powered_by_block', array(
|
||||
* 'label' => t('Hello, world!'),
|
||||
* ));
|
||||
* @endcode
|
||||
* The following defaults are provided:
|
||||
* - label: Random string.
|
||||
* - ID: Random string.
|
||||
* - region: 'sidebar_first'.
|
||||
* - theme: The default theme.
|
||||
* - visibility: Empty array.
|
||||
*
|
||||
* @return \Drupal\block\Entity\Block
|
||||
* The block entity.
|
||||
*
|
||||
* @todo
|
||||
* Add support for creating custom block instances.
|
||||
*/
|
||||
protected function placeBlock($plugin_id, array $settings = []) {
|
||||
$config = \Drupal::configFactory();
|
||||
$settings += [
|
||||
'plugin' => $plugin_id,
|
||||
'region' => 'sidebar_first',
|
||||
'id' => strtolower($this->randomMachineName(8)),
|
||||
'theme' => $config->get('system.theme')->get('default'),
|
||||
'label' => $this->randomMachineName(8),
|
||||
'visibility' => [],
|
||||
'weight' => 0,
|
||||
];
|
||||
$values = [];
|
||||
foreach (['region', 'id', 'theme', 'plugin', 'weight', 'visibility'] as $key) {
|
||||
$values[$key] = $settings[$key];
|
||||
// Remove extra values that do not belong in the settings array.
|
||||
unset($settings[$key]);
|
||||
}
|
||||
foreach ($values['visibility'] as $id => $visibility) {
|
||||
$values['visibility'][$id]['id'] = $id;
|
||||
}
|
||||
$values['settings'] = $settings;
|
||||
$block = Block::create($values);
|
||||
$block->save();
|
||||
return $block;
|
||||
}
|
||||
use BaseBlockCreationTrait;
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\simpletest\Cache\Context;
|
||||
|
||||
use Drupal\Core\Cache\CacheableMetadata;
|
||||
use Drupal\Core\Cache\Context\CacheContextInterface;
|
||||
use Drupal\Core\PrivateKey;
|
||||
use Drupal\Core\Site\Settings;
|
||||
use Drupal\simpletest\TestDiscovery;
|
||||
|
||||
/**
|
||||
* Defines the TestDiscoveryCacheContext service.
|
||||
*
|
||||
* Cache context ID: 'test_discovery'.
|
||||
*/
|
||||
class TestDiscoveryCacheContext implements CacheContextInterface {
|
||||
|
||||
/**
|
||||
* The test discovery service.
|
||||
*
|
||||
* @var \Drupal\simpletest\TestDiscovery
|
||||
*/
|
||||
protected $testDiscovery;
|
||||
|
||||
/**
|
||||
* The private key service.
|
||||
*
|
||||
* @var \Drupal\Core\PrivateKey
|
||||
*/
|
||||
protected $privateKey;
|
||||
|
||||
/**
|
||||
* The hash of discovered test information.
|
||||
*
|
||||
* Services should not be stateful, but we only keep this information per
|
||||
* request. That way we don't perform a file scan every time we need this
|
||||
* hash. The test scan results are unlikely to change during the request.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $hash;
|
||||
|
||||
/**
|
||||
* Construct a test discovery cache context.
|
||||
*
|
||||
* @param \Drupal\simpletest\TestDiscovery $test_discovery
|
||||
* The test discovery service.
|
||||
* @param \Drupal\Core\PrivateKey $private_key
|
||||
* The private key service.
|
||||
*/
|
||||
public function __construct(TestDiscovery $test_discovery, PrivateKey $private_key) {
|
||||
$this->testDiscovery = $test_discovery;
|
||||
$this->privateKey = $private_key;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getLabel() {
|
||||
return t('Test discovery');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getContext() {
|
||||
if (empty($this->hash)) {
|
||||
$tests = $this->testDiscovery->getTestClasses();
|
||||
$this->hash = $this->hash(serialize($tests));
|
||||
}
|
||||
return $this->hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCacheableMetadata() {
|
||||
return new CacheableMetadata();
|
||||
}
|
||||
|
||||
/**
|
||||
* Hashes the given string.
|
||||
*
|
||||
* @param string $identifier
|
||||
* The string to be hashed.
|
||||
*
|
||||
* @return string
|
||||
* The hash.
|
||||
*/
|
||||
protected function hash($identifier) {
|
||||
return hash('sha256', $this->privateKey->get() . Settings::getHashSalt() . $identifier);
|
||||
}
|
||||
|
||||
}
|
|
@ -2,52 +2,20 @@
|
|||
|
||||
namespace Drupal\simpletest;
|
||||
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
use Drupal\Tests\node\Traits\ContentTypeCreationTrait as BaseContentTypeCreationTrait;
|
||||
|
||||
/**
|
||||
* Provides methods to create content type from given values.
|
||||
*
|
||||
* This trait is meant to be used only by test classes.
|
||||
*
|
||||
* @deprecated in Drupal 8.4.x. Will be removed before Drupal 9.0.0. Use
|
||||
* \Drupal\Tests\node\Traits\ContentTypeCreationTrait instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2884454
|
||||
*/
|
||||
trait ContentTypeCreationTrait {
|
||||
|
||||
/**
|
||||
* Creates a custom content type based on default settings.
|
||||
*
|
||||
* @param array $values
|
||||
* An array of settings to change from the defaults.
|
||||
* Example: 'type' => 'foo'.
|
||||
*
|
||||
* @return \Drupal\node\Entity\NodeType
|
||||
* Created content type.
|
||||
*/
|
||||
protected function createContentType(array $values = []) {
|
||||
// Find a non-existent random type name.
|
||||
if (!isset($values['type'])) {
|
||||
do {
|
||||
$id = strtolower($this->randomMachineName(8));
|
||||
} while (NodeType::load($id));
|
||||
}
|
||||
else {
|
||||
$id = $values['type'];
|
||||
}
|
||||
$values += [
|
||||
'type' => $id,
|
||||
'name' => $id,
|
||||
];
|
||||
$type = NodeType::create($values);
|
||||
$status = $type->save();
|
||||
node_add_body_field($type);
|
||||
|
||||
if ($this instanceof \PHPUnit_Framework_TestCase) {
|
||||
$this->assertSame($status, SAVED_NEW, (new FormattableMarkup('Created content type %type.', ['%type' => $type->id()]))->__toString());
|
||||
}
|
||||
else {
|
||||
$this->assertEqual($status, SAVED_NEW, (new FormattableMarkup('Created content type %type.', ['%type' => $type->id()]))->__toString());
|
||||
}
|
||||
|
||||
return $type;
|
||||
}
|
||||
use BaseContentTypeCreationTrait;
|
||||
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@ use Symfony\Component\HttpFoundation\RedirectResponse;
|
|||
* Note that the UI strings are not translated because this form is also used
|
||||
* from run-tests.sh.
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @see simpletest_script_open_browser()
|
||||
* @see run-tests.sh
|
||||
*/
|
||||
|
@ -110,7 +112,7 @@ class SimpletestResultsForm extends FormBase {
|
|||
// performed.
|
||||
$results = [];
|
||||
if (is_numeric($test_id) && !$results = $this->getResults($test_id)) {
|
||||
drupal_set_message($this->t('No test results to display.'), 'error');
|
||||
$this->messenger()->addError($this->t('No test results to display.'));
|
||||
return new RedirectResponse($this->url('simpletest.test_form', [], ['absolute' => TRUE]));
|
||||
}
|
||||
|
||||
|
@ -235,7 +237,7 @@ class SimpletestResultsForm extends FormBase {
|
|||
*
|
||||
* @param array $form
|
||||
* The form to attach the results to.
|
||||
* @param array $test_results
|
||||
* @param array $results
|
||||
* The simpletest results.
|
||||
*
|
||||
* @return array
|
||||
|
@ -288,7 +290,7 @@ class SimpletestResultsForm extends FormBase {
|
|||
'Filename',
|
||||
'Line',
|
||||
'Function',
|
||||
['colspan' => 2, 'data' => 'Status']
|
||||
['colspan' => 2, 'data' => 'Status'],
|
||||
];
|
||||
$form['result']['results'] = [];
|
||||
foreach ($test_results as $group => $assertions) {
|
||||
|
|
|
@ -7,6 +7,8 @@ use Drupal\Core\Form\FormStateInterface;
|
|||
|
||||
/**
|
||||
* Configure simpletest settings for this site.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class SimpletestSettingsForm extends ConfigFormBase {
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|||
|
||||
/**
|
||||
* List tests arranged in groups that can be selected and run.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class SimpletestTestForm extends FormBase {
|
||||
|
||||
|
@ -71,7 +73,7 @@ class SimpletestTestForm extends FormBase {
|
|||
$form['clean'] = [
|
||||
'#type' => 'fieldset',
|
||||
'#title' => $this->t('Clean test environment'),
|
||||
'#description' => $this->t('Remove tables with the prefix "simpletest" and temporary directories that are left over from tests that crashed. This is intended for developers when creating tests.'),
|
||||
'#description' => $this->t('Remove tables with the prefix "test" followed by digits and temporary directories that are left over from tests that crashed. This is intended for developers when creating tests.'),
|
||||
'#weight' => 200,
|
||||
];
|
||||
$form['clean']['op'] = [
|
||||
|
@ -108,6 +110,10 @@ class SimpletestTestForm extends FormBase {
|
|||
];
|
||||
|
||||
$form['tests'] = [
|
||||
'#cache' => [
|
||||
'keys' => ['simpletest_ui_table'],
|
||||
'contexts' => ['test_discovery'],
|
||||
],
|
||||
'#type' => 'table',
|
||||
'#id' => 'simpletest-form-table',
|
||||
'#tableselect' => TRUE,
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Drupal\simpletest;
|
||||
|
||||
@trigger_error(__NAMESPACE__ . '\InstallerTestBase is deprecated in Drupal 8.6.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\FunctionalTests\Installer\InstallerTestBase, see https://www.drupal.org/node/2988752.', E_USER_DEPRECATED);
|
||||
|
||||
use Drupal\Core\DrupalKernel;
|
||||
use Drupal\Core\Language\Language;
|
||||
use Drupal\Core\Session\UserSession;
|
||||
|
@ -13,6 +15,10 @@ use Symfony\Component\HttpFoundation\RequestStack;
|
|||
|
||||
/**
|
||||
* Base class for testing the interactive installer.
|
||||
*
|
||||
* @deprecated in Drupal 8.6.0 and will be removed before Drupal 9.0.0.
|
||||
* Use \Drupal\FunctionalTests\Installer\InstallerTestBase. See
|
||||
* https://www.drupal.org/node/2988752
|
||||
*/
|
||||
abstract class InstallerTestBase extends WebTestBase {
|
||||
|
||||
|
@ -122,6 +128,9 @@ abstract class InstallerTestBase extends WebTestBase {
|
|||
// Select profile.
|
||||
$this->setUpProfile();
|
||||
|
||||
// Address the requirements problem screen, if any.
|
||||
$this->setUpRequirementsProblem();
|
||||
|
||||
// Configure settings.
|
||||
$this->setUpSettings();
|
||||
|
||||
|
@ -195,6 +204,23 @@ abstract class InstallerTestBase extends WebTestBase {
|
|||
$this->drupalPostForm(NULL, $edit, $this->translations['Save and continue']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Installer step: Requirements problem.
|
||||
*
|
||||
* Override this method to test specific requirements warnings or errors
|
||||
* during the installer.
|
||||
*
|
||||
* @see system_requirements()
|
||||
*/
|
||||
protected function setUpRequirementsProblem() {
|
||||
// By default, skip the "recommended PHP version" warning on older test
|
||||
// environments. This allows the installer to be tested consistently on
|
||||
// both recommended PHP versions and older (but still supported) versions.
|
||||
if (version_compare(phpversion(), '7.0') < 0) {
|
||||
$this->continueOnExpectedWarnings(['PHP']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Final installer step: Configure site.
|
||||
*/
|
||||
|
@ -218,4 +244,44 @@ abstract class InstallerTestBase extends WebTestBase {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Continues installation when an expected warning is found.
|
||||
*
|
||||
* @param string[] $expected_warnings
|
||||
* A list of warning summaries to expect on the requirements screen (e.g.
|
||||
* 'PHP', 'PHP OPcode caching', etc.). If only the expected warnings
|
||||
* are found, the test will click the "continue anyway" link to go to the
|
||||
* next screen of the installer. If an expected warning is not found, or if
|
||||
* a warning not in the list is present, a fail is raised.
|
||||
*/
|
||||
protected function continueOnExpectedWarnings($expected_warnings = []) {
|
||||
// Don't try to continue if there are errors.
|
||||
if (strpos($this->getTextContent(), 'Errors found') !== FALSE) {
|
||||
return;
|
||||
}
|
||||
// Allow only details elements that are directly after the warning header
|
||||
// or each other. There is no guaranteed wrapper we can rely on across
|
||||
// distributions. When there are multiple warnings, the selectors will be:
|
||||
// - h3#warning+details summary
|
||||
// - h3#warning+details+details summary
|
||||
// - etc.
|
||||
// We add one more selector than expected warnings to confirm that there
|
||||
// isn't any other warning before clicking the link.
|
||||
// @todo Make this more reliable in
|
||||
// https://www.drupal.org/project/drupal/issues/2927345.
|
||||
$selectors = [];
|
||||
for ($i = 0; $i <= count($expected_warnings); $i++) {
|
||||
$selectors[] = 'h3#warning' . implode('', array_fill(0, $i + 1, '+details')) . ' summary';
|
||||
}
|
||||
$warning_elements = $this->cssSelect(implode(', ', $selectors));
|
||||
|
||||
// Confirm that there are only the expected warnings.
|
||||
$warnings = [];
|
||||
foreach ($warning_elements as $warning) {
|
||||
$warnings[] = trim((string) $warning);
|
||||
}
|
||||
$this->assertEqual($expected_warnings, $warnings);
|
||||
$this->clickLink('continue anyway');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace Drupal\simpletest;
|
||||
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\Component\Utility\Variable;
|
||||
use Drupal\Core\Config\Development\ConfigSchemaChecker;
|
||||
use Drupal\Core\Database\Database;
|
||||
|
@ -14,28 +14,54 @@ use Drupal\Core\Extension\ExtensionDiscovery;
|
|||
use Drupal\Core\KeyValueStore\KeyValueMemoryFactory;
|
||||
use Drupal\Core\Language\Language;
|
||||
use Drupal\Core\Site\Settings;
|
||||
use Drupal\KernelTests\TestServiceProvider;
|
||||
use Symfony\Component\DependencyInjection\Parameter;
|
||||
use Drupal\Core\StreamWrapper\StreamWrapperInterface;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* Base class for integration tests.
|
||||
* Base class for functional integration tests.
|
||||
*
|
||||
* Tests extending this base class can access files and the database, but the
|
||||
* entire environment is initially empty. Drupal runs in a minimal mocked
|
||||
* environment, comparable to the one in the early installer.
|
||||
* This base class should be useful for testing some types of integrations which
|
||||
* don't require the overhead of a fully-installed Drupal instance, but which
|
||||
* have many dependencies on parts of Drupal which can't or shouldn't be mocked.
|
||||
*
|
||||
* The module/hook system is functional and operates on a fixed module list.
|
||||
* Additional modules needed in a test may be loaded and added to the fixed
|
||||
* module list.
|
||||
* This base class partially boots a fixture Drupal. The state of the fixture
|
||||
* Drupal is comparable to the state of a system during the early part of the
|
||||
* installation process.
|
||||
*
|
||||
* Tests extending this base class can access services and the database, but the
|
||||
* system is initially empty. This Drupal runs in a minimal mocked filesystem
|
||||
* which operates within vfsStream.
|
||||
*
|
||||
* Modules specified in the $modules property are added to the service container
|
||||
* for each test. The module/hook system is functional. Additional modules
|
||||
* needed in a test should override $modules. Modules specified in this way will
|
||||
* be added to those specified in superclasses.
|
||||
*
|
||||
* Unlike \Drupal\Tests\BrowserTestBase, the modules are not installed. They are
|
||||
* loaded such that their services and hooks are available, but the install
|
||||
* process has not been performed.
|
||||
*
|
||||
* Other modules can be made available in this way using
|
||||
* KernelTestBase::enableModules().
|
||||
*
|
||||
* Some modules can be brought into a fully-installed state using
|
||||
* KernelTestBase::installConfig(), KernelTestBase::installSchema(), and
|
||||
* KernelTestBase::installEntitySchema(). Alternately, tests which need modules
|
||||
* to be fully installed could inherit from \Drupal\Tests\BrowserTestBase.
|
||||
*
|
||||
* @see \Drupal\Tests\KernelTestBase::$modules
|
||||
* @see \Drupal\Tests\KernelTestBase::enableModules()
|
||||
* @see \Drupal\Tests\KernelTestBase::installConfig()
|
||||
* @see \Drupal\Tests\KernelTestBase::installEntitySchema()
|
||||
* @see \Drupal\Tests\KernelTestBase::installSchema()
|
||||
* @see \Drupal\Tests\BrowserTestBase
|
||||
*
|
||||
* @deprecated in Drupal 8.0.x, will be removed before Drupal 9.0.0. Use
|
||||
* \Drupal\KernelTests\KernelTestBase instead.
|
||||
*
|
||||
* @see \Drupal\simpletest\KernelTestBase::$modules
|
||||
* @see \Drupal\simpletest\KernelTestBase::enableModules()
|
||||
*
|
||||
* @ingroup testing
|
||||
*/
|
||||
abstract class KernelTestBase extends TestBase {
|
||||
|
@ -76,7 +102,7 @@ abstract class KernelTestBase extends TestBase {
|
|||
/**
|
||||
* A KeyValueMemoryFactory instance to use when building the container.
|
||||
*
|
||||
* @var \Drupal\Core\KeyValueStore\KeyValueMemoryFactory.
|
||||
* @var \Drupal\Core\KeyValueStore\KeyValueMemoryFactory
|
||||
*/
|
||||
protected $keyValueFactory;
|
||||
|
||||
|
@ -121,7 +147,7 @@ abstract class KernelTestBase extends TestBase {
|
|||
$path = $this->siteDirectory . '/config_' . CONFIG_SYNC_DIRECTORY;
|
||||
$GLOBALS['config_directories'][CONFIG_SYNC_DIRECTORY] = $path;
|
||||
// Ensure the directory can be created and is writeable.
|
||||
if (!install_ensure_config_directory(CONFIG_SYNC_DIRECTORY)) {
|
||||
if (!file_prepare_directory($path, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
|
||||
throw new \RuntimeException("Failed to create '" . CONFIG_SYNC_DIRECTORY . "' config directory $path");
|
||||
}
|
||||
// Provide the already resolved path for tests.
|
||||
|
@ -173,7 +199,7 @@ EOD;
|
|||
|
||||
// Add this test class as a service provider.
|
||||
// @todo Remove the indirection; implement ServiceProviderInterface instead.
|
||||
$GLOBALS['conf']['container_service_providers']['TestServiceProvider'] = 'Drupal\simpletest\TestServiceProvider';
|
||||
$GLOBALS['conf']['container_service_providers']['TestServiceProvider'] = TestServiceProvider::class;
|
||||
|
||||
// Bootstrap a new kernel.
|
||||
$class_loader = require DRUPAL_ROOT . '/autoload.php';
|
||||
|
@ -201,7 +227,6 @@ EOD;
|
|||
$this->kernel->shutdown();
|
||||
$this->kernel->boot();
|
||||
|
||||
|
||||
// Save the original site directory path, so that extensions in the
|
||||
// site-specific directory can still be discovered in the test site
|
||||
// environment.
|
||||
|
@ -453,8 +478,6 @@ EOD;
|
|||
]));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Installs the storage schema for a specific entity type.
|
||||
*
|
||||
|
@ -476,7 +499,7 @@ EOD;
|
|||
$all_tables_exist = TRUE;
|
||||
foreach ($tables as $table) {
|
||||
if (!$db_schema->tableExists($table)) {
|
||||
$this->fail(SafeMarkup::format('Installed entity type table for the %entity_type entity type: %table', [
|
||||
$this->fail(new FormattableMarkup('Installed entity type table for the %entity_type entity type: %table', [
|
||||
'%entity_type' => $entity_type_id,
|
||||
'%table' => $table,
|
||||
]));
|
||||
|
@ -484,7 +507,7 @@ EOD;
|
|||
}
|
||||
}
|
||||
if ($all_tables_exist) {
|
||||
$this->pass(SafeMarkup::format('Installed entity type tables for the %entity_type entity type: %tables', [
|
||||
$this->pass(new FormattableMarkup('Installed entity type tables for the %entity_type entity type: %tables', [
|
||||
'%entity_type' => $entity_type_id,
|
||||
'%tables' => '{' . implode('}, {', $tables) . '}',
|
||||
]));
|
||||
|
|
|
@ -2,83 +2,20 @@
|
|||
|
||||
namespace Drupal\simpletest;
|
||||
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\Tests\node\Traits\NodeCreationTrait as BaseNodeCreationTrait;
|
||||
|
||||
/**
|
||||
* Provides methods to create node based on default settings.
|
||||
*
|
||||
* This trait is meant to be used only by test classes.
|
||||
*
|
||||
* @deprecated in Drupal 8.4.x. Will be removed before Drupal 9.0.0. Use
|
||||
* \Drupal\Tests\node\Traits\NodeCreationTrait instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2884454
|
||||
*/
|
||||
trait NodeCreationTrait {
|
||||
|
||||
/**
|
||||
* Get a node from the database based on its title.
|
||||
*
|
||||
* @param string|\Drupal\Component\Render\MarkupInterface $title
|
||||
* A node title, usually generated by $this->randomMachineName().
|
||||
* @param $reset
|
||||
* (optional) Whether to reset the entity cache.
|
||||
*
|
||||
* @return \Drupal\node\NodeInterface
|
||||
* A node entity matching $title.
|
||||
*/
|
||||
public function getNodeByTitle($title, $reset = FALSE) {
|
||||
if ($reset) {
|
||||
\Drupal::entityTypeManager()->getStorage('node')->resetCache();
|
||||
}
|
||||
// Cast MarkupInterface objects to string.
|
||||
$title = (string) $title;
|
||||
$nodes = \Drupal::entityTypeManager()
|
||||
->getStorage('node')
|
||||
->loadByProperties(['title' => $title]);
|
||||
// Load the first node returned from the database.
|
||||
$returned_node = reset($nodes);
|
||||
return $returned_node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a node based on default settings.
|
||||
*
|
||||
* @param array $settings
|
||||
* (optional) An associative array of settings for the node, as used in
|
||||
* entity_create(). Override the defaults by specifying the key and value
|
||||
* in the array, for example:
|
||||
* @code
|
||||
* $this->drupalCreateNode(array(
|
||||
* 'title' => t('Hello, world!'),
|
||||
* 'type' => 'article',
|
||||
* ));
|
||||
* @endcode
|
||||
* The following defaults are provided:
|
||||
* - body: Random string using the default filter format:
|
||||
* @code
|
||||
* $settings['body'][0] = array(
|
||||
* 'value' => $this->randomMachineName(32),
|
||||
* 'format' => filter_default_format(),
|
||||
* );
|
||||
* @endcode
|
||||
* - title: Random string.
|
||||
* - type: 'page'.
|
||||
* - uid: The currently logged in user, or anonymous.
|
||||
*
|
||||
* @return \Drupal\node\NodeInterface
|
||||
* The created node entity.
|
||||
*/
|
||||
protected function createNode(array $settings = []) {
|
||||
// Populate defaults array.
|
||||
$settings += [
|
||||
'body' => [[
|
||||
'value' => $this->randomMachineName(32),
|
||||
'format' => filter_default_format(),
|
||||
]],
|
||||
'title' => $this->randomMachineName(8),
|
||||
'type' => 'page',
|
||||
'uid' => \Drupal::currentUser()->id(),
|
||||
];
|
||||
$node = Node::create($settings);
|
||||
$node->save();
|
||||
|
||||
return $node;
|
||||
}
|
||||
use BaseNodeCreationTrait;
|
||||
|
||||
}
|
||||
|
|
|
@ -2,111 +2,15 @@
|
|||
|
||||
namespace Drupal\simpletest;
|
||||
|
||||
use Drupal\Core\Routing\PreloadableRouteProviderInterface;
|
||||
use Symfony\Cmf\Component\Routing\PagedRouteProviderInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Drupal\KernelTests\RouteProvider as CoreRouteProvider;
|
||||
|
||||
/**
|
||||
* Rebuilds the router when the provider is instantiated.
|
||||
*
|
||||
* @todo Move this outside of simpletest namespace to the Drupal\Tests, see
|
||||
* https://www.drupal.org/node/2672762
|
||||
* @deprecated in 8.6.0 for removal before 9.0.0. Use
|
||||
* Drupal\KernelTests\RouteProvider instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2943146
|
||||
*/
|
||||
class RouteProvider implements PreloadableRouteProviderInterface, PagedRouteProviderInterface {
|
||||
|
||||
use \Drupal\Core\DependencyInjection\DependencySerializationTrait;
|
||||
|
||||
/**
|
||||
* Loads the real route provider from the container and rebuilds the router.
|
||||
*
|
||||
* @return \Drupal\Core\Routing\PreloadableRouteProviderInterface|\Symfony\Cmf\Component\Routing\PagedRouteProviderInterface|\Symfony\Component\EventDispatcher\EventSubscriberInterface
|
||||
* The route provider.
|
||||
*/
|
||||
protected function lazyLoadItself() {
|
||||
if (!isset($this->service)) {
|
||||
$container = \Drupal::getContainer();
|
||||
$this->service = $container->get('simpletest.router.route_provider');
|
||||
$container->get('router.builder')->rebuild();
|
||||
}
|
||||
|
||||
return $this->service;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRouteCollectionForRequest(Request $request) {
|
||||
return $this->lazyLoadItself()->getRouteCollectionForRequest($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRouteByName($name) {
|
||||
return $this->lazyLoadItself()->getRouteByName($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function preLoadRoutes($names){
|
||||
return $this->lazyLoadItself()->preLoadRoutes($names);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRoutesByNames($names) {
|
||||
return $this->lazyLoadItself()->getRoutesByNames($names);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCandidateOutlines(array $parts) {
|
||||
return $this->lazyLoadItself()->getCandidateOutlines($parts);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRoutesByPattern($pattern) {
|
||||
return $this->lazyLoadItself()->getRoutesByPattern($pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function routeProviderRouteCompare(array $a, array $b) {
|
||||
return $this->lazyLoadItself()->routeProviderRouteCompare($a, $b);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAllRoutes() {
|
||||
return $this->lazyLoadItself()->getAllRoutes();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function reset() {
|
||||
return $this->lazyLoadItself()->reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRoutesPaged($offset, $length = NULL) {
|
||||
return $this->lazyLoadItself()->getRoutesPaged($offset, $length);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRoutesCount() {
|
||||
return $this->lazyLoadItself()->getRoutesCount();
|
||||
}
|
||||
|
||||
class RouteProvider extends CoreRouteProvider {
|
||||
}
|
||||
|
|
|
@ -5,16 +5,16 @@ namespace Drupal\simpletest;
|
|||
use Drupal\Component\Assertion\Handle;
|
||||
use Drupal\Component\Render\MarkupInterface;
|
||||
use Drupal\Component\Utility\Crypt;
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\Core\Site\Settings;
|
||||
use Drupal\Core\StreamWrapper\PublicStream;
|
||||
use Drupal\Core\Test\TestDatabase;
|
||||
use Drupal\Core\Test\TestSetupTrait;
|
||||
use Drupal\Core\Utility\Error;
|
||||
use Drupal\Tests\AssertHelperTrait as BaseAssertHelperTrait;
|
||||
use Drupal\Tests\ConfigTestTrait;
|
||||
use Drupal\Tests\RandomGeneratorTrait;
|
||||
use Drupal\Tests\SessionTestTrait;
|
||||
use Drupal\Tests\Traits\Core\GeneratePermutationsTrait;
|
||||
|
||||
/**
|
||||
|
@ -24,12 +24,11 @@ use Drupal\Tests\Traits\Core\GeneratePermutationsTrait;
|
|||
*/
|
||||
abstract class TestBase {
|
||||
|
||||
use BaseAssertHelperTrait;
|
||||
use TestSetupTrait;
|
||||
use SessionTestTrait;
|
||||
use RandomGeneratorTrait;
|
||||
use AssertHelperTrait;
|
||||
use GeneratePermutationsTrait;
|
||||
// For backwards compatibility switch the visbility of the methods to public.
|
||||
// For backwards compatibility switch the visibility of the methods to public.
|
||||
use ConfigTestTrait {
|
||||
configImporter as public;
|
||||
copyConfig as public;
|
||||
|
@ -44,13 +43,15 @@ abstract class TestBase {
|
|||
|
||||
/**
|
||||
* Time limit for the test.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $timeLimit = 500;
|
||||
|
||||
/**
|
||||
* Current results of this test case.
|
||||
*
|
||||
* @var Array
|
||||
* @var array
|
||||
*/
|
||||
public $results = [
|
||||
'#pass' => 0,
|
||||
|
@ -62,7 +63,7 @@ abstract class TestBase {
|
|||
/**
|
||||
* Assertions thrown in that test case.
|
||||
*
|
||||
* @var Array
|
||||
* @var array
|
||||
*/
|
||||
protected $assertions = [];
|
||||
|
||||
|
@ -245,6 +246,20 @@ abstract class TestBase {
|
|||
$this->testId = $test_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fail the test if it belongs to a PHPUnit-based framework.
|
||||
*
|
||||
* This would probably be caused by automated test conversions such as those
|
||||
* in https://www.drupal.org/project/drupal/issues/2770921.
|
||||
*/
|
||||
public function checkTestHierarchyMismatch() {
|
||||
// We can use getPhpunitTestSuite() because it uses a regex on the class'
|
||||
// namespace to deduce the PHPUnit test suite.
|
||||
if (TestDiscovery::getPhpunitTestSuite(get_class($this)) !== FALSE) {
|
||||
$this->fail(get_class($this) . ' incorrectly subclasses ' . __CLASS__ . ', it should probably extend \Drupal\Tests\BrowserTestBase instead.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs setup tasks before each individual test method is run.
|
||||
*/
|
||||
|
@ -288,7 +303,7 @@ abstract class TestBase {
|
|||
* TRUE is a synonym for 'pass', FALSE for 'fail'.
|
||||
* @param string|\Drupal\Component\Render\MarkupInterface $message
|
||||
* (optional) A message to display with the assertion. Do not translate
|
||||
* messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed
|
||||
* messages: use \Drupal\Component\Render\FormattableMarkup to embed
|
||||
* variables in the message text, not t(). If left blank, a default message
|
||||
* will be displayed.
|
||||
* @param $group
|
||||
|
@ -446,7 +461,7 @@ abstract class TestBase {
|
|||
* The value on which the assertion is to be done.
|
||||
* @param $message
|
||||
* (optional) A message to display with the assertion. Do not translate
|
||||
* messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed
|
||||
* messages: use \Drupal\Component\Render\FormattableMarkup to embed
|
||||
* variables in the message text, not t(). If left blank, a default message
|
||||
* will be displayed.
|
||||
* @param $group
|
||||
|
@ -459,7 +474,7 @@ abstract class TestBase {
|
|||
* TRUE if the assertion succeeded, FALSE otherwise.
|
||||
*/
|
||||
protected function assertTrue($value, $message = '', $group = 'Other') {
|
||||
return $this->assert((bool) $value, $message ? $message : SafeMarkup::format('Value @value is TRUE.', ['@value' => var_export($value, TRUE)]), $group);
|
||||
return $this->assert((bool) $value, $message ? $message : new FormattableMarkup('Value @value is TRUE.', ['@value' => var_export($value, TRUE)]), $group);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -471,7 +486,7 @@ abstract class TestBase {
|
|||
* The value on which the assertion is to be done.
|
||||
* @param $message
|
||||
* (optional) A message to display with the assertion. Do not translate
|
||||
* messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed
|
||||
* messages: use \Drupal\Component\Render\FormattableMarkup to embed
|
||||
* variables in the message text, not t(). If left blank, a default message
|
||||
* will be displayed.
|
||||
* @param $group
|
||||
|
@ -484,7 +499,7 @@ abstract class TestBase {
|
|||
* TRUE if the assertion succeeded, FALSE otherwise.
|
||||
*/
|
||||
protected function assertFalse($value, $message = '', $group = 'Other') {
|
||||
return $this->assert(!$value, $message ? $message : SafeMarkup::format('Value @value is FALSE.', ['@value' => var_export($value, TRUE)]), $group);
|
||||
return $this->assert(!$value, $message ? $message : new FormattableMarkup('Value @value is FALSE.', ['@value' => var_export($value, TRUE)]), $group);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -494,7 +509,7 @@ abstract class TestBase {
|
|||
* The value on which the assertion is to be done.
|
||||
* @param $message
|
||||
* (optional) A message to display with the assertion. Do not translate
|
||||
* messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed
|
||||
* messages: use \Drupal\Component\Render\FormattableMarkup to embed
|
||||
* variables in the message text, not t(). If left blank, a default message
|
||||
* will be displayed.
|
||||
* @param $group
|
||||
|
@ -507,7 +522,7 @@ abstract class TestBase {
|
|||
* TRUE if the assertion succeeded, FALSE otherwise.
|
||||
*/
|
||||
protected function assertNull($value, $message = '', $group = 'Other') {
|
||||
return $this->assert(!isset($value), $message ? $message : SafeMarkup::format('Value @value is NULL.', ['@value' => var_export($value, TRUE)]), $group);
|
||||
return $this->assert(!isset($value), $message ? $message : new FormattableMarkup('Value @value is NULL.', ['@value' => var_export($value, TRUE)]), $group);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -517,7 +532,7 @@ abstract class TestBase {
|
|||
* The value on which the assertion is to be done.
|
||||
* @param $message
|
||||
* (optional) A message to display with the assertion. Do not translate
|
||||
* messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed
|
||||
* messages: use \Drupal\Component\Render\FormattableMarkup to embed
|
||||
* variables in the message text, not t(). If left blank, a default message
|
||||
* will be displayed.
|
||||
* @param $group
|
||||
|
@ -530,7 +545,7 @@ abstract class TestBase {
|
|||
* TRUE if the assertion succeeded, FALSE otherwise.
|
||||
*/
|
||||
protected function assertNotNull($value, $message = '', $group = 'Other') {
|
||||
return $this->assert(isset($value), $message ? $message : SafeMarkup::format('Value @value is not NULL.', ['@value' => var_export($value, TRUE)]), $group);
|
||||
return $this->assert(isset($value), $message ? $message : new FormattableMarkup('Value @value is not NULL.', ['@value' => var_export($value, TRUE)]), $group);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -542,7 +557,7 @@ abstract class TestBase {
|
|||
* The second value to check.
|
||||
* @param $message
|
||||
* (optional) A message to display with the assertion. Do not translate
|
||||
* messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed
|
||||
* messages: use \Drupal\Component\Render\FormattableMarkup to embed
|
||||
* variables in the message text, not t(). If left blank, a default message
|
||||
* will be displayed.
|
||||
* @param $group
|
||||
|
@ -562,7 +577,7 @@ abstract class TestBase {
|
|||
$second = $this->castSafeStrings($second);
|
||||
$is_equal = $first == $second;
|
||||
if (!$is_equal || !$message) {
|
||||
$default_message = SafeMarkup::format('Value @first is equal to value @second.', ['@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE)]);
|
||||
$default_message = new FormattableMarkup('Value @first is equal to value @second.', ['@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE)]);
|
||||
$message = $message ? $message . PHP_EOL . $default_message : $default_message;
|
||||
}
|
||||
return $this->assert($is_equal, $message, $group);
|
||||
|
@ -577,7 +592,7 @@ abstract class TestBase {
|
|||
* The second value to check.
|
||||
* @param $message
|
||||
* (optional) A message to display with the assertion. Do not translate
|
||||
* messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed
|
||||
* messages: use \Drupal\Component\Render\FormattableMarkup to embed
|
||||
* variables in the message text, not t(). If left blank, a default message
|
||||
* will be displayed.
|
||||
* @param $group
|
||||
|
@ -597,7 +612,7 @@ abstract class TestBase {
|
|||
$second = $this->castSafeStrings($second);
|
||||
$not_equal = $first != $second;
|
||||
if (!$not_equal || !$message) {
|
||||
$default_message = SafeMarkup::format('Value @first is not equal to value @second.', ['@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE)]);
|
||||
$default_message = new FormattableMarkup('Value @first is not equal to value @second.', ['@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE)]);
|
||||
$message = $message ? $message . PHP_EOL . $default_message : $default_message;
|
||||
}
|
||||
return $this->assert($not_equal, $message, $group);
|
||||
|
@ -612,7 +627,7 @@ abstract class TestBase {
|
|||
* The second value to check.
|
||||
* @param $message
|
||||
* (optional) A message to display with the assertion. Do not translate
|
||||
* messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed
|
||||
* messages: use \Drupal\Component\Render\FormattableMarkup to embed
|
||||
* variables in the message text, not t(). If left blank, a default message
|
||||
* will be displayed.
|
||||
* @param $group
|
||||
|
@ -627,7 +642,7 @@ abstract class TestBase {
|
|||
protected function assertIdentical($first, $second, $message = '', $group = 'Other') {
|
||||
$is_identical = $first === $second;
|
||||
if (!$is_identical || !$message) {
|
||||
$default_message = SafeMarkup::format('Value @first is identical to value @second.', ['@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE)]);
|
||||
$default_message = new FormattableMarkup('Value @first is identical to value @second.', ['@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE)]);
|
||||
$message = $message ? $message . PHP_EOL . $default_message : $default_message;
|
||||
}
|
||||
return $this->assert($is_identical, $message, $group);
|
||||
|
@ -642,7 +657,7 @@ abstract class TestBase {
|
|||
* The second value to check.
|
||||
* @param $message
|
||||
* (optional) A message to display with the assertion. Do not translate
|
||||
* messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed
|
||||
* messages: use \Drupal\Component\Render\FormattableMarkup to embed
|
||||
* variables in the message text, not t(). If left blank, a default message
|
||||
* will be displayed.
|
||||
* @param $group
|
||||
|
@ -657,7 +672,7 @@ abstract class TestBase {
|
|||
protected function assertNotIdentical($first, $second, $message = '', $group = 'Other') {
|
||||
$not_identical = $first !== $second;
|
||||
if (!$not_identical || !$message) {
|
||||
$default_message = SafeMarkup::format('Value @first is not identical to value @second.', ['@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE)]);
|
||||
$default_message = new FormattableMarkup('Value @first is not identical to value @second.', ['@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE)]);
|
||||
$message = $message ? $message . PHP_EOL . $default_message : $default_message;
|
||||
}
|
||||
return $this->assert($not_identical, $message, $group);
|
||||
|
@ -672,7 +687,7 @@ abstract class TestBase {
|
|||
* The second object to check.
|
||||
* @param $message
|
||||
* (optional) A message to display with the assertion. Do not translate
|
||||
* messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed
|
||||
* messages: use \Drupal\Component\Render\FormattableMarkup to embed
|
||||
* variables in the message text, not t(). If left blank, a default message
|
||||
* will be displayed.
|
||||
* @param $group
|
||||
|
@ -685,7 +700,7 @@ abstract class TestBase {
|
|||
* TRUE if the assertion succeeded, FALSE otherwise.
|
||||
*/
|
||||
protected function assertIdenticalObject($object1, $object2, $message = '', $group = 'Other') {
|
||||
$message = $message ?: SafeMarkup::format('@object1 is identical to @object2', [
|
||||
$message = $message ?: new FormattableMarkup('@object1 is identical to @object2', [
|
||||
'@object1' => var_export($object1, TRUE),
|
||||
'@object2' => var_export($object2, TRUE),
|
||||
]);
|
||||
|
@ -752,7 +767,7 @@ abstract class TestBase {
|
|||
*
|
||||
* @param $message
|
||||
* (optional) A message to display with the assertion. Do not translate
|
||||
* messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed
|
||||
* messages: use \Drupal\Component\Render\FormattableMarkup to embed
|
||||
* variables in the message text, not t(). If left blank, a default message
|
||||
* will be displayed.
|
||||
* @param $group
|
||||
|
@ -773,7 +788,7 @@ abstract class TestBase {
|
|||
*
|
||||
* @param $message
|
||||
* (optional) A message to display with the assertion. Do not translate
|
||||
* messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed
|
||||
* messages: use \Drupal\Component\Render\FormattableMarkup to embed
|
||||
* variables in the message text, not t(). If left blank, a default message
|
||||
* will be displayed.
|
||||
* @param $group
|
||||
|
@ -794,7 +809,7 @@ abstract class TestBase {
|
|||
*
|
||||
* @param $message
|
||||
* (optional) A message to display with the assertion. Do not translate
|
||||
* messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed
|
||||
* messages: use \Drupal\Component\Render\FormattableMarkup to embed
|
||||
* variables in the message text, not t(). If left blank, a default message
|
||||
* will be displayed.
|
||||
* @param $group
|
||||
|
@ -861,6 +876,7 @@ abstract class TestBase {
|
|||
* methods during debugging.
|
||||
*/
|
||||
public function run(array $methods = []) {
|
||||
$this->checkTestHierarchyMismatch();
|
||||
$class = get_class($this);
|
||||
|
||||
if ($missing_requirements = $this->checkRequirements()) {
|
||||
|
@ -982,7 +998,7 @@ abstract class TestBase {
|
|||
|
||||
TestServiceProvider::$currentTest = NULL;
|
||||
// Clear out the error messages and restore error handler.
|
||||
drupal_get_messages();
|
||||
\Drupal::messenger()->deleteAll();
|
||||
restore_error_handler();
|
||||
}
|
||||
|
||||
|
@ -1323,7 +1339,7 @@ abstract class TestBase {
|
|||
]);
|
||||
$decoded_exception = Error::decodeException($exception);
|
||||
unset($decoded_exception['backtrace']);
|
||||
$message = SafeMarkup::format('%type: @message in %function (line %line of %file). <pre class="backtrace">@backtrace</pre>', $decoded_exception + [
|
||||
$message = new FormattableMarkup('%type: @message in %function (line %line of %file). <pre class="backtrace">@backtrace</pre>', $decoded_exception + [
|
||||
'@backtrace' => Error::formatBacktrace($verbose_backtrace),
|
||||
]);
|
||||
$this->error($message, 'Uncaught exception', Error::getLastCaller($backtrace));
|
||||
|
|
|
@ -6,7 +6,6 @@ use Doctrine\Common\Annotations\SimpleAnnotationReader;
|
|||
use Doctrine\Common\Reflection\StaticReflectionParser;
|
||||
use Drupal\Component\Annotation\Reflection\MockFileFinder;
|
||||
use Drupal\Component\Utility\NestedArray;
|
||||
use Drupal\Core\Cache\CacheBackendInterface;
|
||||
use Drupal\Core\Extension\ExtensionDiscovery;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\simpletest\Exception\MissingGroupException;
|
||||
|
@ -25,11 +24,11 @@ class TestDiscovery {
|
|||
protected $classLoader;
|
||||
|
||||
/**
|
||||
* Backend for caching discovery results.
|
||||
* Statically cached list of test classes.
|
||||
*
|
||||
* @var \Drupal\Core\Cache\CacheBackendInterface
|
||||
* @var array
|
||||
*/
|
||||
protected $cacheBackend;
|
||||
protected $testClasses;
|
||||
|
||||
/**
|
||||
* Cached map of all test namespaces to respective directories.
|
||||
|
@ -70,14 +69,11 @@ class TestDiscovery {
|
|||
* \Symfony\Component\ClassLoader\ApcClassLoader.
|
||||
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
|
||||
* The module handler.
|
||||
* @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
|
||||
* (optional) Backend for caching discovery results.
|
||||
*/
|
||||
public function __construct($root, $class_loader, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache_backend = NULL) {
|
||||
public function __construct($root, $class_loader, ModuleHandlerInterface $module_handler) {
|
||||
$this->root = $root;
|
||||
$this->classLoader = $class_loader;
|
||||
$this->moduleHandler = $module_handler;
|
||||
$this->cacheBackend = $cache_backend;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -144,8 +140,8 @@ class TestDiscovery {
|
|||
* An array of tests keyed by the the group name.
|
||||
* @code
|
||||
* $groups['block'] => array(
|
||||
* 'Drupal\block\Tests\BlockTest' => array(
|
||||
* 'name' => 'Drupal\block\Tests\BlockTest',
|
||||
* 'Drupal\Tests\block\Functional\BlockTest' => array(
|
||||
* 'name' => 'Drupal\Tests\block\Functional\BlockTest',
|
||||
* 'description' => 'Tests block UI CRUD functionality.',
|
||||
* 'group' => 'block',
|
||||
* ),
|
||||
|
@ -159,9 +155,9 @@ class TestDiscovery {
|
|||
$reader = new SimpleAnnotationReader();
|
||||
$reader->addNamespace('Drupal\\simpletest\\Annotation');
|
||||
|
||||
if (!isset($extension)) {
|
||||
if ($this->cacheBackend && $cache = $this->cacheBackend->get('simpletest:discovery:classes')) {
|
||||
return $cache->data;
|
||||
if (!isset($extension) && empty($types)) {
|
||||
if (!empty($this->testClasses)) {
|
||||
return $this->testClasses;
|
||||
}
|
||||
}
|
||||
$list = [];
|
||||
|
@ -189,14 +185,17 @@ class TestDiscovery {
|
|||
// abstract class, trait or test fixture.
|
||||
continue;
|
||||
}
|
||||
// Skip this test class if it requires unavailable modules.
|
||||
// @todo PHPUnit skips tests with unmet requirements when executing a test
|
||||
// (instead of excluding them upfront). Refactor test runner to follow
|
||||
// that approach.
|
||||
// Skip this test class if it is a Simpletest-based test and requires
|
||||
// unavailable modules. TestDiscovery should not filter out module
|
||||
// requirements for PHPUnit-based test classes.
|
||||
// @todo Move this behavior to \Drupal\simpletest\TestBase so tests can be
|
||||
// marked as skipped, instead.
|
||||
// @see https://www.drupal.org/node/1273478
|
||||
if (!empty($info['requires']['module'])) {
|
||||
if (array_diff($info['requires']['module'], $this->availableExtensions['module'])) {
|
||||
continue;
|
||||
if ($info['type'] == 'Simpletest') {
|
||||
if (!empty($info['requires']['module'])) {
|
||||
if (array_diff($info['requires']['module'], $this->availableExtensions['module'])) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -210,12 +209,10 @@ class TestDiscovery {
|
|||
}
|
||||
|
||||
// Allow modules extending core tests to disable originals.
|
||||
$this->moduleHandler->alter('simpletest', $list);
|
||||
$this->moduleHandler->alterDeprecated('Convert your test to a PHPUnit-based one and implement test listeners. See: https://www.drupal.org/node/2939892', 'simpletest', $list);
|
||||
|
||||
if (!isset($extension)) {
|
||||
if ($this->cacheBackend) {
|
||||
$this->cacheBackend->set('simpletest:discovery:classes', $list);
|
||||
}
|
||||
if (!isset($extension) && empty($types)) {
|
||||
$this->testClasses = $list;
|
||||
}
|
||||
|
||||
if ($types) {
|
||||
|
@ -285,13 +282,21 @@ class TestDiscovery {
|
|||
$flags |= \FilesystemIterator::SKIP_DOTS;
|
||||
$flags |= \FilesystemIterator::FOLLOW_SYMLINKS;
|
||||
$flags |= \FilesystemIterator::CURRENT_AS_SELF;
|
||||
$flags |= \FilesystemIterator::KEY_AS_FILENAME;
|
||||
|
||||
$iterator = new \RecursiveDirectoryIterator($path, $flags);
|
||||
$filter = new \RecursiveCallbackFilterIterator($iterator, function ($current, $key, $iterator) {
|
||||
$filter = new \RecursiveCallbackFilterIterator($iterator, function ($current, $file_name, $iterator) {
|
||||
if ($iterator->hasChildren()) {
|
||||
return TRUE;
|
||||
}
|
||||
return $current->isFile() && $current->getExtension() === 'php';
|
||||
// We don't want to discover abstract TestBase classes, traits or
|
||||
// interfaces. They can be deprecated and will call @trigger_error()
|
||||
// during discovery.
|
||||
return
|
||||
substr($file_name, -4) === '.php' &&
|
||||
substr($file_name, -12) !== 'TestBase.php' &&
|
||||
substr($file_name, -9) !== 'Trait.php' &&
|
||||
substr($file_name, -13) !== 'Interface.php';
|
||||
});
|
||||
$files = new \RecursiveIteratorIterator($filter);
|
||||
$classes = [];
|
||||
|
@ -309,7 +314,7 @@ class TestDiscovery {
|
|||
/**
|
||||
* Retrieves information about a test class for UI purposes.
|
||||
*
|
||||
* @param string $class
|
||||
* @param string $classname
|
||||
* The test classname.
|
||||
* @param string $doc_comment
|
||||
* (optional) The class PHPDoc comment. If not passed in reflection will be
|
||||
|
@ -328,7 +333,7 @@ class TestDiscovery {
|
|||
* If the class does not have a @group annotation.
|
||||
*/
|
||||
public static function getTestInfo($classname, $doc_comment = NULL) {
|
||||
if (!$doc_comment) {
|
||||
if ($doc_comment === NULL) {
|
||||
$reflection = new \ReflectionClass($classname);
|
||||
$doc_comment = $reflection->getDocComment();
|
||||
}
|
||||
|
|
|
@ -2,51 +2,16 @@
|
|||
|
||||
namespace Drupal\simpletest;
|
||||
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\Core\DependencyInjection\ServiceModifierInterface;
|
||||
use Drupal\Core\DependencyInjection\ServiceProviderInterface;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Drupal\KernelTests\TestServiceProvider as CoreTestServiceProvider;
|
||||
|
||||
class TestServiceProvider implements ServiceProviderInterface, ServiceModifierInterface {
|
||||
|
||||
/**
|
||||
* @var \Drupal\simpletest\TestBase;
|
||||
*/
|
||||
public static $currentTest;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function register(ContainerBuilder $container) {
|
||||
if (static::$currentTest && method_exists(static::$currentTest, 'containerBuild')) {
|
||||
static::$currentTest->containerBuild($container);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function alter(ContainerBuilder $container) {
|
||||
if (static::$currentTest instanceof KernelTestBase) {
|
||||
static::addRouteProvider($container);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the on demand rebuild route provider service.
|
||||
*
|
||||
* @param \Drupal\Core\DependencyInjection\ContainerBuilder $container
|
||||
*/
|
||||
public static function addRouteProvider(ContainerBuilder $container) {
|
||||
foreach (['router.route_provider' => 'RouteProvider'] as $original_id => $class) {
|
||||
// While $container->get() does a recursive resolve, getDefinition() does
|
||||
// not, so do it ourselves.
|
||||
for ($id = $original_id; $container->hasAlias($id); $id = (string) $container->getAlias($id));
|
||||
$definition = $container->getDefinition($id);
|
||||
$definition->clearTag('needs_destruction');
|
||||
$container->setDefinition("simpletest.$original_id", $definition);
|
||||
$container->setDefinition($id, new Definition('Drupal\simpletest\\' . $class));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Provides special routing services for tests.
|
||||
*
|
||||
* @deprecated in 8.6.0 for removal before Drupal 9.0.0. Use
|
||||
* Drupal\KernelTests\TestServiceProvider instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2943146
|
||||
*/
|
||||
class TestServiceProvider extends CoreTestServiceProvider {
|
||||
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ class InstallationProfileModuleTestsTest extends WebTestBase {
|
|||
public static $modules = ['simpletest'];
|
||||
|
||||
/**
|
||||
* An administrative user with permission to adminsiter unit tests.
|
||||
* An administrative user with permission to administer unit tests.
|
||||
*
|
||||
* @var \Drupal\user\UserInterface
|
||||
*/
|
||||
|
@ -35,7 +35,9 @@ class InstallationProfileModuleTestsTest extends WebTestBase {
|
|||
* - but still install the drupal_system_listing_compatible_test.module
|
||||
* contained in the Testing profile.
|
||||
*
|
||||
* @see \Drupal\drupal_system_listing_compatible_test\Tests\SystemListingCompatibleTest
|
||||
* @see \Drupal\Tests\drupal_system_listing_compatible_test\Kernel\SystemListingCrossProfileCompatibleTest
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $profile = 'testing';
|
||||
|
||||
|
@ -51,12 +53,18 @@ class InstallationProfileModuleTestsTest extends WebTestBase {
|
|||
*/
|
||||
public function testInstallationProfileTests() {
|
||||
$this->drupalGet('admin/config/development/testing');
|
||||
$this->assertText('Drupal\drupal_system_listing_compatible_test\Tests\SystemListingCompatibleTest');
|
||||
$this->assertText('Drupal\Tests\drupal_system_listing_compatible_test\Kernel\SystemListingCrossProfileCompatibleTest');
|
||||
$edit = [
|
||||
'tests[Drupal\drupal_system_listing_compatible_test\Tests\SystemListingCompatibleTest]' => TRUE,
|
||||
'tests[Drupal\Tests\drupal_system_listing_compatible_test\Kernel\SystemListingCrossProfileCompatibleTest]' => TRUE,
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Run tests'));
|
||||
$this->assertText('SystemListingCompatibleTest test executed.');
|
||||
|
||||
// Verifies that tests in installation profile modules are passed.
|
||||
$element = $this->xpath('//tr[contains(@class, :class)]/td[contains(text(), :value)]', [
|
||||
':class' => 'simpletest-pass',
|
||||
':value' => 'Drupal\Tests\drupal_system_listing_compatible_test\Kernel\SystemListingCrossProfileCompatibleTest',
|
||||
]);
|
||||
$this->assertTrue(!empty($element));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ EOS;
|
|||
$this->assertIdentical(\Drupal::moduleHandler()->getImplementations('entity_type_alter'), ['entity_test']);
|
||||
|
||||
// Verify that no modules have been installed.
|
||||
$this->assertFalse(db_table_exists($table), "'$table' database table not found.");
|
||||
$this->assertFalse(Database::getConnection()->schema()->tableExists($table), "'$table' database table not found.");
|
||||
|
||||
// Verify that the settings.testing.php got taken into account.
|
||||
$this->assertTrue(function_exists('simpletest_test_stub_settings_function'));
|
||||
|
@ -114,7 +114,7 @@ EOS;
|
|||
$list = \Drupal::moduleHandler()->getImplementations('hook_info');
|
||||
$this->assertFalse(in_array($module, $list), "{$module}_hook_info() in \Drupal::moduleHandler()->getImplementations() not found.");
|
||||
|
||||
$this->assertFalse(db_table_exists($table), "'$table' database table not found.");
|
||||
$this->assertFalse(Database::getConnection()->schema()->tableExists($table), "'$table' database table not found.");
|
||||
|
||||
// Install the module.
|
||||
\Drupal::service('module_installer')->install([$module]);
|
||||
|
@ -126,7 +126,7 @@ EOS;
|
|||
$list = \Drupal::moduleHandler()->getImplementations('hook_info');
|
||||
$this->assertTrue(in_array($module, $list), "{$module}_hook_info() in \Drupal::moduleHandler()->getImplementations() found.");
|
||||
|
||||
$this->assertTrue(db_table_exists($table), "'$table' database table found.");
|
||||
$this->assertTrue(Database::getConnection()->schema()->tableExists($table), "'$table' database table found.");
|
||||
$schema = drupal_get_module_schema($module, $table);
|
||||
$this->assertTrue($schema, "'$table' table schema found.");
|
||||
}
|
||||
|
@ -156,7 +156,7 @@ EOS;
|
|||
$table = 'entity_test_example';
|
||||
// Verify that we can install a table from the module schema.
|
||||
$this->installSchema($module, $table);
|
||||
$this->assertTrue(db_table_exists($table), "'$table' database table found.");
|
||||
$this->assertTrue(Database::getConnection()->schema()->tableExists($table), "'$table' database table found.");
|
||||
|
||||
// Verify that the schema is known to Schema API.
|
||||
$schema = drupal_get_module_schema($module, $table);
|
||||
|
@ -171,7 +171,7 @@ EOS;
|
|||
catch (\Exception $e) {
|
||||
$this->pass('Exception for non-retrievable schema found.');
|
||||
}
|
||||
$this->assertFalse(db_table_exists($table), "'$table' database table not found.");
|
||||
$this->assertFalse(Database::getConnection()->schema()->tableExists($table), "'$table' database table not found.");
|
||||
$schema = drupal_get_module_schema($module, $table);
|
||||
$this->assertFalse($schema, "'$table' table schema not found.");
|
||||
|
||||
|
@ -185,14 +185,14 @@ EOS;
|
|||
catch (\Exception $e) {
|
||||
$this->pass('Exception for non-retrievable schema found.');
|
||||
}
|
||||
$this->assertFalse(db_table_exists($table), "'$table' database table not found.");
|
||||
$this->assertFalse(Database::getConnection()->schema()->tableExists($table), "'$table' database table not found.");
|
||||
$schema = drupal_get_module_schema($module, $table);
|
||||
$this->assertTrue($schema, "'$table' table schema found.");
|
||||
|
||||
// Verify that the same table can be installed after enabling the module.
|
||||
$this->enableModules([$module]);
|
||||
$this->installSchema($module, $table);
|
||||
$this->assertTrue(db_table_exists($table), "'$table' database table found.");
|
||||
$this->assertTrue(Database::getConnection()->schema()->tableExists($table), "'$table' database table found.");
|
||||
$schema = drupal_get_module_schema($module, $table);
|
||||
$this->assertTrue($schema, "'$table' table schema found.");
|
||||
}
|
||||
|
@ -206,7 +206,7 @@ EOS;
|
|||
$this->enableModules(['user']);
|
||||
// Verity that the entity schema is created properly.
|
||||
$this->installEntitySchema($entity);
|
||||
$this->assertTrue(db_table_exists($entity), "'$entity' database table found.");
|
||||
$this->assertTrue(Database::getConnection()->schema()->tableExists($entity), "'$entity' database table found.");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -278,7 +278,7 @@ EOS;
|
|||
$field_storage = FieldStorageConfig::create([
|
||||
'field_name' => 'test_field',
|
||||
'entity_type' => 'entity_test',
|
||||
'type' => 'test_field'
|
||||
'type' => 'test_field',
|
||||
]);
|
||||
$field_storage->save();
|
||||
FieldConfig::create([
|
||||
|
@ -354,7 +354,7 @@ EOS;
|
|||
$info = Database::getConnectionInfo();
|
||||
$connection->query('ATTACH DATABASE :database AS :prefix', [
|
||||
':database' => $info['default']['database'] . '-' . $this->databasePrefix,
|
||||
':prefix' => $this->databasePrefix
|
||||
':prefix' => $this->databasePrefix,
|
||||
]);
|
||||
|
||||
$result = $connection->query("SELECT name FROM " . $this->databasePrefix . ".sqlite_master WHERE type = :type AND name LIKE :table_name AND name NOT LIKE :pattern", [
|
||||
|
|
|
@ -30,7 +30,7 @@ class MissingCheckedRequirementsTest extends WebTestBase {
|
|||
protected function checkRequirements() {
|
||||
if ($this->isInChildSite()) {
|
||||
return [
|
||||
'Test is not allowed to run.'
|
||||
'Test is not allowed to run.',
|
||||
];
|
||||
}
|
||||
return parent::checkRequirements();
|
||||
|
|
|
@ -59,7 +59,7 @@ class SimpleTestBrowserTest extends WebTestBase {
|
|||
$this->maximumRedirects = 1;
|
||||
$edit = [
|
||||
'name' => $user->getUsername(),
|
||||
'pass' => $user->pass_raw
|
||||
'pass' => $user->pass_raw,
|
||||
];
|
||||
$this->drupalPostForm('user/login', $edit, t('Log in'), [
|
||||
'query' => ['destination' => 'user/logout'],
|
||||
|
@ -87,7 +87,7 @@ class SimpleTestBrowserTest extends WebTestBase {
|
|||
$this->drupalLogout();
|
||||
|
||||
$system_path = $base_url . '/' . drupal_get_path('module', 'system');
|
||||
$HTTP_path = $system_path . '/tests/http.php/user/login';
|
||||
$http_path = $system_path . '/tests/http.php/user/login';
|
||||
$https_path = $system_path . '/tests/https.php/user/login';
|
||||
// Generate a valid simpletest User-Agent to pass validation.
|
||||
$this->assertTrue(preg_match('/test\d+/', $this->databasePrefix, $matches), 'Database prefix contains test prefix.');
|
||||
|
@ -95,14 +95,14 @@ class SimpleTestBrowserTest extends WebTestBase {
|
|||
$this->additionalCurlOptions = [CURLOPT_USERAGENT => $test_ua];
|
||||
|
||||
// Test pages only available for testing.
|
||||
$this->drupalGet($HTTP_path);
|
||||
$this->drupalGet($http_path);
|
||||
$this->assertResponse(200, 'Requesting http.php with a legitimate simpletest User-Agent returns OK.');
|
||||
$this->drupalGet($https_path);
|
||||
$this->assertResponse(200, 'Requesting https.php with a legitimate simpletest User-Agent returns OK.');
|
||||
|
||||
// Now slightly modify the HMAC on the header, which should not validate.
|
||||
$this->additionalCurlOptions = [CURLOPT_USERAGENT => $test_ua . 'X'];
|
||||
$this->drupalGet($HTTP_path);
|
||||
$this->drupalGet($http_path);
|
||||
$this->assertResponse(403, 'Requesting http.php with a bad simpletest User-Agent fails.');
|
||||
$this->drupalGet($https_path);
|
||||
$this->assertResponse(403, 'Requesting https.php with a bad simpletest User-Agent fails.');
|
||||
|
@ -110,7 +110,7 @@ class SimpleTestBrowserTest extends WebTestBase {
|
|||
// Use a real User-Agent and verify that the special files http.php and
|
||||
// https.php can't be accessed.
|
||||
$this->additionalCurlOptions = [CURLOPT_USERAGENT => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12'];
|
||||
$this->drupalGet($HTTP_path);
|
||||
$this->drupalGet($http_path);
|
||||
$this->assertResponse(403, 'Requesting http.php with a normal User-Agent fails.');
|
||||
$this->drupalGet($https_path);
|
||||
$this->assertResponse(403, 'Requesting https.php with a normal User-Agent fails.');
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\simpletest\Tests;
|
||||
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
/**
|
||||
* Tests SimpleTest error and exception collector.
|
||||
*
|
||||
* @group WebTestBase
|
||||
*/
|
||||
class SimpleTestErrorCollectorTest extends WebTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['system_test', 'error_test'];
|
||||
|
||||
/**
|
||||
* Errors triggered during the test.
|
||||
*
|
||||
* Errors are intercepted by the overridden implementation
|
||||
* of Drupal\simpletest\WebTestBase::error() below.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $collectedErrors = [];
|
||||
|
||||
/**
|
||||
* Tests that simpletest collects errors from the tested site.
|
||||
*/
|
||||
public function testErrorCollect() {
|
||||
$this->collectedErrors = [];
|
||||
$this->drupalGet('error-test/generate-warnings-with-report');
|
||||
$this->assertEqual(count($this->collectedErrors), 3, 'Three errors were collected');
|
||||
|
||||
if (count($this->collectedErrors) == 3) {
|
||||
$this->assertError($this->collectedErrors[0], 'Notice', 'Drupal\error_test\Controller\ErrorTestController->generateWarnings()', 'ErrorTestController.php', 'Undefined variable: bananas');
|
||||
$this->assertError($this->collectedErrors[1], 'Warning', 'Drupal\error_test\Controller\ErrorTestController->generateWarnings()', 'ErrorTestController.php', 'Division by zero');
|
||||
$this->assertError($this->collectedErrors[2], 'User warning', 'Drupal\error_test\Controller\ErrorTestController->generateWarnings()', 'ErrorTestController.php', 'Drupal & awesome');
|
||||
}
|
||||
else {
|
||||
// Give back the errors to the log report.
|
||||
foreach ($this->collectedErrors as $error) {
|
||||
parent::error($error['message'], $error['group'], $error['caller']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores errors into an array.
|
||||
*
|
||||
* This test class is trying to verify that simpletest correctly sees errors
|
||||
* and warnings. However, it can't generate errors and warnings that
|
||||
* propagate up to the testing framework itself, or these tests would always
|
||||
* fail. So, this special copy of error() doesn't propagate the errors up
|
||||
* the class hierarchy. It just stuffs them into a protected collectedErrors
|
||||
* array for various assertions to inspect.
|
||||
*/
|
||||
protected function error($message = '', $group = 'Other', array $caller = NULL) {
|
||||
// Due to a WTF elsewhere, simpletest treats debug() and verbose()
|
||||
// messages as if they were an 'error'. But, we don't want to collect
|
||||
// those here. This function just wants to collect the real errors (PHP
|
||||
// notices, PHP fatal errors, etc.), and let all the 'errors' from the
|
||||
// 'User notice' group bubble up to the parent classes to be handled (and
|
||||
// eventually displayed) as normal.
|
||||
if ($group == 'User notice') {
|
||||
parent::error($message, $group, $caller);
|
||||
}
|
||||
// Everything else should be collected but not propagated.
|
||||
else {
|
||||
$this->collectedErrors[] = [
|
||||
'message' => $message,
|
||||
'group' => $group,
|
||||
'caller' => $caller,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a collected error matches what we are expecting.
|
||||
*/
|
||||
public function assertError($error, $group, $function, $file, $message = NULL) {
|
||||
$this->assertEqual($error['group'], $group, format_string("Group was %group", ['%group' => $group]));
|
||||
$this->assertEqual($error['caller']['function'], $function, format_string("Function was %function", ['%function' => $function]));
|
||||
$this->assertEqual(drupal_basename($error['caller']['file']), $file, format_string("File was %file", ['%file' => $file]));
|
||||
if (isset($message)) {
|
||||
$this->assertEqual($error['message'], $message, format_string("Message was %message", ['%message' => $message]));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -175,7 +175,7 @@ EOD;
|
|||
// along by the rethrow.
|
||||
assert(FALSE, 'Lorem Ipsum');
|
||||
}
|
||||
catch ( \AssertionError $e ) {
|
||||
catch (\AssertionError $e) {
|
||||
$this->assertEqual($e->getMessage(), 'Lorem Ipsum', 'Runtime assertions Enabled and running.');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\simpletest\Tests;
|
||||
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
/**
|
||||
* Tests if Simpletest-based tests are skipped based on module requirements.
|
||||
*
|
||||
* This test should always be skipped when TestDiscovery is used to discover it.
|
||||
* This means that if you specify this test to run-tests.sh with --class or
|
||||
* --file, this test will run and fail.
|
||||
*
|
||||
* @dependencies module_does_not_exist
|
||||
*
|
||||
* @group simpletest
|
||||
*
|
||||
* @todo Change or remove this test when Simpletest-based tests are able to skip
|
||||
* themselves based on requirements.
|
||||
* @see https://www.drupal.org/node/1273478
|
||||
*/
|
||||
class SkipRequiredModulesTest extends WebTestBase {
|
||||
|
||||
public function testModuleNotFound() {
|
||||
$this->fail('This test should have been skipped during discovery.');
|
||||
}
|
||||
|
||||
}
|
|
@ -35,9 +35,9 @@ class UiPhpUnitOutputTest extends WebTestBase {
|
|||
|
||||
// Check that there are <br> tags for the HTML output by
|
||||
// SimpletestUiPrinter.
|
||||
$this->assertEqual($output[18], 'HTML output was generated<br />');
|
||||
$this->assertEqual($output[19], 'HTML output was generated<br />');
|
||||
// Check that URLs are printed as HTML links.
|
||||
$this->assertIdentical(strpos($output[19], '<a href="http'), 0);
|
||||
$this->assertIdentical(strpos($output[20], '<a href="http'), 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,11 +2,7 @@
|
|||
|
||||
namespace Drupal\simpletest;
|
||||
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\user\Entity\Role;
|
||||
use Drupal\user\Entity\User;
|
||||
use Drupal\user\RoleInterface;
|
||||
use Drupal\Tests\user\Traits\UserCreationTrait as BaseUserCreationTrait;
|
||||
|
||||
/**
|
||||
* Provides methods to create additional test users and switch the currently
|
||||
|
@ -14,201 +10,14 @@ use Drupal\user\RoleInterface;
|
|||
*
|
||||
* This trait is meant to be used only by test classes extending
|
||||
* \Drupal\simpletest\TestBase.
|
||||
*
|
||||
* @deprecated in Drupal 8.4.x. Will be removed before Drupal 9.0.0. Use
|
||||
* Drupal\Tests\user\Traits\UserCreationTrait instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2884454
|
||||
*/
|
||||
trait UserCreationTrait {
|
||||
|
||||
/**
|
||||
* Switch the current logged in user.
|
||||
*
|
||||
* @param \Drupal\Core\Session\AccountInterface $account
|
||||
* The user account object.
|
||||
*/
|
||||
protected function setCurrentUser(AccountInterface $account) {
|
||||
\Drupal::currentUser()->setAccount($account);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a user with a given set of permissions.
|
||||
*
|
||||
* @param array $permissions
|
||||
* Array of permission names to assign to user. Note that the user always
|
||||
* has the default permissions derived from the "authenticated users" role.
|
||||
* @param string $name
|
||||
* The user name.
|
||||
* @param bool $admin
|
||||
* (optional) Whether the user should be an administrator
|
||||
* with all the available permissions.
|
||||
*
|
||||
* @return \Drupal\user\Entity\User|false
|
||||
* A fully loaded user object with pass_raw property, or FALSE if account
|
||||
* creation fails.
|
||||
*/
|
||||
protected function createUser(array $permissions = [], $name = NULL, $admin = FALSE) {
|
||||
// Create a role with the given permission set, if any.
|
||||
$rid = FALSE;
|
||||
if ($permissions) {
|
||||
$rid = $this->createRole($permissions);
|
||||
if (!$rid) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// Create a user assigned to that role.
|
||||
$edit = [];
|
||||
$edit['name'] = !empty($name) ? $name : $this->randomMachineName();
|
||||
$edit['mail'] = $edit['name'] . '@example.com';
|
||||
$edit['pass'] = user_password();
|
||||
$edit['status'] = 1;
|
||||
if ($rid) {
|
||||
$edit['roles'] = [$rid];
|
||||
}
|
||||
|
||||
if ($admin) {
|
||||
$edit['roles'][] = $this->createAdminRole();
|
||||
}
|
||||
|
||||
$account = User::create($edit);
|
||||
$account->save();
|
||||
|
||||
$this->assertTrue($account->id(), SafeMarkup::format('User created with name %name and pass %pass', ['%name' => $edit['name'], '%pass' => $edit['pass']]), 'User login');
|
||||
if (!$account->id()) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Add the raw password so that we can log in as this user.
|
||||
$account->pass_raw = $edit['pass'];
|
||||
// Support BrowserTestBase as well.
|
||||
$account->passRaw = $account->pass_raw;
|
||||
return $account;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an administrative role.
|
||||
*
|
||||
* @param string $rid
|
||||
* (optional) The role ID (machine name). Defaults to a random name.
|
||||
* @param string $name
|
||||
* (optional) The label for the role. Defaults to a random string.
|
||||
* @param int $weight
|
||||
* (optional) The weight for the role. Defaults NULL so that entity_create()
|
||||
* sets the weight to maximum + 1.
|
||||
*
|
||||
* @return string
|
||||
* Role ID of newly created role, or FALSE if role creation failed.
|
||||
*/
|
||||
protected function createAdminRole($rid = NULL, $name = NULL, $weight = NULL) {
|
||||
$rid = $this->createRole([], $rid, $name, $weight);
|
||||
if ($rid) {
|
||||
/** @var \Drupal\user\RoleInterface $role */
|
||||
$role = Role::load($rid);
|
||||
$role->setIsAdmin(TRUE);
|
||||
$role->save();
|
||||
}
|
||||
return $rid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a role with specified permissions.
|
||||
*
|
||||
* @param array $permissions
|
||||
* Array of permission names to assign to role.
|
||||
* @param string $rid
|
||||
* (optional) The role ID (machine name). Defaults to a random name.
|
||||
* @param string $name
|
||||
* (optional) The label for the role. Defaults to a random string.
|
||||
* @param int $weight
|
||||
* (optional) The weight for the role. Defaults NULL so that entity_create()
|
||||
* sets the weight to maximum + 1.
|
||||
*
|
||||
* @return string
|
||||
* Role ID of newly created role, or FALSE if role creation failed.
|
||||
*/
|
||||
protected function createRole(array $permissions, $rid = NULL, $name = NULL, $weight = NULL) {
|
||||
// Generate a random, lowercase machine name if none was passed.
|
||||
if (!isset($rid)) {
|
||||
$rid = strtolower($this->randomMachineName(8));
|
||||
}
|
||||
// Generate a random label.
|
||||
if (!isset($name)) {
|
||||
// In the role UI role names are trimmed and random string can start or
|
||||
// end with a space.
|
||||
$name = trim($this->randomString(8));
|
||||
}
|
||||
|
||||
// Check the all the permissions strings are valid.
|
||||
if (!$this->checkPermissions($permissions)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Create new role.
|
||||
$role = Role::create([
|
||||
'id' => $rid,
|
||||
'label' => $name,
|
||||
]);
|
||||
if (isset($weight)) {
|
||||
$role->set('weight', $weight);
|
||||
}
|
||||
$result = $role->save();
|
||||
|
||||
$this->assertIdentical($result, SAVED_NEW, SafeMarkup::format('Created role ID @rid with name @name.', [
|
||||
'@name' => var_export($role->label(), TRUE),
|
||||
'@rid' => var_export($role->id(), TRUE),
|
||||
]), 'Role');
|
||||
|
||||
if ($result === SAVED_NEW) {
|
||||
// Grant the specified permissions to the role, if any.
|
||||
if (!empty($permissions)) {
|
||||
$this->grantPermissions($role, $permissions);
|
||||
$assigned_permissions = Role::load($role->id())->getPermissions();
|
||||
$missing_permissions = array_diff($permissions, $assigned_permissions);
|
||||
if (!$missing_permissions) {
|
||||
$this->pass(SafeMarkup::format('Created permissions: @perms', ['@perms' => implode(', ', $permissions)]), 'Role');
|
||||
}
|
||||
else {
|
||||
$this->fail(SafeMarkup::format('Failed to create permissions: @perms', ['@perms' => implode(', ', $missing_permissions)]), 'Role');
|
||||
}
|
||||
}
|
||||
return $role->id();
|
||||
}
|
||||
else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a given list of permission names is valid.
|
||||
*
|
||||
* @param array $permissions
|
||||
* The permission names to check.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the permissions are valid, FALSE otherwise.
|
||||
*/
|
||||
protected function checkPermissions(array $permissions) {
|
||||
$available = array_keys(\Drupal::service('user.permissions')->getPermissions());
|
||||
$valid = TRUE;
|
||||
foreach ($permissions as $permission) {
|
||||
if (!in_array($permission, $available)) {
|
||||
$this->fail(SafeMarkup::format('Invalid permission %permission.', ['%permission' => $permission]), 'Role');
|
||||
$valid = FALSE;
|
||||
}
|
||||
}
|
||||
return $valid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Grant permissions to a user role.
|
||||
*
|
||||
* @param \Drupal\user\RoleInterface $role
|
||||
* The ID of a user role to alter.
|
||||
* @param array $permissions
|
||||
* (optional) A list of permission names to grant.
|
||||
*/
|
||||
protected function grantPermissions(RoleInterface $role, array $permissions) {
|
||||
foreach ($permissions as $permission) {
|
||||
$role->grantPermission($permission);
|
||||
}
|
||||
$role->trustData()->save();
|
||||
}
|
||||
use BaseUserCreationTrait;
|
||||
|
||||
}
|
||||
|
|
|
@ -7,8 +7,7 @@ use Drupal\Component\Serialization\Json;
|
|||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Component\Utility\NestedArray;
|
||||
use Drupal\Component\Utility\UrlHelper;
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\Core\EventSubscriber\AjaxResponseSubscriber;
|
||||
use Drupal\Core\EventSubscriber\MainContentViewSubscriber;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
|
@ -18,8 +17,13 @@ use Drupal\Core\Test\FunctionalTestSetupTrait;
|
|||
use Drupal\Core\Url;
|
||||
use Drupal\system\Tests\Cache\AssertPageCacheContextsAndTagsTrait;
|
||||
use Drupal\Tests\EntityViewTrait;
|
||||
use Drupal\Tests\block\Traits\BlockCreationTrait as BaseBlockCreationTrait;
|
||||
use Drupal\Tests\Listeners\DeprecationListenerTrait;
|
||||
use Drupal\Tests\node\Traits\ContentTypeCreationTrait as BaseContentTypeCreationTrait;
|
||||
use Drupal\Tests\node\Traits\NodeCreationTrait as BaseNodeCreationTrait;
|
||||
use Drupal\Tests\Traits\Core\CronRunTrait;
|
||||
use Drupal\Tests\TestFileCreationTrait;
|
||||
use Drupal\Tests\user\Traits\UserCreationTrait as BaseUserCreationTrait;
|
||||
use Drupal\Tests\XdebugRequestTrait;
|
||||
use Zend\Diactoros\Uri;
|
||||
|
||||
|
@ -37,21 +41,21 @@ abstract class WebTestBase extends TestBase {
|
|||
compareFiles as drupalCompareFiles;
|
||||
}
|
||||
use AssertPageCacheContextsAndTagsTrait;
|
||||
use BlockCreationTrait {
|
||||
use BaseBlockCreationTrait {
|
||||
placeBlock as drupalPlaceBlock;
|
||||
}
|
||||
use ContentTypeCreationTrait {
|
||||
use BaseContentTypeCreationTrait {
|
||||
createContentType as drupalCreateContentType;
|
||||
}
|
||||
use CronRunTrait;
|
||||
use AssertMailTrait {
|
||||
getMails as drupalGetMails;
|
||||
}
|
||||
use NodeCreationTrait {
|
||||
use BaseNodeCreationTrait {
|
||||
getNodeByTitle as drupalGetNodeByTitle;
|
||||
createNode as drupalCreateNode;
|
||||
}
|
||||
use UserCreationTrait {
|
||||
use BaseUserCreationTrait {
|
||||
createUser as drupalCreateUser;
|
||||
createRole as drupalCreateRole;
|
||||
createAdminRole as drupalCreateAdminRole;
|
||||
|
@ -93,7 +97,7 @@ abstract class WebTestBase extends TestBase {
|
|||
/**
|
||||
* The headers of the page currently loaded in the internal browser.
|
||||
*
|
||||
* @var Array
|
||||
* @var array
|
||||
*/
|
||||
protected $headers;
|
||||
|
||||
|
@ -165,6 +169,8 @@ abstract class WebTestBase extends TestBase {
|
|||
|
||||
/**
|
||||
* The maximum number of redirects to follow when handling responses.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $maximumRedirects = 5;
|
||||
|
||||
|
@ -280,7 +286,7 @@ abstract class WebTestBase extends TestBase {
|
|||
|
||||
$edit = [
|
||||
'name' => $account->getUsername(),
|
||||
'pass' => $account->pass_raw
|
||||
'pass' => $account->pass_raw,
|
||||
];
|
||||
$this->drupalPostForm('user/login', $edit, t('Log in'));
|
||||
|
||||
|
@ -389,69 +395,6 @@ abstract class WebTestBase extends TestBase {
|
|||
$this->rebuildAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the parameters that will be used when Simpletest installs Drupal.
|
||||
*
|
||||
* @see install_drupal()
|
||||
* @see install_state_defaults()
|
||||
*
|
||||
* @return array
|
||||
* Array of parameters for use in install_drupal().
|
||||
*/
|
||||
protected function installParameters() {
|
||||
$connection_info = Database::getConnectionInfo();
|
||||
$driver = $connection_info['default']['driver'];
|
||||
$connection_info['default']['prefix'] = $connection_info['default']['prefix']['default'];
|
||||
unset($connection_info['default']['driver']);
|
||||
unset($connection_info['default']['namespace']);
|
||||
unset($connection_info['default']['pdo']);
|
||||
unset($connection_info['default']['init_commands']);
|
||||
// Remove database connection info that is not used by SQLite.
|
||||
if ($driver == 'sqlite') {
|
||||
unset($connection_info['default']['username']);
|
||||
unset($connection_info['default']['password']);
|
||||
unset($connection_info['default']['host']);
|
||||
unset($connection_info['default']['port']);
|
||||
}
|
||||
$parameters = [
|
||||
'interactive' => FALSE,
|
||||
'parameters' => [
|
||||
'profile' => $this->profile,
|
||||
'langcode' => 'en',
|
||||
],
|
||||
'forms' => [
|
||||
'install_settings_form' => [
|
||||
'driver' => $driver,
|
||||
$driver => $connection_info['default'],
|
||||
],
|
||||
'install_configure_form' => [
|
||||
'site_name' => 'Drupal',
|
||||
'site_mail' => 'simpletest@example.com',
|
||||
'account' => [
|
||||
'name' => $this->rootUser->name,
|
||||
'mail' => $this->rootUser->getEmail(),
|
||||
'pass' => [
|
||||
'pass1' => $this->rootUser->pass_raw,
|
||||
'pass2' => $this->rootUser->pass_raw,
|
||||
],
|
||||
],
|
||||
// \Drupal\Core\Render\Element\Checkboxes::valueCallback() requires
|
||||
// NULL instead of FALSE values for programmatic form submissions to
|
||||
// disable a checkbox.
|
||||
'enable_update_status_module' => NULL,
|
||||
'enable_update_status_emails' => NULL,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
// If we only have one db driver available, we cannot set the driver.
|
||||
include_once DRUPAL_ROOT . '/core/includes/install.inc';
|
||||
if (count($this->getDatabaseTypes()) == 1) {
|
||||
unset($parameters['forms']['install_settings_form']['driver']);
|
||||
}
|
||||
return $parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Preserve the original batch, and instantiate the test batch.
|
||||
*/
|
||||
|
@ -479,21 +422,6 @@ abstract class WebTestBase extends TestBase {
|
|||
$batch = $this->originalBatch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all supported database driver installer objects.
|
||||
*
|
||||
* This wraps drupal_get_database_types() for use without a current container.
|
||||
*
|
||||
* @return \Drupal\Core\Database\Install\Tasks[]
|
||||
* An array of available database driver installer objects.
|
||||
*/
|
||||
protected function getDatabaseTypes() {
|
||||
\Drupal::setContainer($this->originalContainer);
|
||||
$database_types = drupal_get_database_types();
|
||||
\Drupal::unsetContainer();
|
||||
return $database_types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Queues custom translations to be written to settings.php.
|
||||
*
|
||||
|
@ -732,9 +660,9 @@ abstract class WebTestBase extends TestBase {
|
|||
'@method' => !empty($curl_options[CURLOPT_NOBODY]) ? 'HEAD' : (empty($curl_options[CURLOPT_POSTFIELDS]) ? 'GET' : 'POST'),
|
||||
'@url' => isset($original_url) ? $original_url : $url,
|
||||
'@status' => $status,
|
||||
'@length' => format_size(strlen($this->getRawContent()))
|
||||
'@length' => format_size(strlen($this->getRawContent())),
|
||||
];
|
||||
$message = SafeMarkup::format('@method @url returned @status (@length).', $message_vars);
|
||||
$message = new FormattableMarkup('@method @url returned @status (@length).', $message_vars);
|
||||
$this->assertTrue($this->getRawContent() !== FALSE, $message, 'Browser');
|
||||
return $this->getRawContent();
|
||||
}
|
||||
|
@ -765,9 +693,22 @@ abstract class WebTestBase extends TestBase {
|
|||
// generated by _drupal_log_error() in the exact form required
|
||||
// by \Drupal\simpletest\WebTestBase::error().
|
||||
if (preg_match('/^X-Drupal-Assertion-[0-9]+: (.*)$/', $header, $matches)) {
|
||||
// Call \Drupal\simpletest\WebTestBase::error() with the parameters from
|
||||
// the header.
|
||||
call_user_func_array([&$this, 'error'], unserialize(urldecode($matches[1])));
|
||||
$parameters = unserialize(urldecode($matches[1]));
|
||||
// Handle deprecation notices triggered by system under test.
|
||||
if ($parameters[1] === 'User deprecated function') {
|
||||
if (getenv('SYMFONY_DEPRECATIONS_HELPER') !== 'disabled') {
|
||||
$message = (string) $parameters[0];
|
||||
$test_info = TestDiscovery::getTestInfo(get_called_class());
|
||||
if ($test_info['group'] !== 'legacy' && !in_array($message, DeprecationListenerTrait::getSkippedDeprecations())) {
|
||||
call_user_func_array([&$this, 'error'], $parameters);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Call \Drupal\simpletest\WebTestBase::error() with the parameters from
|
||||
// the header.
|
||||
call_user_func_array([&$this, 'error'], $parameters);
|
||||
}
|
||||
}
|
||||
|
||||
// Save cookies.
|
||||
|
@ -892,7 +833,7 @@ abstract class WebTestBase extends TestBase {
|
|||
* The result of the request.
|
||||
*/
|
||||
protected function drupalGetWithFormat($path, $format, array $options = [], array $headers = []) {
|
||||
$options += ['query' => ['_format' => $format]];
|
||||
$options = array_merge_recursive(['query' => ['_format' => $format]], $options);
|
||||
return $this->drupalGet($path, $options, $headers);
|
||||
}
|
||||
|
||||
|
@ -1113,7 +1054,7 @@ abstract class WebTestBase extends TestBase {
|
|||
}
|
||||
// We have not found a form which contained all fields of $edit.
|
||||
foreach ($edit as $name => $value) {
|
||||
$this->fail(SafeMarkup::format('Failed to set field @name to @value', ['@name' => $name, '@value' => $value]));
|
||||
$this->fail(new FormattableMarkup('Failed to set field @name to @value', ['@name' => $name, '@value' => $value]));
|
||||
}
|
||||
if (!$ajax && isset($submit)) {
|
||||
$this->assertTrue($submit_matches, format_string('Found the @submit button', ['@submit' => $submit]));
|
||||
|
@ -1785,10 +1726,10 @@ abstract class WebTestBase extends TestBase {
|
|||
$urls = $this->xpath($pattern, [':label' => $label]);
|
||||
if (isset($urls[$index])) {
|
||||
$url_target = $this->getAbsoluteUrl($urls[$index]['href']);
|
||||
$this->pass(SafeMarkup::format('Clicked link %label (@url_target) from @url_before', ['%label' => $label, '@url_target' => $url_target, '@url_before' => $url_before]), 'Browser');
|
||||
$this->pass(new FormattableMarkup('Clicked link %label (@url_target) from @url_before', ['%label' => $label, '@url_target' => $url_target, '@url_before' => $url_before]), 'Browser');
|
||||
return $this->drupalGet($url_target);
|
||||
}
|
||||
$this->fail(SafeMarkup::format('Link %label does not exist on @url_before', ['%label' => $label, '@url_before' => $url_before]), 'Browser');
|
||||
$this->fail(new FormattableMarkup('Link %label does not exist on @url_before', ['%label' => $label, '@url_before' => $url_before]), 'Browser');
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -1964,7 +1905,7 @@ abstract class WebTestBase extends TestBase {
|
|||
* (optional) Any additional options to pass for $path to the url generator.
|
||||
* @param $message
|
||||
* (optional) A message to display with the assertion. Do not translate
|
||||
* messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed
|
||||
* messages: use \Drupal\Component\Render\FormattableMarkup to embed
|
||||
* variables in the message text, not t(). If left blank, a default message
|
||||
* will be displayed.
|
||||
* @param $group
|
||||
|
@ -1991,7 +1932,7 @@ abstract class WebTestBase extends TestBase {
|
|||
}
|
||||
$url = $url_obj->setAbsolute()->toString();
|
||||
if (!$message) {
|
||||
$message = SafeMarkup::format('Expected @url matches current URL (@current_url).', [
|
||||
$message = new FormattableMarkup('Expected @url matches current URL (@current_url).', [
|
||||
'@url' => var_export($url, TRUE),
|
||||
'@current_url' => $this->getUrl(),
|
||||
]);
|
||||
|
@ -2011,7 +1952,7 @@ abstract class WebTestBase extends TestBase {
|
|||
* of all codes see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html.
|
||||
* @param $message
|
||||
* (optional) A message to display with the assertion. Do not translate
|
||||
* messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed
|
||||
* messages: use \Drupal\Component\Render\FormattableMarkup to embed
|
||||
* variables in the message text, not t(). If left blank, a default message
|
||||
* will be displayed.
|
||||
* @param $group
|
||||
|
@ -2026,7 +1967,7 @@ abstract class WebTestBase extends TestBase {
|
|||
protected function assertResponse($code, $message = '', $group = 'Browser') {
|
||||
$curl_code = curl_getinfo($this->curlHandle, CURLINFO_HTTP_CODE);
|
||||
$match = is_array($code) ? in_array($curl_code, $code) : $curl_code == $code;
|
||||
return $this->assertTrue($match, $message ? $message : SafeMarkup::format('HTTP response expected @code, actual @curl_code', ['@code' => $code, '@curl_code' => $curl_code]), $group);
|
||||
return $this->assertTrue($match, $message ? $message : new FormattableMarkup('HTTP response expected @code, actual @curl_code', ['@code' => $code, '@curl_code' => $curl_code]), $group);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2037,7 +1978,7 @@ abstract class WebTestBase extends TestBase {
|
|||
* of all codes see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html.
|
||||
* @param $message
|
||||
* (optional) A message to display with the assertion. Do not translate
|
||||
* messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed
|
||||
* messages: use \Drupal\Component\Render\FormattableMarkup to embed
|
||||
* variables in the message text, not t(). If left blank, a default message
|
||||
* will be displayed.
|
||||
* @param $group
|
||||
|
@ -2052,7 +1993,7 @@ abstract class WebTestBase extends TestBase {
|
|||
protected function assertNoResponse($code, $message = '', $group = 'Browser') {
|
||||
$curl_code = curl_getinfo($this->curlHandle, CURLINFO_HTTP_CODE);
|
||||
$match = is_array($code) ? in_array($curl_code, $code) : $curl_code == $code;
|
||||
return $this->assertFalse($match, $message ? $message : SafeMarkup::format('HTTP response not expected @code, actual @curl_code', ['@code' => $code, '@curl_code' => $curl_code]), $group);
|
||||
return $this->assertFalse($match, $message ? $message : new FormattableMarkup('HTTP response not expected @code, actual @curl_code', ['@code' => $code, '@curl_code' => $curl_code]), $group);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Reference in a new issue