diff --cc core/modules/rest/tests/src/Functional/EntityResource/Term/TermResourceTestBase.php index 713c1e5c1b,8a0cffb578..0000000000 --- a/core/modules/rest/tests/src/Functional/EntityResource/Term/TermResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/Term/TermResourceTestBase.php @@@ -2,9 -2,9 +2,10 @@@ namespace Drupal\Tests\rest\Functional\EntityResource\Term; +use Drupal\Core\Cache\Cache; use Drupal\taxonomy\Entity\Term; use Drupal\taxonomy\Entity\Vocabulary; + use Drupal\taxonomy\TermInterface; use Drupal\Tests\rest\Functional\BcTimestampNormalizerUnixTestTrait; use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase; use GuzzleHttp\RequestOptions; @@@ -111,12 -170,11 +172,12 @@@ abstract class TermResourceTestBase ext ], 'description' => [ [ - 'value' => NULL, + '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 than seven.

\n", ], ], - 'parent' => [], + 'parent' => $expected_parent_normalization, 'weight' => [ ['value' => 0], ], @@@ -233,18 -291,54 +294,68 @@@ $this->assertSame($normalization['path'], $updated_normalization['path']); } + /** + * {@inheritdoc} + */ + protected function getExpectedCacheTags() { + return Cache::mergeTags(parent::getExpectedCacheTags(), ['config:filter.format.plain_text', 'config:filter.settings']); + } + + /** + * {@inheritdoc} + */ + protected function getExpectedCacheContexts() { + return Cache::mergeContexts(['url.site'], $this->container->getParameter('renderer.config')['required_cache_contexts']); + } + + /** + * Tests GETting a term with a parent term other than the default (0). + * + * @see ::getExpectedNormalizedEntity() + * + * @dataProvider providerTestGetTermWithParent + */ + public function testGetTermWithParent(array $parent_term_ids) { + // Create all possible parent terms. + Term::create(['vid' => Vocabulary::load('camelids')->id()]) + ->setName('Lamoids') + ->save(); + Term::create(['vid' => Vocabulary::load('camelids')->id()]) + ->setName('Wimoids') + ->save(); + + // Modify the entity under test to use the provided parent terms. + $this->entity->set('parent', $parent_term_ids)->save(); + + $this->initAuthentication(); + $url = $this->getEntityResourceUrl(); + $url->setOption('query', ['_format' => static::$format]); + $request_options = $this->getAuthenticationRequestOptions('GET'); + $this->provisionEntityResource(); + $this->setUpAuthorization('GET'); + $response = $this->request('GET', $url, $request_options); + $expected = $this->getExpectedNormalizedEntity(); + static::recursiveKSort($expected); + $actual = $this->serializer->decode((string) $response->getBody(), static::$format); + static::recursiveKSort($actual); + $this->assertSame($expected, $actual); + } + + public function providerTestGetTermWithParent() { + return [ + 'root parent: [0] (= no parent)' => [ + [TermInterface::ROOT_ID] + ], + 'non-root parent: [2]' => [ + [2] + ], + 'multiple parents: [0,2] (root + non-root parent)' => [ + [TermInterface::ROOT_ID, 2] + ], + 'multiple parents: [3,2] (both non-root parents)' => [ + [3, 2] + ], + ]; + } + }