diff --git a/modules/next/modules/next_jsonapi/tests/src/Kernel/Controller/EntityResourceTest.php b/modules/next/modules/next_jsonapi/tests/src/Kernel/Controller/EntityResourceTest.php index 068c0cdb..a20b591f 100644 --- a/modules/next/modules/next_jsonapi/tests/src/Kernel/Controller/EntityResourceTest.php +++ b/modules/next/modules/next_jsonapi/tests/src/Kernel/Controller/EntityResourceTest.php @@ -47,10 +47,7 @@ protected function setUp(): void { $this->installConfig(['filter', 'next']); $this->installSchema('node', ['node_access']); - $type = NodeType::create([ - 'type' => 'article', - ]); - $type->save(); + NodeType::create(['type' => 'article', 'name' => 'Article'])->save(); foreach (range(1, 100) as $number) { $article = $this->createNode([ diff --git a/modules/next/src/Entity/NextEntityTypeConfig.php b/modules/next/src/Entity/NextEntityTypeConfig.php index a6241014..7fcaeef9 100644 --- a/modules/next/src/Entity/NextEntityTypeConfig.php +++ b/modules/next/src/Entity/NextEntityTypeConfig.php @@ -255,6 +255,20 @@ public function getPluginCollections() { return $collections; } + /** + * {@inheritdoc} + * + * @todo add sites with onDependencyRemoval support. + */ + public function calculateDependencies() { + parent::calculateDependencies(); + [$entity_type_id, $bundle] = explode('.', $this->id()); + $target_entity_type = $this->entityTypeManager()->getDefinition($entity_type_id); + $bundle_config_dependency = $target_entity_type->getBundleConfigDependency($bundle); + $this->addDependency($bundle_config_dependency['type'], $bundle_config_dependency['name']); + return $this; + } + /** * Wraps the site_resolver plugin manager. * diff --git a/modules/next/tests/src/Kernel/Controller/NextPreviewUrlControllerTest.php b/modules/next/tests/src/Kernel/Controller/NextPreviewUrlControllerTest.php index cd3964cb..724243a3 100644 --- a/modules/next/tests/src/Kernel/Controller/NextPreviewUrlControllerTest.php +++ b/modules/next/tests/src/Kernel/Controller/NextPreviewUrlControllerTest.php @@ -6,6 +6,7 @@ use Drupal\KernelTests\KernelTestBase; use Drupal\next\Controller\NextPreviewUrlController; use Drupal\next\Entity\NextSite; +use Drupal\node\Entity\NodeType; use Drupal\Tests\node\Traits\NodeCreationTrait; use Drupal\Tests\user\Traits\UserCreationTrait; use Symfony\Component\HttpFoundation\Request; @@ -44,6 +45,8 @@ protected function setUp(): void { $this->installConfig(['filter', 'next']); $this->installSchema('node', ['node_access']); + NodeType::create(['type' => 'page', 'name' => 'Page'])->save(); + $this->nextSite = NextSite::create([ 'label' => 'Blog', 'id' => 'blog', diff --git a/modules/next/tests/src/Kernel/Entity/NextEntityTypeConfigTest.php b/modules/next/tests/src/Kernel/Entity/NextEntityTypeConfigTest.php index c35d941a..ce72fb57 100644 --- a/modules/next/tests/src/Kernel/Entity/NextEntityTypeConfigTest.php +++ b/modules/next/tests/src/Kernel/Entity/NextEntityTypeConfigTest.php @@ -5,6 +5,7 @@ use Drupal\KernelTests\KernelTestBase; use Drupal\next\Entity\NextEntityTypeConfig; use Drupal\next\Entity\NextSite; +use Drupal\node\Entity\NodeType; use Drupal\Tests\node\Traits\NodeCreationTrait; /** @@ -42,6 +43,8 @@ protected function setUp(): void { $this->installEntitySchema('path_alias'); $this->installConfig(['filter']); $this->installSchema('node', ['node_access']); + + NodeType::create(['type' => 'page', 'name' => 'Page'])->save(); } /** @@ -169,4 +172,33 @@ public function testDraftEnabled() { $this->assertFalse($entity_type_config->isDraftEnabled()); } + /** + * Tests config dependency calculation. + */ + public function testConfigDependencies(): void { + $blog_site = NextSite::create([ + 'id' => 'blog', + ]); + $blog_site->save(); + + // Create entity type config. + /** @var \Drupal\next\Entity\NextEntityTypeConfigInterface $entity_type_config */ + $entity_type_config = NextEntityTypeConfig::create([ + 'id' => 'node.page', + 'site_resolver' => 'site_selector', + 'configuration' => [ + 'sites' => [ + 'blog' => 'blog', + ], + ], + ]); + // Saving causes dependency calculation. + $entity_type_config->save(); + self::assertEquals([ + 'config' => [ + 'node.type.page', + ], + ], $entity_type_config->getDependencies()); + } + } diff --git a/modules/next/tests/src/Kernel/Entity/NextSiteTest.php b/modules/next/tests/src/Kernel/Entity/NextSiteTest.php index 18e676f3..3aee8d8a 100644 --- a/modules/next/tests/src/Kernel/Entity/NextSiteTest.php +++ b/modules/next/tests/src/Kernel/Entity/NextSiteTest.php @@ -4,6 +4,7 @@ use Drupal\KernelTests\KernelTestBase; use Drupal\next\Entity\NextSite; +use Drupal\node\Entity\NodeType; use Drupal\Tests\node\Traits\NodeCreationTrait; use Drupal\Tests\user\Traits\UserCreationTrait; use Drupal\user\Entity\User; @@ -42,6 +43,8 @@ protected function setUp(): void { $this->installConfig(['filter', 'next']); $this->installSchema('node', ['node_access']); + NodeType::create(['type' => 'page', 'name' => 'Page'])->save(); + $this->nextSite = NextSite::create([ 'label' => 'Blog', 'id' => 'blog', diff --git a/modules/next/tests/src/Kernel/Event/EntityRevalidatedEventTest.php b/modules/next/tests/src/Kernel/Event/EntityRevalidatedEventTest.php index 6cb1761a..437f6612 100644 --- a/modules/next/tests/src/Kernel/Event/EntityRevalidatedEventTest.php +++ b/modules/next/tests/src/Kernel/Event/EntityRevalidatedEventTest.php @@ -5,6 +5,7 @@ use Drupal\dblog\Controller\DbLogController; use Drupal\KernelTests\KernelTestBase; use Drupal\next\Entity\NextEntityTypeConfig; +use Drupal\node\Entity\NodeType; use Drupal\Tests\node\Traits\NodeCreationTrait; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -45,6 +46,8 @@ protected function setUp(): void { $this->installSchema('node', ['node_access']); $this->installSchema('user', ['users_data']); + NodeType::create(['type' => 'page', 'name' => 'Page'])->save(); + // Create entity type config. $entity_type_config = NextEntityTypeConfig::create([ 'id' => 'node.page', diff --git a/modules/next/tests/src/Kernel/NextEntityTypeManagerTest.php b/modules/next/tests/src/Kernel/NextEntityTypeManagerTest.php index 80502d28..42461fc9 100644 --- a/modules/next/tests/src/Kernel/NextEntityTypeManagerTest.php +++ b/modules/next/tests/src/Kernel/NextEntityTypeManagerTest.php @@ -5,6 +5,7 @@ use Drupal\KernelTests\KernelTestBase; use Drupal\next\Entity\NextEntityTypeConfig; use Drupal\next\Entity\NextSite; +use Drupal\node\Entity\NodeType; use Drupal\Tests\node\Traits\NodeCreationTrait; /** @@ -33,6 +34,8 @@ protected function setUp(): void { $this->installEntitySchema('user'); $this->installConfig(['filter', 'next']); $this->installSchema('node', ['node_access']); + + NodeType::create(['type' => 'page', 'name' => 'Page'])->save(); } /** diff --git a/modules/next/tests/src/Kernel/Plugin/PathRevalidatorTest.php b/modules/next/tests/src/Kernel/Plugin/PathRevalidatorTest.php index c0f9af99..9b29ac13 100644 --- a/modules/next/tests/src/Kernel/Plugin/PathRevalidatorTest.php +++ b/modules/next/tests/src/Kernel/Plugin/PathRevalidatorTest.php @@ -5,6 +5,7 @@ use Drupal\KernelTests\KernelTestBase; use Drupal\next\Entity\NextEntityTypeConfig; use Drupal\next\Entity\NextSite; +use Drupal\node\Entity\NodeType; use Drupal\Tests\node\Traits\NodeCreationTrait; use GuzzleHttp\ClientInterface; use GuzzleHttp\Psr7\Response as GuzzleResponse; @@ -48,6 +49,8 @@ protected function setUp(): void { $this->installEntitySchema('path_alias'); $this->installConfig(['filter']); $this->installSchema('node', ['node_access']); + + NodeType::create(['type' => 'page', 'name' => 'Page'])->save(); } /** diff --git a/modules/next/tests/src/Kernel/Plugin/SimpleOauthPreviewUrlGeneratorTest.php b/modules/next/tests/src/Kernel/Plugin/SimpleOauthPreviewUrlGeneratorTest.php index e070141c..89757f3d 100644 --- a/modules/next/tests/src/Kernel/Plugin/SimpleOauthPreviewUrlGeneratorTest.php +++ b/modules/next/tests/src/Kernel/Plugin/SimpleOauthPreviewUrlGeneratorTest.php @@ -6,6 +6,7 @@ use Drupal\KernelTests\KernelTestBase; use Drupal\next\Entity\NextEntityTypeConfig; use Drupal\next\Entity\NextSite; +use Drupal\node\Entity\NodeType; use Drupal\Tests\node\Traits\NodeCreationTrait; use Drupal\Tests\user\Traits\UserCreationTrait; use Drupal\user\Entity\User; @@ -52,6 +53,8 @@ protected function setUp(): void { $this->installConfig(['filter', 'next']); $this->installSchema('node', ['node_access']); + NodeType::create(['type' => 'page', 'name' => 'Page'])->save(); + $this->nextSettingsManager = $this->container->get('next.settings.manager'); // Create NextSite entities. diff --git a/modules/next/tests/src/Kernel/Plugin/SiteResolverTest.php b/modules/next/tests/src/Kernel/Plugin/SiteResolverTest.php index a2671d38..0eeade35 100644 --- a/modules/next/tests/src/Kernel/Plugin/SiteResolverTest.php +++ b/modules/next/tests/src/Kernel/Plugin/SiteResolverTest.php @@ -35,18 +35,9 @@ protected function setUp(): void { $this->installConfig(['filter']); $this->installSchema('node', ['node_access']); - // Create page type. - $page_type = NodeType::create([ - 'type' => 'page', - 'label' => 'Page', - ]); - $page_type->save(); - - $article_type = NodeType::create([ - 'type' => 'article', - 'label' => 'Article', - ]); - $article_type->save(); + // Create content types. + NodeType::create(['type' => 'page', 'name' => 'Page'])->save(); + NodeType::create(['type' => 'article', 'name' => 'Article'])->save(); // Create NextSite entities. $blog = NextSite::create([ diff --git a/modules/next/tests/src/Kernel/Renderer/MainContent/HtmlRendererTest.php b/modules/next/tests/src/Kernel/Renderer/MainContent/HtmlRendererTest.php index 11e5ac63..24c1d36e 100644 --- a/modules/next/tests/src/Kernel/Renderer/MainContent/HtmlRendererTest.php +++ b/modules/next/tests/src/Kernel/Renderer/MainContent/HtmlRendererTest.php @@ -45,18 +45,9 @@ protected function setUp(): void { $this->installSchema('node', ['node_access']); $this->installSchema('user', ['users_data']); - // Create page type. - $page_type = NodeType::create([ - 'type' => 'page', - 'label' => 'Page', - ]); - $page_type->save(); - - $article_type = NodeType::create([ - 'type' => 'article', - 'label' => 'Article', - ]); - $article_type->save(); + // Create content types. + NodeType::create(['type' => 'page', 'name' => 'Page'])->save(); + NodeType::create(['type' => 'article', 'name' => 'Article'])->save(); // Create NextSite entities. $blog = NextSite::create([