Skip to content
Snippets Groups Projects
Unverified Commit 7f543411 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3475719 by daffie, mondrake, alexpott: Set entity schema installation,...

Issue #3475719 by daffie, mondrake, alexpott: Set entity schema installation, module configuration installation and content creation in the right order in kerneltests for MongoDB
parent 6728ca19
No related branches found
No related tags found
13 merge requests!11197Issue #3506427 by eduardo morales alberti: Remove responsive_image.ajax from hook,!11131[10.4.x-only-DO-NOT-MERGE]: Issue ##2842525 Ajax attached to Views exposed filter form does not trigger callbacks,!10786Issue #3490579 by shalini_jha, mstrelan: Add void return to all views...,!5423Draft: Resolve #3329907 "Test2",!3878Removed unused condition head title for views,!3818Issue #2140179: $entity->original gets stale between updates,!3478Issue #3337882: Deleted menus are not removed from content type config,!3154Fixes #2987987 - CSRF token validation broken on routes with optional parameters.,!2964Issue #2865710 : Dependencies from only one instance of a widget are used in display modes,!2062Issue #3246454: Add weekly granularity to views date sort,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!579Issue #2230909: Simple decimals fail to pass validation,!213Issue #2906496: Give Media a menu item under Content
Pipeline #368534 passed with warnings
Pipeline: drupal

#368547

    Pipeline: drupal

    #368541

      Pipeline: drupal

      #368536

        Showing
        with 121 additions and 4 deletions
        ......@@ -26910,7 +26910,7 @@
        ];
        $ignoreErrors[] = [
        // identifier: missingType.return
        'message' => '#^Method class@anonymous/core/modules/media/tests/src/Kernel/OEmbedResourceConstraintValidatorTest\\.php\\:107\\:\\:getEntity\\(\\) has no return type specified\\.$#',
        'message' => '#^Method class@anonymous/core/modules/media/tests/src/Kernel/OEmbedResourceConstraintValidatorTest\\.php\\:108\\:\\:getEntity\\(\\) has no return type specified\\.$#',
        'count' => 1,
        'path' => __DIR__ . '/modules/media/tests/src/Kernel/OEmbedResourceConstraintValidatorTest.php',
        ];
        <?php
        namespace Drupal\Core\Test\EventSubscriber;
        use Drupal\Core\Database\Connection;
        use Drupal\Core\Database\Schema;
        use Drupal\Core\Entity\EntityTypeManagerInterface;
        use Drupal\Core\Entity\Sql\SqlEntityStorageInterface;
        use Drupal\Core\Field\FieldStorageDefinitionEvent;
        use Drupal\Core\Field\FieldStorageDefinitionEvents;
        use Symfony\Component\EventDispatcher\EventSubscriberInterface;
        /**
        * Response subscriber to field storage events.
        *
        * In Kernel test field storages can be created without the entity schema, on
        * which the field storage is based, not being created. For database driver that
        * store the whole entity instance in a single JSON object, like the database
        * driver for MongoDB is doing, the kernel test will fail.
        *
        * @internal
        */
        final class FieldStorageCreateCheckSubscriber implements EventSubscriberInterface {
        /**
        * The schema object for this connection.
        */
        protected Schema $schema;
        /**
        * Constructs the FieldStorageCreateCheckSubscriber object.
        *
        * @param \Drupal\Core\Database\Connection $connection
        * The database connection.
        * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
        * The entity type manager service.
        * @param bool $throwLogicExceptionOrDeprecationWarning
        * When the value is TRUE a LogicException will be thrown, when the value is
        * FALSE a deprecation warning will be given. The value defaults to FALSE.
        */
        public function __construct(
        protected Connection $connection,
        protected EntityTypeManagerInterface $entityTypeManager,
        private readonly bool $throwLogicExceptionOrDeprecationWarning = FALSE,
        ) {
        $this->schema = $this->connection->schema();
        }
        /**
        * Gets the subscribed events.
        *
        * @return array
        * An array of subscribed event names.
        *
        * @see \Symfony\Component\EventDispatcher\EventSubscriberInterface::getSubscribedEvents()
        */
        public static function getSubscribedEvents(): array {
        return [
        FieldStorageDefinitionEvents::CREATE => ['onFieldStorageDefinitionCreateEvent'],
        ];
        }
        /**
        * Listener method for any field storage definition create event.
        *
        * @param \Drupal\Core\Field\FieldStorageDefinitionEvent $event
        * The field storage definition event object.
        * @param string $event_name
        * The event name.
        */
        public function onFieldStorageDefinitionCreateEvent(FieldStorageDefinitionEvent $event, $event_name): void {
        $entity_type_id = $event->getFieldStorageDefinition()->getTargetEntityTypeId();
        if ($entity_type_id) {
        $storage = $this->entityTypeManager->getStorage($entity_type_id);
        if ($storage instanceof SqlEntityStorageInterface) {
        $base_table = $storage->getTableMapping()->getBaseTable();
        if (!$this->schema->tableExists($base_table)) {
        if ($this->throwLogicExceptionOrDeprecationWarning) {
        throw new \LogicException(sprintf('Creating the "%s" field storage definition without the entity schema "%s" being installed is not allowed.',
        $event->getFieldStorageDefinition()->id(),
        $entity_type_id,
        ));
        }
        else {
        @trigger_error('Creating the "' . $event->getFieldStorageDefinition()->id() . '" field storage definition without the entity schema "' . $entity_type_id . '" being installed is deprecated in drupal:11.2.0 and will be replaced by a LogicException in drupal:12.0.0. See https://www.drupal.org/node/3493981', E_USER_DEPRECATED);
        }
        }
        }
        }
        }
        }
        ......@@ -37,6 +37,7 @@ class CommentUninstallTest extends KernelTestBase {
        protected function setUp(): void {
        parent::setUp();
        $this->installEntitySchema('node');
        $this->installEntitySchema('comment');
        $this->installConfig(['comment']);
        $this->installSchema('user', ['users_data']);
        ......
        ......@@ -41,6 +41,7 @@ class AddModerationConfigActionTest extends KernelTestBase {
        ];
        public function testAddEntityTypeAndBundle(): void {
        $this->installEntitySchema('node');
        $this->installConfig('node');
        $this->createContentType(['type' => 'a']);
        ......
        ......@@ -35,6 +35,7 @@ class AddToAllBundlesConfigActionTest extends KernelTestBase {
        protected function setUp(): void {
        parent::setUp();
        $this->installEntitySchema('node');
        NodeType::create([
        'type' => 'one',
        'name' => 'One',
        ......
        ......@@ -18,7 +18,7 @@ class ConfigActionsTest extends KernelTestBase {
        /**
        * {@inheritdoc}
        */
        protected static $modules = ['entity_test', 'field'];
        protected static $modules = ['entity_test', 'field', 'user'];
        private readonly ConfigActionManager $configActionManager;
        ......@@ -28,6 +28,8 @@ class ConfigActionsTest extends KernelTestBase {
        protected function setUp(): void {
        parent::setUp();
        $this->installEntitySchema('entity_test');
        $this->installEntitySchema('entity_test_with_bundle');
        EntityTestBundle::create([
        'id' => 'test',
        'label' => $this->randomString(),
        ......
        ......@@ -30,6 +30,7 @@ class FieldConfigValidationTest extends ConfigEntityValidationTestBase {
        protected function setUp(): void {
        parent::setUp();
        $this->installEntitySchema('node');
        $this->installConfig('node');
        $this->createContentType(['type' => 'one']);
        $this->createContentType(['type' => 'another']);
        ......@@ -70,6 +71,7 @@ public function testInvalidDependencies(): void {
        * Tests validation of a field_config's default value.
        */
        public function testMultilineTextFieldDefaultValue(): void {
        $this->installEntitySchema('user');
        // First, create a field storage for which a complex default value exists.
        $this->enableModules(['text']);
        $text_field_storage_config = FieldStorageConfig::create([
        ......
        ......@@ -26,6 +26,7 @@ class FieldEntitySettingsTest extends KernelTestBase {
        */
        protected function setUp(): void {
        parent::setUp();
        $this->installEntitySchema('entity_test_with_bundle');
        EntityTestBundle::create(['id' => 'test', 'label' => 'Test'])->save();
        }
        ......
        ......@@ -60,6 +60,7 @@ protected function setUp(): void {
        $this->installConfig(['entity_reference_test', 'filter']);
        $this->installEntitySchema('user');
        $this->installEntitySchema('node');
        $this->installEntitySchema('entity_test');
        // Create test nodes.
        $type = $this->randomMachineName();
        ......
        ......@@ -40,6 +40,7 @@ class ContentLanguageSettingsValidationTest extends ConfigEntityValidationTestBa
        */
        protected function setUp(): void {
        parent::setUp();
        $this->installEntitySchema('node');
        $this->installConfig('node');
        $this->createContentType(['type' => 'alpha']);
        ......
        ......@@ -31,6 +31,7 @@ public function testLayoutBuilderActions(): void {
        /** @var \Drupal\Core\Config\Action\ConfigActionManager $manager */
        $manager = $this->container->get('plugin.manager.config_action');
        $this->installEntitySchema('entity_test_with_bundle');
        EntityTestBundle::create(['id' => 'test'])->save();
        /** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */
        ......
        ......@@ -39,6 +39,7 @@ class LayoutBuilderEntityViewDisplayValidationTest extends ConfigEntityValidatio
        protected function setUp(): void {
        parent::setUp();
        $this->installEntitySchema('node');
        $this->installConfig('node');
        $this->createContentType(['type' => 'one']);
        $this->createContentType(['type' => 'two']);
        ......
        ......@@ -29,6 +29,7 @@ class MediaMappingsConstraintValidatorTest extends KernelTestBase {
        protected function setUp(): void {
        parent::setUp();
        $this->installEntitySchema('file');
        $this->installEntitySchema('media');
        $this->installEntitySchema('user');
        }
        ......
        ......@@ -48,6 +48,7 @@ class MediaThumbnailFormatterTest extends MediaKernelTestBase {
        */
        protected function setUp(): void {
        parent::setUp();
        $this->installEntitySchema('entity_test_with_bundle');
        // Create an entity bundle that has a media reference field.
        $entity_test_bundle = EntityTestBundle::create([
        'id' => $this->testEntityBundleId,
        ......
        ......@@ -19,13 +19,17 @@ class MediaTypeValidationTest extends ConfigEntityValidationTestBase {
        /**
        * {@inheritdoc}
        */
        protected static $modules = ['field', 'media', 'media_test_source'];
        protected static $modules = ['field', 'media', 'media_test_source', 'user', 'image'];
        /**
        * {@inheritdoc}
        */
        protected function setUp(): void {
        parent::setUp();
        $this->installEntitySchema('user');
        $this->installEntitySchema('media');
        $this->entity = $this->createMediaType('test', ['id' => 'test_media']);
        }
        ......
        ......@@ -36,6 +36,7 @@ protected function setUp(): void {
        parent::setUp();
        $this->installEntitySchema('file');
        $this->installEntitySchema('user');
        $this->installEntitySchema('media');
        }
        /**
        ......
        ......@@ -52,6 +52,7 @@ private function assertMenuNamesAreSorted(NodeType $node_type): void {
        * Tests node type-specific settings for Menu UI.
        */
        public function testContentTypeMenuSettings(): void {
        $this->installEntitySchema('node');
        $this->installConfig(['node']);
        Menu::create(['id' => 'a', 'label' => 'Z'])->save();
        Menu::create(['id' => 'b', 'label' => 'X'])->save();
        ......
        ......@@ -28,6 +28,8 @@ class ConfigActionsTest extends KernelTestBase {
        */
        protected function setUp(): void {
        parent::setUp();
        $this->installEntitySchema('node');
        $this->installConfig('node');
        $this->configActionManager = $this->container->get('plugin.manager.config_action');
        }
        ......
        ......@@ -35,6 +35,7 @@ class NodeTypeValidationTest extends ConfigEntityValidationTestBase {
        */
        protected function setUp(): void {
        parent::setUp();
        $this->installEntitySchema('node');
        $this->installConfig('node');
        $this->entity = $this->createContentType();
        }
        ......
        ......@@ -22,7 +22,7 @@ class TextItemBaseTest extends KernelTestBase {
        /**
        * {@inheritdoc}
        */
        protected static $modules = ['filter', 'text', 'entity_test', 'field'];
        protected static $modules = ['filter', 'text', 'entity_test', 'field', 'user'];
        /**
        * Tests creation of sample values.
        ......@@ -67,6 +67,8 @@ public static function providerTextFieldSampleValue() {
        * @covers ::calculateDependencies
        */
        public function testCalculateDependencies(): void {
        $this->installEntitySchema('user');
        $this->installEntitySchema('entity_test');
        $format = FilterFormat::create([
        'format' => 'test_format',
        'name' => 'Test format',
        ......
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Please to comment