Commit 137b3fe2 authored by catch's avatar catch
Browse files

task: #3556693 Change use of Contact in ContentEntityNullStorageTest

By: @andypost
By: @berdir
(cherry picked from commit ad1cf48b)
parent 4355ee0a
Loading
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -37,3 +37,14 @@ entity_test.entity_test_bundle.*:
entity_test.entity_test_mul_bundle.*:
  type: entity_test.entity_test_bundle.*
  label: 'Entity test mul bundle'

entity_test.entity_test_no_id_bundle.*:
  type: config_entity
  label: 'Entity test no ID bundle'
  mapping:
    label:
      type: label
      label: 'Label'
    id:
      type: string
      label: 'Machine-readable name'
+1 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@
    'add-page' => '/entity_test_no_id/add',
  ],
  admin_permission: 'administer entity_test content',
  bundle_entity_type: 'entity_test_no_id_bundle',
  field_ui_base_route: 'entity.entity_test_no_id.admin_form',
)]
class EntityTestNoId extends EntityTest {
+64 −0
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

namespace Drupal\entity_test\Entity;

use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
use Drupal\Core\Entity\Attribute\ConfigEntityType;
use Drupal\Core\Entity\BundleEntityFormBase;
use Drupal\Core\Entity\EntityAccessControlHandler;
use Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider;
use Drupal\Core\StringTranslation\TranslatableMarkup;

/**
 * Defines the entity_test_no_id bundle configuration entity.
 */
#[ConfigEntityType(
  id: 'entity_test_no_id_bundle',
  label: new TranslatableMarkup('Entity Test without id bundle'),
  config_prefix: 'entity_test_no_id_bundle',
  entity_keys: [
    'id' => 'id',
    'label' => 'label',
  ],
  handlers: [
    'access' => EntityAccessControlHandler::class,
    'form' => [
      'default' => BundleEntityFormBase::class,
      'add' => BundleEntityFormBase::class,
      'edit' => BundleEntityFormBase::class,
    ],
    'route_provider' => [
      'html' => DefaultHtmlRouteProvider::class,
    ],
  ],
  links: [
    'add-form' => '/admin/structure/entity_test_no_id_bundle/add',
    'edit-form' => '/admin/structure/entity_test_no_id_bundle/manage/{entity_test_no_id_bundle}',
    'collection' => '/admin/structure/entity_test_no_id_bundle',
  ],
  admin_permission: 'administer entity_test content',
  bundle_of: 'entity_test_no_id',
  config_export: [
    'id',
    'label',
  ],
)]
class EntityTestNoIdBundle extends ConfigEntityBundleBase {

  /**
   * The machine name.
   *
   * @var string
   */
  protected $id;

  /**
   * The human-readable name.
   *
   * @var string
   */
  protected $label;

}
+12 −12
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@

namespace Drupal\KernelTests\Core\Entity;

use Drupal\contact\Entity\ContactForm;
use Drupal\entity_test\Entity\EntityTestNoIdBundle;
use Drupal\Core\Config\ConfigImporterFactory;
use Drupal\Core\Config\StorageComparer;
use Drupal\KernelTests\KernelTestBase;
@@ -24,7 +24,7 @@ class ContentEntityNullStorageTest extends KernelTestBase {
  /**
   * {@inheritdoc}
   */
  protected static $modules = ['system', 'contact', 'user'];
  protected static $modules = ['system', 'entity_test', 'user'];

  /**
   * Tests using entity query with ContentEntityNullStorage.
@@ -32,22 +32,22 @@ class ContentEntityNullStorageTest extends KernelTestBase {
   * @see \Drupal\Core\Entity\Query\Null\Query
   */
  public function testEntityQuery(): void {
    $this->assertSame(0, \Drupal::entityQuery('contact_message')->accessCheck(FALSE)->count()->execute(), 'Counting a null storage returns 0.');
    $this->assertSame([], \Drupal::entityQuery('contact_message')->accessCheck(FALSE)->execute(), 'Querying a null storage returns an empty array.');
    $this->assertSame([], \Drupal::entityQuery('contact_message')->accessCheck(FALSE)->condition('contact_form', 'test')->execute(), 'Querying a null storage returns an empty array and conditions are ignored.');
    $this->assertSame([], \Drupal::entityQueryAggregate('contact_message')->accessCheck(FALSE)->aggregate('name', 'AVG')->execute(), 'Aggregate querying a null storage returns an empty array');
    $this->assertSame(0, \Drupal::entityQuery('entity_test_no_id')->accessCheck(FALSE)->count()->execute(), 'Counting a null storage returns 0.');
    $this->assertSame([], \Drupal::entityQuery('entity_test_no_id')->accessCheck(FALSE)->execute(), 'Querying a null storage returns an empty array.');
    $this->assertSame([], \Drupal::entityQuery('entity_test_no_id')->accessCheck(FALSE)->condition('type', 'test')->execute(), 'Querying a null storage returns an empty array and conditions are ignored.');
    $this->assertSame([], \Drupal::entityQueryAggregate('entity_test_no_id')->accessCheck(FALSE)->aggregate('name', 'AVG')->execute(), 'Aggregate querying a null storage returns an empty array');

  }

  /**
   * Tests deleting a contact form entity via a configuration import.
   * Tests deleting an entity test no ID bundle entity via a configuration import.
   *
   * @see \Drupal\Core\Entity\Event\BundleConfigImportValidate
   */
  public function testDeleteThroughImport(): void {
    $this->installConfig(['system']);
    $contact_form = ContactForm::create(['id' => 'test', 'label' => 'Test contact form']);
    $contact_form->save();
    $entity_test_no_id_bundle = EntityTestNoIdBundle::create(['id' => 'test', 'label' => 'Test entity test no ID bundle']);
    $entity_test_no_id_bundle->save();

    $this->copyConfig($this->container->get('config.storage'), $this->container->get('config.storage.sync'));

@@ -58,13 +58,13 @@ public function testDeleteThroughImport(): void {
    );
    $config_importer = $this->container->get(ConfigImporterFactory::class)->get($storage_comparer->createChangelist());

    // Delete the contact message in sync.
    // Delete the entity test no ID bundle in sync.
    $sync = $this->container->get('config.storage.sync');
    $sync->delete($contact_form->getConfigDependencyName());
    $sync->delete($entity_test_no_id_bundle->getConfigDependencyName());

    // Import.
    $config_importer->reset()->import();
    $this->assertNull(ContactForm::load($contact_form->id()), 'The contact form has been deleted.');
    $this->assertNull(EntityTestNoIdBundle::load($entity_test_no_id_bundle->id()), 'The entity test no ID bundle has been deleted.');
  }

}