.../EntityTestTextItemNormalizerTest.php | 63 +++++++++++++++++++--- .../EntityResource/Term/TermResourceTestBase.php | 6 +-- 2 files changed, 60 insertions(+), 9 deletions(-) diff --git a/core/modules/rest/tests/src/Functional/EntityResource/EntityTest/EntityTestTextItemNormalizerTest.php b/core/modules/rest/tests/src/Functional/EntityResource/EntityTest/EntityTestTextItemNormalizerTest.php index 336bd58..b41ad7f 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/EntityTest/EntityTestTextItemNormalizerTest.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityTest/EntityTestTextItemNormalizerTest.php @@ -3,6 +3,7 @@ namespace Drupal\Tests\rest\Functional\EntityResource\EntityTest; use Drupal\Core\Cache\Cache; +use Drupal\Core\Language\LanguageInterface; use Drupal\filter\Entity\FilterFormat; use Drupal\Tests\rest\Functional\AnonResourceTestTrait; @@ -16,6 +17,11 @@ class EntityTestTextItemNormalizerTest extends EntityTestResourceTestBase { /** * {@inheritdoc} */ + public static $modules = ['filter_test']; + + /** + * {@inheritdoc} + */ protected static $format = 'json'; /** @@ -31,8 +37,8 @@ protected function getExpectedNormalizedEntity() { $expected['field_test_text'] = [ [ 'value' => 'Cádiz is the oldest continuously inhabited city in Spain and a nice place to spend a Sunday with friends.', - 'format' => 'plain_text', - 'processed' => '
Cádiz is the oldest continuously inhabited city in Spain and a nice place to spend a Sunday with friends.
' . "\n", + 'format' => 'my_text_format', + 'processed' => 'Cádiz is the oldest continuously inhabited city in Spain and a nice place to spend a Sunday with friends.
' . "\n" . 'This is a dynamic llama.
', ], ]; return $expected; @@ -43,9 +49,38 @@ protected function getExpectedNormalizedEntity() { */ protected function createEntity() { $entity = parent::createEntity(); + FilterFormat::create([ + 'format' => 'my_text_format', + 'name' => 'My Text Format', + 'filters' => [ + 'filter_test_assets' => [ + 'weight' => -1, + 'status' => TRUE, + ], + 'filter_test_cache_tags' => [ + 'weight' => 0, + 'status' => TRUE, + ], + 'filter_test_cache_contexts' => [ + 'weight' => 0, + 'status' => TRUE, + ], + 'filter_test_cache_merge' => [ + 'weight' => 0, + 'status' => TRUE, + ], + 'filter_test_placeholders' => [ + 'weight' => 1, + 'status' => TRUE, + ], + 'filter_autop' => [ + 'status' => TRUE, + ], + ], + ])->save(); $entity->field_test_text = [ 'value' => 'Cádiz is the oldest continuously inhabited city in Spain and a nice place to spend a Sunday with friends.', - 'format' => 'plain_text', + 'format' => 'my_text_format', ]; $entity->save(); return $entity; @@ -59,7 +94,7 @@ protected function getNormalizedPostEntity() { $post_entity['field_test_text'] = [ [ 'value' => 'Llamas are awesome.', - 'format' => 'plain_text', + 'format' => 'my_text_format', ], ]; return $post_entity; @@ -69,14 +104,30 @@ protected function getNormalizedPostEntity() { * {@inheritdoc} */ protected function getExpectedCacheTags() { - return Cache::mergeTags(['config:filter.format.plain_text'], parent::getExpectedCacheTags()); + return Cache::mergeTags([ + // The cache tag set by the processed_text element itself. + 'config:filter.format.my_text_format', + // The cache tags set by the filter_test_cache_tags filter. + 'foo:bar', + 'foo:baz', + // The cache tags set by the filter_test_cache_merge filter. + 'merge:tag' + ], parent::getExpectedCacheTags()); } /** * {@inheritdoc} */ protected function getExpectedCacheContexts() { - return Cache::mergeContexts(['languages:language_interface', 'theme'], parent::getExpectedCacheContexts()); + return Cache::mergeContexts([ + // The cache context set by the filter_test_cache_contexts filter. + 'languages:' . LanguageInterface::TYPE_CONTENT, + // The default cache contexts for Renderer. + 'languages:' . LanguageInterface::TYPE_INTERFACE, + 'theme', + // The cache tags set by the filter_test_cache_merge filter. + 'user.permissions', + ], parent::getExpectedCacheContexts()); } /** diff --git a/core/modules/rest/tests/src/Functional/EntityResource/Term/TermResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/Term/TermResourceTestBase.php index b34fb52..713c1e5 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/Term/TermResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/Term/TermResourceTestBase.php @@ -80,7 +80,7 @@ protected function createEntity() { // Create a "Llama" taxonomy term. $term = Term::create(['vid' => $vocabulary->id()]) ->setName('Llama') - ->setDescription("It is a little known fact that llamas cannot count higher the seven.") + ->setDescription("It is a little known fact that llamas cannot count higher than seven.") ->setChangedTime(123456789) ->set('path', '/llama'); $term->save(); @@ -111,9 +111,9 @@ protected function getExpectedNormalizedEntity() { ], 'description' => [ [ - 'value' => 'It is a little known fact that llamas cannot count higher the seven.', + 'value' => 'It is a little known fact that llamas cannot count higher than seven.', 'format' => NULL, - 'processed' => "It is a little known fact that llamas cannot count higher the seven.
\n", + 'processed' => "It is a little known fact that llamas cannot count higher than seven.
\n", ], ], 'parent' => [],