comparison core/modules/simpletest/src/KernelTestBase.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 7a779792577d
children af1871eacc83
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
1 <?php 1 <?php
2 2
3 namespace Drupal\simpletest; 3 namespace Drupal\simpletest;
4 4
5 use Drupal\Component\Utility\Html; 5 use Drupal\Component\Utility\Html;
6 use Drupal\Component\Utility\SafeMarkup; 6 use Drupal\Component\Render\FormattableMarkup;
7 use Drupal\Component\Utility\Variable; 7 use Drupal\Component\Utility\Variable;
8 use Drupal\Core\Config\Development\ConfigSchemaChecker; 8 use Drupal\Core\Config\Development\ConfigSchemaChecker;
9 use Drupal\Core\Database\Database; 9 use Drupal\Core\Database\Database;
10 use Drupal\Core\DependencyInjection\ContainerBuilder; 10 use Drupal\Core\DependencyInjection\ContainerBuilder;
11 use Drupal\Core\DrupalKernel; 11 use Drupal\Core\DrupalKernel;
12 use Drupal\Core\Entity\Sql\SqlEntityStorageInterface; 12 use Drupal\Core\Entity\Sql\SqlEntityStorageInterface;
13 use Drupal\Core\Extension\ExtensionDiscovery; 13 use Drupal\Core\Extension\ExtensionDiscovery;
14 use Drupal\Core\KeyValueStore\KeyValueMemoryFactory; 14 use Drupal\Core\KeyValueStore\KeyValueMemoryFactory;
15 use Drupal\Core\Language\Language; 15 use Drupal\Core\Language\Language;
16 use Drupal\Core\Site\Settings; 16 use Drupal\Core\Site\Settings;
17 use Drupal\KernelTests\TestServiceProvider;
17 use Symfony\Component\DependencyInjection\Parameter; 18 use Symfony\Component\DependencyInjection\Parameter;
18 use Drupal\Core\StreamWrapper\StreamWrapperInterface; 19 use Drupal\Core\StreamWrapper\StreamWrapperInterface;
19 use Symfony\Component\DependencyInjection\Reference; 20 use Symfony\Component\DependencyInjection\Reference;
20 use Symfony\Component\HttpFoundation\Request; 21 use Symfony\Component\HttpFoundation\Request;
21 22
99 protected $configDirectories = []; 100 protected $configDirectories = [];
100 101
101 /** 102 /**
102 * A KeyValueMemoryFactory instance to use when building the container. 103 * A KeyValueMemoryFactory instance to use when building the container.
103 * 104 *
104 * @var \Drupal\Core\KeyValueStore\KeyValueMemoryFactory. 105 * @var \Drupal\Core\KeyValueStore\KeyValueMemoryFactory
105 */ 106 */
106 protected $keyValueFactory; 107 protected $keyValueFactory;
107 108
108 /** 109 /**
109 * Array of registered stream wrappers. 110 * Array of registered stream wrappers.
196 file_put_contents($directory . '/settings.php', $php); 197 file_put_contents($directory . '/settings.php', $php);
197 } 198 }
198 199
199 // Add this test class as a service provider. 200 // Add this test class as a service provider.
200 // @todo Remove the indirection; implement ServiceProviderInterface instead. 201 // @todo Remove the indirection; implement ServiceProviderInterface instead.
201 $GLOBALS['conf']['container_service_providers']['TestServiceProvider'] = 'Drupal\simpletest\TestServiceProvider'; 202 $GLOBALS['conf']['container_service_providers']['TestServiceProvider'] = TestServiceProvider::class;
202 203
203 // Bootstrap a new kernel. 204 // Bootstrap a new kernel.
204 $class_loader = require DRUPAL_ROOT . '/autoload.php'; 205 $class_loader = require DRUPAL_ROOT . '/autoload.php';
205 $this->kernel = new DrupalKernel('testing', $class_loader, FALSE); 206 $this->kernel = new DrupalKernel('testing', $class_loader, FALSE);
206 $request = Request::create('/'); 207 $request = Request::create('/');
475 '%tables' => '{' . implode('}, {', $tables) . '}', 476 '%tables' => '{' . implode('}, {', $tables) . '}',
476 '%module' => $module, 477 '%module' => $module,
477 ])); 478 ]));
478 } 479 }
479 480
480
481 /** 481 /**
482 * Installs the storage schema for a specific entity type. 482 * Installs the storage schema for a specific entity type.
483 * 483 *
484 * @param string $entity_type_id 484 * @param string $entity_type_id
485 * The ID of the entity type. 485 * The ID of the entity type.
497 $tables = $storage->getTableMapping()->getTableNames(); 497 $tables = $storage->getTableMapping()->getTableNames();
498 $db_schema = $this->container->get('database')->schema(); 498 $db_schema = $this->container->get('database')->schema();
499 $all_tables_exist = TRUE; 499 $all_tables_exist = TRUE;
500 foreach ($tables as $table) { 500 foreach ($tables as $table) {
501 if (!$db_schema->tableExists($table)) { 501 if (!$db_schema->tableExists($table)) {
502 $this->fail(SafeMarkup::format('Installed entity type table for the %entity_type entity type: %table', [ 502 $this->fail(new FormattableMarkup('Installed entity type table for the %entity_type entity type: %table', [
503 '%entity_type' => $entity_type_id, 503 '%entity_type' => $entity_type_id,
504 '%table' => $table, 504 '%table' => $table,
505 ])); 505 ]));
506 $all_tables_exist = FALSE; 506 $all_tables_exist = FALSE;
507 } 507 }
508 } 508 }
509 if ($all_tables_exist) { 509 if ($all_tables_exist) {
510 $this->pass(SafeMarkup::format('Installed entity type tables for the %entity_type entity type: %tables', [ 510 $this->pass(new FormattableMarkup('Installed entity type tables for the %entity_type entity type: %tables', [
511 '%entity_type' => $entity_type_id, 511 '%entity_type' => $entity_type_id,
512 '%tables' => '{' . implode('}, {', $tables) . '}', 512 '%tables' => '{' . implode('}, {', $tables) . '}',
513 ])); 513 ]));
514 } 514 }
515 } 515 }