Mercurial > hg > isophonics-drupal-site
comparison core/tests/Drupal/KernelTests/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 | c2387f117808 |
children | af1871eacc83 |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
4 | 4 |
5 use Drupal\Component\FileCache\ApcuFileCacheBackend; | 5 use Drupal\Component\FileCache\ApcuFileCacheBackend; |
6 use Drupal\Component\FileCache\FileCache; | 6 use Drupal\Component\FileCache\FileCache; |
7 use Drupal\Component\FileCache\FileCacheFactory; | 7 use Drupal\Component\FileCache\FileCacheFactory; |
8 use Drupal\Component\Utility\Html; | 8 use Drupal\Component\Utility\Html; |
9 use Drupal\Component\Utility\SafeMarkup; | 9 use Drupal\Component\Render\FormattableMarkup; |
10 use Drupal\Core\Config\Development\ConfigSchemaChecker; | 10 use Drupal\Core\Config\Development\ConfigSchemaChecker; |
11 use Drupal\Core\Database\Database; | 11 use Drupal\Core\Database\Database; |
12 use Drupal\Core\DependencyInjection\ContainerBuilder; | 12 use Drupal\Core\DependencyInjection\ContainerBuilder; |
13 use Drupal\Core\DependencyInjection\ServiceProviderInterface; | 13 use Drupal\Core\DependencyInjection\ServiceProviderInterface; |
14 use Drupal\Core\DrupalKernel; | 14 use Drupal\Core\DrupalKernel; |
15 use Drupal\Core\Entity\Sql\SqlEntityStorageInterface; | 15 use Drupal\Core\Entity\Sql\SqlEntityStorageInterface; |
16 use Drupal\Core\Extension\ExtensionDiscovery; | 16 use Drupal\Core\Extension\ExtensionDiscovery; |
17 use Drupal\Core\Language\Language; | 17 use Drupal\Core\Language\Language; |
18 use Drupal\Core\Site\Settings; | 18 use Drupal\Core\Site\Settings; |
19 use Drupal\Core\Test\TestDatabase; | 19 use Drupal\Core\Test\TestDatabase; |
20 use Drupal\simpletest\AssertContentTrait; | |
21 use Drupal\Tests\AssertHelperTrait; | 20 use Drupal\Tests\AssertHelperTrait; |
22 use Drupal\Tests\ConfigTestTrait; | 21 use Drupal\Tests\ConfigTestTrait; |
23 use Drupal\Tests\PhpunitCompatibilityTrait; | 22 use Drupal\Tests\PhpunitCompatibilityTrait; |
24 use Drupal\Tests\RandomGeneratorTrait; | 23 use Drupal\Tests\RandomGeneratorTrait; |
25 use Drupal\Tests\TestRequirementsTrait; | 24 use Drupal\Tests\TestRequirementsTrait; |
26 use Drupal\simpletest\TestServiceProvider; | |
27 use PHPUnit\Framework\TestCase; | 25 use PHPUnit\Framework\TestCase; |
28 use Symfony\Component\DependencyInjection\Reference; | 26 use Symfony\Component\DependencyInjection\Reference; |
29 use Symfony\Component\HttpFoundation\Request; | 27 use Symfony\Component\HttpFoundation\Request; |
30 use org\bovigo\vfs\vfsStream; | 28 use org\bovigo\vfs\vfsStream; |
31 use org\bovigo\vfs\visitor\vfsStreamPrintVisitor; | 29 use org\bovigo\vfs\visitor\vfsStreamPrintVisitor; |
460 Database::renameConnection('default', 'simpletest_original_default'); | 458 Database::renameConnection('default', 'simpletest_original_default'); |
461 foreach ($connection_info as $target => $value) { | 459 foreach ($connection_info as $target => $value) { |
462 // Replace the full table prefix definition to ensure that no table | 460 // Replace the full table prefix definition to ensure that no table |
463 // prefixes of the test runner leak into the test. | 461 // prefixes of the test runner leak into the test. |
464 $connection_info[$target]['prefix'] = [ | 462 $connection_info[$target]['prefix'] = [ |
465 'default' => $value['prefix']['default'] . $this->databasePrefix, | 463 'default' => $this->databasePrefix, |
466 ]; | 464 ]; |
467 } | 465 } |
468 } | 466 } |
469 return $connection_info; | 467 return $connection_info; |
470 } | 468 } |
761 $tables = $storage->getTableMapping()->getTableNames(); | 759 $tables = $storage->getTableMapping()->getTableNames(); |
762 $db_schema = $this->container->get('database')->schema(); | 760 $db_schema = $this->container->get('database')->schema(); |
763 $all_tables_exist = TRUE; | 761 $all_tables_exist = TRUE; |
764 foreach ($tables as $table) { | 762 foreach ($tables as $table) { |
765 if (!$db_schema->tableExists($table)) { | 763 if (!$db_schema->tableExists($table)) { |
766 $this->fail(SafeMarkup::format('Installed entity type table for the %entity_type entity type: %table', [ | 764 $this->fail(new FormattableMarkup('Installed entity type table for the %entity_type entity type: %table', [ |
767 '%entity_type' => $entity_type_id, | 765 '%entity_type' => $entity_type_id, |
768 '%table' => $table, | 766 '%table' => $table, |
769 ])); | 767 ])); |
770 $all_tables_exist = FALSE; | 768 $all_tables_exist = FALSE; |
771 } | 769 } |
772 } | 770 } |
773 if ($all_tables_exist) { | 771 if ($all_tables_exist) { |
774 $this->pass(SafeMarkup::format('Installed entity type tables for the %entity_type entity type: %tables', [ | 772 $this->pass(new FormattableMarkup('Installed entity type tables for the %entity_type entity type: %tables', [ |
775 '%entity_type' => $entity_type_id, | 773 '%entity_type' => $entity_type_id, |
776 '%tables' => '{' . implode('}, {', $tables) . '}', | 774 '%tables' => '{' . implode('}, {', $tables) . '}', |
777 ])); | 775 ])); |
778 } | 776 } |
779 } | 777 } |
812 | 810 |
813 // Perform an ExtensionDiscovery scan as this function may receive a | 811 // Perform an ExtensionDiscovery scan as this function may receive a |
814 // profile that is not the current profile, and we don't yet have a cached | 812 // profile that is not the current profile, and we don't yet have a cached |
815 // way to receive inactive profile information. | 813 // way to receive inactive profile information. |
816 // @todo Remove as part of https://www.drupal.org/node/2186491 | 814 // @todo Remove as part of https://www.drupal.org/node/2186491 |
817 $listing = new ExtensionDiscovery(\Drupal::root()); | 815 $listing = new ExtensionDiscovery($this->root); |
818 $module_list = $listing->scan('module'); | 816 $module_list = $listing->scan('module'); |
819 // In ModuleHandlerTest we pass in a profile as if it were a module. | 817 // In ModuleHandlerTest we pass in a profile as if it were a module. |
820 $module_list += $listing->scan('profile'); | 818 $module_list += $listing->scan('profile'); |
821 | 819 |
822 // Set the list of modules in the extension handler. | 820 // Set the list of modules in the extension handler. |
934 * @param bool|string|int|array|null $value | 932 * @param bool|string|int|array|null $value |
935 * The value to set. Note that array values are replaced entirely; use | 933 * The value to set. Note that array values are replaced entirely; use |
936 * \Drupal\Core\Site\Settings::get() to perform custom merges. | 934 * \Drupal\Core\Site\Settings::get() to perform custom merges. |
937 */ | 935 */ |
938 protected function setSetting($name, $value) { | 936 protected function setSetting($name, $value) { |
937 if ($name === 'install_profile') { | |
938 @trigger_error('Use \Drupal\KernelTests\KernelTestBase::setInstallProfile() to set the install profile in kernel tests. See https://www.drupal.org/node/2538996', E_USER_DEPRECATED); | |
939 $this->setInstallProfile($value); | |
940 } | |
939 $settings = Settings::getInstance() ? Settings::getAll() : []; | 941 $settings = Settings::getInstance() ? Settings::getAll() : []; |
940 $settings[$name] = $value; | 942 $settings[$name] = $value; |
941 new Settings($settings); | 943 new Settings($settings); |
944 } | |
945 | |
946 /** | |
947 * Sets the install profile and rebuilds the container to update it. | |
948 * | |
949 * @param string $profile | |
950 * The install profile to set. | |
951 */ | |
952 protected function setInstallProfile($profile) { | |
953 $this->container->get('config.factory') | |
954 ->getEditable('core.extension') | |
955 ->set('profile', $profile) | |
956 ->save(); | |
957 | |
958 // The installation profile is provided by a container parameter. Saving | |
959 // the configuration doesn't automatically trigger invalidation | |
960 $this->container->get('kernel')->rebuildContainer(); | |
942 } | 961 } |
943 | 962 |
944 /** | 963 /** |
945 * Stops test execution. | 964 * Stops test execution. |
946 */ | 965 */ |