function StyleSerializerTest::testMulEntityRows
Same name in other branches
- 9 core/modules/rest/tests/src/Functional/Views/StyleSerializerTest.php \Drupal\Tests\rest\Functional\Views\StyleSerializerTest::testMulEntityRows()
- 8.9.x core/modules/rest/tests/src/Functional/Views/StyleSerializerTest.php \Drupal\Tests\rest\Functional\Views\StyleSerializerTest::testMulEntityRows()
- 11.x core/modules/rest/tests/src/Functional/Views/StyleSerializerTest.php \Drupal\Tests\rest\Functional\Views\StyleSerializerTest::testMulEntityRows()
Tests multilingual entity rows.
File
-
core/
modules/ rest/ tests/ src/ Functional/ Views/ StyleSerializerTest.php, line 292
Class
- StyleSerializerTest
- Tests the serializer style plugin.
Namespace
Drupal\Tests\rest\Functional\ViewsCode
public function testMulEntityRows() : void {
// Create some languages.
ConfigurableLanguage::createFromLangcode('l1')->save();
ConfigurableLanguage::createFromLangcode('l2')->save();
// Create an entity with no translations.
$storage = \Drupal::entityTypeManager()->getStorage('entity_test_mul');
$storage->create([
'langcode' => 'l1',
'name' => 'mul-none',
])
->save();
// Create some entities with translations.
$entity = $storage->create([
'langcode' => 'l1',
'name' => 'mul-l1-orig',
]);
$entity->save();
$entity->addTranslation('l2', [
'name' => 'mul-l1-l2',
])
->save();
$entity = $storage->create([
'langcode' => 'l2',
'name' => 'mul-l2-orig',
]);
$entity->save();
$entity->addTranslation('l1', [
'name' => 'mul-l2-l1',
])
->save();
// Get the names of the output.
$json = $this->drupalGet('test/serialize/translated_entity', [
'query' => [
'_format' => 'json',
],
]);
$decoded = $this->container
->get('serializer')
->decode($json, 'json');
$names = [];
foreach ($decoded as $item) {
$names[] = $item['name'][0]['value'];
}
sort($names);
// Check that the names are correct.
$expected = [
'mul-l1-l2',
'mul-l1-orig',
'mul-l2-l1',
'mul-l2-orig',
'mul-none',
];
$this->assertSame($expected, $names, 'The translated content was found in the JSON.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.