diff --git a/tests/src/Kernel/AbstractTestCase.php b/tests/src/Kernel/AbstractTestCase.php new file mode 100644 index 0000000..9d771c8 --- /dev/null +++ b/tests/src/Kernel/AbstractTestCase.php @@ -0,0 +1,45 @@ + 10, ], ]; - self::assertSame($expected_build, $build); + self::assertRenderArray($expected_build, $build); // -- Wrong type. self::expectErrorMessage('The input should be either instance of Drupal\Core\Cache\CacheableDependencyInterface or array. stdClass was given.'); diff --git a/tests/src/Kernel/EntityFormViewBuilderTest.php b/tests/src/Kernel/EntityFormViewBuilderTest.php index db74c26..bcb3d7d 100644 --- a/tests/src/Kernel/EntityFormViewBuilderTest.php +++ b/tests/src/Kernel/EntityFormViewBuilderTest.php @@ -3,7 +3,6 @@ namespace Drupal\Tests\twig_tweak\Kernel; use Drupal\Core\Cache\Cache; -use Drupal\KernelTests\KernelTestBase; use Drupal\Tests\user\Traits\UserCreationTrait; use Drupal\node\Entity\Node; use Drupal\node\Entity\NodeType; @@ -13,7 +12,7 @@ use Drupal\node\Entity\NodeType; * * @group twig_tweak */ -final class EntityFormViewBuilderTest extends KernelTestBase { +final class EntityFormViewBuilderTest extends AbstractTestCase { use UserCreationTrait; @@ -47,7 +46,7 @@ final class EntityFormViewBuilderTest extends KernelTestBase { /** * Test callback. */ - public function testEntityViewBuilder(): void { + public function testEntityFormViewBuilder(): void { $view_builder = $this->container->get('twig_tweak.entity_form_view_builder'); @@ -82,7 +81,7 @@ final class EntityFormViewBuilderTest extends KernelTestBase { ], 'max-age' => 50, ]; - self::assertSame($expected_cache, $build['#cache']); + self::assertCache($expected_cache, $build['#cache']); self::assertStringContainsString('
renderPlain($build)); // -- Private node with access check. @@ -100,7 +99,7 @@ final class EntityFormViewBuilderTest extends KernelTestBase { ], 'max-age' => 50, ]; - self::assertSame($expected_cache, $build['#cache']); + self::assertCache($expected_cache, $build['#cache']); self::assertSame('', $this->renderPlain($build)); // -- Private node without access check. @@ -117,7 +116,7 @@ final class EntityFormViewBuilderTest extends KernelTestBase { ], 'max-age' => Cache::PERMANENT, ]; - self::assertSame($expected_cache, $build['#cache']); + self::assertCache($expected_cache, $build['#cache']); self::assertStringContainsString('renderPlain($build)); } diff --git a/tests/src/Kernel/EntityViewBuilderTest.php b/tests/src/Kernel/EntityViewBuilderTest.php index e294408..088fc03 100644 --- a/tests/src/Kernel/EntityViewBuilderTest.php +++ b/tests/src/Kernel/EntityViewBuilderTest.php @@ -3,7 +3,6 @@ namespace Drupal\Tests\twig_tweak\Kernel; use Drupal\Core\Cache\Cache; -use Drupal\KernelTests\KernelTestBase; use Drupal\node\Entity\Node; use Drupal\node\Entity\NodeType; use Drupal\Tests\user\Traits\UserCreationTrait; @@ -13,7 +12,7 @@ use Drupal\Tests\user\Traits\UserCreationTrait; * * @group twig_tweak */ -final class EntityViewBuilderTest extends KernelTestBase { +final class EntityViewBuilderTest extends AbstractTestCase { use UserCreationTrait; @@ -84,7 +83,7 @@ final class EntityViewBuilderTest extends KernelTestBase { ], 'bin' => 'render', ]; - self::assertSame($expected_cache, $build['#cache']); + self::assertCache($expected_cache, $build['#cache']); $expected_html = <<< 'HTML'
@@ -117,7 +116,7 @@ final class EntityViewBuilderTest extends KernelTestBase { ], 'bin' => 'render', ]; - self::assertSame($expected_cache, $build['#cache']); + self::assertCache($expected_cache, $build['#cache']); $expected_html = <<< 'HTML'
@@ -150,7 +149,7 @@ final class EntityViewBuilderTest extends KernelTestBase { ], 'max-age' => 50, ]; - self::assertSame($expected_cache, $build['#cache']); + self::assertCache($expected_cache, $build['#cache']); self::assertSame('', $this->renderPlain($build)); @@ -172,7 +171,7 @@ final class EntityViewBuilderTest extends KernelTestBase { ], 'bin' => 'render', ]; - self::assertSame($expected_cache, $build['#cache']); + self::assertCache($expected_cache, $build['#cache']); $expected_html = <<< 'HTML'
diff --git a/tests/src/Kernel/FieldViewBuilderTest.php b/tests/src/Kernel/FieldViewBuilderTest.php index fc8aea6..e358b5e 100644 --- a/tests/src/Kernel/FieldViewBuilderTest.php +++ b/tests/src/Kernel/FieldViewBuilderTest.php @@ -3,7 +3,6 @@ namespace Drupal\Tests\twig_tweak\Kernel; use Drupal\Core\Cache\Cache; -use Drupal\KernelTests\KernelTestBase; use Drupal\Tests\user\Traits\UserCreationTrait; use Drupal\node\Entity\Node; use Drupal\node\Entity\NodeType; @@ -13,7 +12,7 @@ use Drupal\node\Entity\NodeType; * * @group twig_tweak */ -final class FieldViewBuilderTest extends KernelTestBase { +final class FieldViewBuilderTest extends AbstractTestCase { use UserCreationTrait; @@ -74,7 +73,7 @@ final class FieldViewBuilderTest extends KernelTestBase { ], 'max-age' => 50, ]; - self::assertSame($expected_cache, $build['#cache']); + self::assertCache($expected_cache, $build['#cache']); self::assertSame('Public node', $this->renderPlain($build)); @@ -93,7 +92,7 @@ final class FieldViewBuilderTest extends KernelTestBase { ], 'max-age' => 50, ]; - self::assertSame($expected_cache, $build['#cache']); + self::assertCache($expected_cache, $build['#cache']); $expected_html = 'Public node'; self::assertSame($expected_html, $this->renderPlain($build)); @@ -112,7 +111,7 @@ final class FieldViewBuilderTest extends KernelTestBase { ], 'max-age' => 50, ]; - self::assertSame($expected_cache, $build['#cache']); + self::assertCache($expected_cache, $build['#cache']); self::assertSame('', $this->renderPlain($build)); // -- Private node without access check. diff --git a/tests/src/Kernel/ImageViewBuilderTest.php b/tests/src/Kernel/ImageViewBuilderTest.php index 9c611e3..32c0877 100644 --- a/tests/src/Kernel/ImageViewBuilderTest.php +++ b/tests/src/Kernel/ImageViewBuilderTest.php @@ -6,7 +6,6 @@ use Drupal\Core\Cache\Cache; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\file\Entity\File; use Drupal\image\Entity\ImageStyle; -use Drupal\KernelTests\KernelTestBase; use Drupal\responsive_image\Entity\ResponsiveImageStyle; /** @@ -14,7 +13,7 @@ use Drupal\responsive_image\Entity\ResponsiveImageStyle; * * @group twig_tweak */ -final class ImageViewBuilderTest extends KernelTestBase { +final class ImageViewBuilderTest extends AbstractTestCase { /** * {@inheritdoc} @@ -83,7 +82,7 @@ final class ImageViewBuilderTest extends KernelTestBase { 'max-age' => 70, ], ]; - self::assertSame($expected_build, $build); + self::assertRenderArray($expected_build, $build); self::assertSame('', $this->renderPlain($build)); // -- With style. @@ -105,7 +104,7 @@ final class ImageViewBuilderTest extends KernelTestBase { 'max-age' => 70, ], ]; - self::assertSame($expected_build, $build); + self::assertRenderArray($expected_build, $build); self::assertSame('Ocean', $this->renderPlain($build)); // -- With responsive style. @@ -127,7 +126,7 @@ final class ImageViewBuilderTest extends KernelTestBase { 'max-age' => 70, ], ]; - self::assertSame($expected_build, $build); + self::assertRenderArray($expected_build, $build); self::assertSame('Ocean', $this->renderPlain($build)); // -- Private image with access check. @@ -142,7 +141,7 @@ final class ImageViewBuilderTest extends KernelTestBase { 'max-age' => 70, ], ]; - self::assertSame($expected_build, $build); + self::assertRenderArray($expected_build, $build); self::assertSame('', $this->renderPlain($build)); // -- Private image without access check. @@ -157,7 +156,7 @@ final class ImageViewBuilderTest extends KernelTestBase { 'max-age' => Cache::PERMANENT, ], ]; - self::assertSame($expected_build, $build); + self::assertRenderArray($expected_build, $build); self::assertSame('', $this->renderPlain($build)); } diff --git a/tests/src/Kernel/RegionViewBuilderTest.php b/tests/src/Kernel/RegionViewBuilderTest.php index edddbde..fef7e5c 100644 --- a/tests/src/Kernel/RegionViewBuilderTest.php +++ b/tests/src/Kernel/RegionViewBuilderTest.php @@ -5,7 +5,6 @@ namespace Drupal\Tests\twig_tweak\Kernel; use Drupal\block\Entity\Block; use Drupal\Component\Utility\Html; use Drupal\Core\Cache\Cache; -use Drupal\KernelTests\KernelTestBase; use Drupal\Tests\user\Traits\UserCreationTrait; /** @@ -13,7 +12,7 @@ use Drupal\Tests\user\Traits\UserCreationTrait; * * @group twig_tweak */ -final class RegionViewBuilderTest extends KernelTestBase { +final class RegionViewBuilderTest extends AbstractTestCase { use UserCreationTrait; @@ -117,7 +116,8 @@ final class RegionViewBuilderTest extends KernelTestBase { 'max-age' => 123, ], ]; - self::assertSame($expected_build, $build); + + self::assertRenderArray($expected_build, $build); $expected_html = <<< 'HTML'
@@ -137,7 +137,8 @@ final class RegionViewBuilderTest extends KernelTestBase { ->save(); $build = $view_builder->build('sidebar_first'); - self::assertSame($expected_build, $build); + self::assertRenderArray($expected_build, $build); + Html::resetSeenIds(); $actual_html = $renderer->renderPlain($expected_build); self::assertSame(self::normalizeHtml($expected_html), self::normalizeHtml($actual_html));