Revert "Issue #3393800 by mstrelan, dww, acbramley, amateescu, smustgrave, quietone: Kernel tests can't use path aliases on entities"

This reverts commit 97bdbe883c.
merge-requests/5828/head
Lee Rowlands 2023-12-22 14:16:21 +10:00
parent fdacae95f3
commit ebdb093f3d
No known key found for this signature in database
GPG Key ID: 2B829A3DF9204DC4
17 changed files with 55 additions and 68 deletions

View File

@ -34,7 +34,6 @@ class MigrateBlockContentTranslationTest extends MigrateDrupal6TestBase {
protected function setUp(): void { protected function setUp(): void {
parent::setUp(); parent::setUp();
$this->installEntitySchema('block_content'); $this->installEntitySchema('block_content');
$this->installEntitySchema('path_alias');
$this->installConfig(['block']); $this->installConfig(['block']);
$this->installConfig(['block_content']); $this->installConfig(['block_content']);
$this->container->get('theme_installer')->install(['stark']); $this->container->get('theme_installer')->install(['stark']);

View File

@ -32,7 +32,6 @@ class MigrateBlockTest extends MigrateDrupal6TestBase {
*/ */
protected function setUp(): void { protected function setUp(): void {
parent::setUp(); parent::setUp();
$this->installEntitySchema('path_alias');
// Install the themes used for this test. // Install the themes used for this test.
$this->installEntitySchema('block_content'); $this->installEntitySchema('block_content');

View File

@ -37,7 +37,6 @@ class MigrateBlockContentTranslationTest extends MigrateDrupal7TestBase {
protected function setUp(): void { protected function setUp(): void {
parent::setUp(); parent::setUp();
$this->installEntitySchema('block_content'); $this->installEntitySchema('block_content');
$this->installEntitySchema('path_alias');
$this->installConfig(['block']); $this->installConfig(['block']);
$this->installConfig(['block_content']); $this->installConfig(['block_content']);
$this->container->get('theme_installer')->install(['stark']); $this->container->get('theme_installer')->install(['stark']);

View File

@ -37,7 +37,6 @@ class MigrateBlockNoBlockContentTest extends MigrateDrupal7TestBase {
$this->container->get('theme_installer')->install(['olivero', 'claro']); $this->container->get('theme_installer')->install(['olivero', 'claro']);
$this->installConfig(static::$modules); $this->installConfig(static::$modules);
$this->installEntitySchema('path_alias');
// Set Olivero and Claro as the default public and admin theme. // Set Olivero and Claro as the default public and admin theme.
$config = $this->config('system.theme'); $config = $this->config('system.theme');

View File

@ -34,7 +34,6 @@ class MigrateBlockTest extends MigrateDrupal7TestBase {
*/ */
protected function setUp(): void { protected function setUp(): void {
parent::setUp(); parent::setUp();
$this->installEntitySchema('path_alias');
// Install the themes used for this test. // Install the themes used for this test.
$this->installEntitySchema('block_content'); $this->installEntitySchema('block_content');

View File

@ -2,6 +2,7 @@
namespace Drupal\Tests\menu_link_content\Kernel; namespace Drupal\Tests\menu_link_content\Kernel;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Menu\MenuTreeParameters; use Drupal\Core\Menu\MenuTreeParameters;
use Drupal\menu_link_content\Entity\MenuLinkContent; use Drupal\menu_link_content\Entity\MenuLinkContent;
use Drupal\KernelTests\KernelTestBase; use Drupal\KernelTests\KernelTestBase;
@ -44,6 +45,17 @@ class PathAliasMenuLinkContentTest extends KernelTestBase {
module_set_weight('menu_link_content', 1); module_set_weight('menu_link_content', 1);
} }
/**
* {@inheritdoc}
*/
public function register(ContainerBuilder $container) {
parent::register($container);
$definition = $container->getDefinition('path_alias.path_processor');
$definition
->addTag('path_processor_inbound', ['priority' => 100]);
}
/** /**
* Tests the path aliasing changing. * Tests the path aliasing changing.
*/ */

View File

@ -1,49 +0,0 @@
<?php
declare(strict_types = 1);
namespace Drupal\Tests\path_alias\Kernel;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\Traits\Core\PathAliasTestTrait;
/**
* Tests path alias on entities.
*
* @group path_alias
*/
class EntityAliasTest extends KernelTestBase {
use PathAliasTestTrait;
/**
* {@inheritdoc}
*/
protected static $modules = [
'path_alias',
'entity_test',
'user',
];
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->installEntitySchema('entity_test');
$this->installEntitySchema('path_alias');
$this->installEntitySchema('user');
}
/**
* Tests transform.
*/
public function testEntityAlias(): void {
EntityTest::create(['id' => 1])->save();
$this->createPathAlias('/entity_test/1', '/entity-alias');
$entity = EntityTest::load(1);
$this->assertSame('/entity-alias', $entity->toUrl()->toString());
}
}

View File

@ -37,6 +37,7 @@ class RssFieldsTest extends ViewsKernelTestBase {
$this->installConfig(['node', 'filter']); $this->installConfig(['node', 'filter']);
$this->installEntitySchema('user'); $this->installEntitySchema('user');
$this->installEntitySchema('node'); $this->installEntitySchema('node');
$this->installEntitySchema('path_alias');
$this->createContentType(['type' => 'article']); $this->createContentType(['type' => 'article']);
} }

View File

@ -12,13 +12,6 @@ use Drupal\views\Plugin\views\PluginBase;
*/ */
class PluginInstanceTest extends ViewsKernelTestBase { class PluginInstanceTest extends ViewsKernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'path_alias',
];
/** /**
* All views plugin types. * All views plugin types.
* *

View File

@ -28,6 +28,7 @@ abstract class ViewsKernelTestBase extends KernelTestBase {
* {@inheritdoc} * {@inheritdoc}
*/ */
protected static $modules = [ protected static $modules = [
'path_alias',
'system', 'system',
'views', 'views',
'views_test_config', 'views_test_config',

View File

@ -20,7 +20,7 @@ class WorkspaceViewsKernelTest extends ViewsKernelTestBase {
* *
* @var array * @var array
*/ */
protected static $modules = ['views_ui', 'workspaces', 'path_alias']; protected static $modules = ['views_ui', 'workspaces'];
/** /**
* Tests creating a view of workspace entities. * Tests creating a view of workspace entities.

View File

@ -120,10 +120,6 @@ class ResolvedLibraryDefinitionsFilesMatchTest extends KernelTestBase {
// @todo Remove this in https://www.drupal.org/node/3039217. // @todo Remove this in https://www.drupal.org/node/3039217.
$this->installEntitySchema('user'); $this->installEntitySchema('user');
// Install the 'path_alias' entity schema because the path alias path
// processor requires it.
$this->installEntitySchema('path_alias');
// Remove demo_umami_content module as its install hook creates content // Remove demo_umami_content module as its install hook creates content
// that relies on the presence of entity tables and various other elements // that relies on the presence of entity tables and various other elements
// not present in a kernel test. // not present in a kernel test.

View File

@ -40,7 +40,6 @@ class ModuleConfigureRouteTest extends KernelTestBase {
parent::setUp(); parent::setUp();
$this->routeProvider = \Drupal::service('router.route_provider'); $this->routeProvider = \Drupal::service('router.route_provider');
$this->moduleInfo = \Drupal::service('extension.list.module')->getList(); $this->moduleInfo = \Drupal::service('extension.list.module')->getList();
$this->installEntitySchema('path_alias');
} }
/** /**

View File

@ -2,6 +2,7 @@
namespace Drupal\KernelTests\Core\Routing; namespace Drupal\KernelTests\Core\Routing;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\KernelTests\KernelTestBase; use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\Traits\Core\PathAliasTestTrait; use Drupal\Tests\Traits\Core\PathAliasTestTrait;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@ -30,6 +31,20 @@ class ContentNegotiationRoutingTest extends KernelTestBase {
$this->installEntitySchema('path_alias'); $this->installEntitySchema('path_alias');
} }
/**
* {@inheritdoc}
*/
public function register(ContainerBuilder $container) {
parent::register($container);
// \Drupal\KernelTests\KernelTestBase::register() removes the alias path
// processor.
if ($container->hasDefinition('path_alias.path_processor')) {
$definition = $container->getDefinition('path_alias.path_processor');
$definition->addTag('path_processor_inbound', ['priority' => 100])->addTag('path_processor_outbound', ['priority' => 300]);
}
}
/** /**
* Tests the content negotiation aspect of routing. * Tests the content negotiation aspect of routing.
*/ */

View File

@ -5,6 +5,7 @@ namespace Drupal\KernelTests\Core\Routing;
use ColinODell\PsrTestLogger\TestLogger; use ColinODell\PsrTestLogger\TestLogger;
use Drupal\Core\Cache\MemoryBackend; use Drupal\Core\Cache\MemoryBackend;
use Drupal\Core\Database\Database; use Drupal\Core\Database\Database;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\KeyValueStore\KeyValueMemoryFactory; use Drupal\Core\KeyValueStore\KeyValueMemoryFactory;
use Drupal\Core\Path\CurrentPathStack; use Drupal\Core\Path\CurrentPathStack;
use Drupal\Core\Routing\MatcherDumper; use Drupal\Core\Routing\MatcherDumper;
@ -105,6 +106,19 @@ class RouteProviderTest extends KernelTestBase {
$this->logger = new TestLogger(); $this->logger = new TestLogger();
} }
/**
* {@inheritdoc}
*/
public function register(ContainerBuilder $container) {
parent::register($container);
// Read the incoming path alias for these tests.
if ($container->hasDefinition('path_alias.path_processor')) {
$definition = $container->getDefinition('path_alias.path_processor');
$definition->addTag('path_processor_inbound');
}
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View File

@ -32,7 +32,7 @@ class Stable9LibraryOverrideTest extends StableLibraryOverrideTestBase {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected static $modules = ['system', 'user']; protected static $modules = ['system', 'user', 'path_alias'];
/** /**
* {@inheritdoc} * {@inheritdoc}

View File

@ -591,6 +591,16 @@ abstract class KernelTestBase extends TestCase implements ServiceProviderInterfa
->addTag('event_subscriber'); ->addTag('event_subscriber');
} }
if ($container->hasDefinition('path_alias.path_processor')) {
// The alias-based processor requires the path_alias entity schema to be
// installed, so we prevent it from being registered to the path processor
// manager. We do this by removing the tags that the compiler pass looks
// for. This means that the URL generator can safely be used within tests.
$container->getDefinition('path_alias.path_processor')
->clearTag('path_processor_inbound')
->clearTag('path_processor_outbound');
}
// Relax the password hashing cost in tests to avoid performance issues. // Relax the password hashing cost in tests to avoid performance issues.
if ($container->hasDefinition('password')) { if ($container->hasDefinition('password')) {
$container->getDefinition('password') $container->getDefinition('password')