.../Normalizer/TextItemBaseNormalizerTest.php | 23 ++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/core/modules/text/tests/src/Kernel/Normalizer/TextItemBaseNormalizerTest.php b/core/modules/text/tests/src/Kernel/Normalizer/TextItemBaseNormalizerTest.php index 426f878..e577cb6 100644 --- a/core/modules/text/tests/src/Kernel/Normalizer/TextItemBaseNormalizerTest.php +++ b/core/modules/text/tests/src/Kernel/Normalizer/TextItemBaseNormalizerTest.php @@ -29,6 +29,16 @@ class TextItemBaseNormalizerTest extends KernelTestBase { protected $serializer; /** + * The text format ID of the fallback format. + * + * In a non-unit test, this would be read from the 'filter.settings' config, + * from the 'fallback_format' key. + * + * @var string + */ + static $fallbackFormatId = 'plain_text'; + + /** * {@inheritdoc} */ protected function setUp() { @@ -79,6 +89,8 @@ public function testNormalize($text_item, array $expected, $filter_config_update $original_entity = EntityTest::create(['field_text' => $text_item]); $original_entity->save(); + $filter_format = FilterFormat::load(empty($text_item['format']) ? static::$fallbackFormatId : $text_item['format']); + $entity = clone $original_entity; $context = new RenderContext(); $data = $this->container->get('renderer') @@ -86,15 +98,12 @@ public function testNormalize($text_item, array $expected, $filter_config_update return $this->serializer->normalize($entity); }); + $cacheability = new BubbleableMetadata(); + $cacheability->setCacheTags($filter_format->getCacheTags()); + $this->assertEquals($cacheability, $context->pop()); $this->assertEquals($expected, $data['field_text'][0]); if ($filter_config_update) { - if (empty($text_item['format'])) { - $filter_format = FilterFormat::load('plain_text'); - } - else { - $filter_format = FilterFormat::load($text_item['format']); - } // Update format to see if normalization changes. foreach ($filter_config_update as $instance_id => $update) { $filter_format->setFilterConfig($instance_id, $update); @@ -111,8 +120,6 @@ public function testNormalize($text_item, array $expected, $filter_config_update }); $this->assertFalse($context->isEmpty()); - $cacheability = new BubbleableMetadata(); - $cacheability->setCacheTags($tags); $this->assertEquals($cacheability, $context->pop()); $expected['processed'] = $updated_processed; $this->assertEquals($expected, $data['field_text'][0]);