annotate core/modules/node/tests/src/Functional/NodeTranslationUITest.php @ 6:875880e46745

Styling
author Chris Cannam
date Fri, 08 Dec 2017 13:21:27 +0000
parents 4c8ae668cc8c
children 1fec387a4317
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\Tests\node\Functional;
Chris@0 4
Chris@0 5 use Drupal\Core\Entity\EntityInterface;
Chris@0 6 use Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase;
Chris@0 7 use Drupal\Core\Language\LanguageInterface;
Chris@0 8 use Drupal\Core\Url;
Chris@0 9 use Drupal\node\Entity\Node;
Chris@0 10 use Drupal\language\Entity\ConfigurableLanguage;
Chris@0 11
Chris@0 12 /**
Chris@0 13 * Tests the Node Translation UI.
Chris@0 14 *
Chris@0 15 * @group node
Chris@0 16 */
Chris@0 17 class NodeTranslationUITest extends ContentTranslationUITestBase {
Chris@0 18
Chris@0 19 /**
Chris@0 20 * {inheritdoc}
Chris@0 21 */
Chris@0 22 protected $defaultCacheContexts = [
Chris@0 23 'languages:language_interface',
Chris@0 24 'session',
Chris@0 25 'theme',
Chris@0 26 'route',
Chris@0 27 'timezone',
Chris@0 28 'url.path.parent',
Chris@0 29 'url.query_args:_wrapper_format',
Chris@0 30 'user'
Chris@0 31 ];
Chris@0 32
Chris@0 33 /**
Chris@0 34 * Modules to enable.
Chris@0 35 *
Chris@0 36 * @var array
Chris@0 37 */
Chris@0 38 public static $modules = ['block', 'language', 'content_translation', 'node', 'datetime', 'field_ui', 'help'];
Chris@0 39
Chris@0 40 /**
Chris@0 41 * The profile to install as a basis for testing.
Chris@0 42 *
Chris@0 43 * @var string
Chris@0 44 */
Chris@0 45 protected $profile = 'standard';
Chris@0 46
Chris@0 47 protected function setUp() {
Chris@0 48 $this->entityTypeId = 'node';
Chris@0 49 $this->bundle = 'article';
Chris@0 50 parent::setUp();
Chris@0 51
Chris@0 52 // Ensure the help message is shown even with prefixed paths.
Chris@0 53 $this->drupalPlaceBlock('help_block', ['region' => 'content']);
Chris@0 54
Chris@0 55 // Display the language selector.
Chris@0 56 $this->drupalLogin($this->administrator);
Chris@0 57 $edit = ['language_configuration[language_alterable]' => TRUE];
Chris@0 58 $this->drupalPostForm('admin/structure/types/manage/article', $edit, t('Save content type'));
Chris@0 59 $this->drupalLogin($this->translator);
Chris@0 60 }
Chris@0 61
Chris@0 62 /**
Chris@0 63 * Tests the basic translation UI.
Chris@0 64 */
Chris@0 65 public function testTranslationUI() {
Chris@0 66 parent::testTranslationUI();
Chris@0 67 $this->doUninstallTest();
Chris@0 68 }
Chris@0 69
Chris@0 70 /**
Chris@0 71 * Tests changing the published status on a node without fields.
Chris@0 72 */
Chris@0 73 public function testPublishedStatusNoFields() {
Chris@0 74 // Test changing the published status of an article without fields.
Chris@0 75 $this->drupalLogin($this->administrator);
Chris@0 76 // Delete all fields.
Chris@0 77 $this->drupalGet('admin/structure/types/manage/article/fields');
Chris@0 78 $this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.' . $this->fieldName . '/delete', [], t('Delete'));
Chris@0 79 $this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.field_tags/delete', [], t('Delete'));
Chris@0 80 $this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.field_image/delete', [], t('Delete'));
Chris@0 81
Chris@0 82 // Add a node.
Chris@0 83 $default_langcode = $this->langcodes[0];
Chris@0 84 $values[$default_langcode] = ['title' => [['value' => $this->randomMachineName()]]];
Chris@0 85 $this->entityId = $this->createEntity($values[$default_langcode], $default_langcode);
Chris@0 86 $storage = $this->container->get('entity_type.manager')
Chris@0 87 ->getStorage($this->entityTypeId);
Chris@0 88 $storage->resetCache([$this->entityId]);
Chris@0 89 $entity = $storage->load($this->entityId);
Chris@0 90
Chris@0 91 // Add a content translation.
Chris@0 92 $langcode = 'fr';
Chris@0 93 $language = ConfigurableLanguage::load($langcode);
Chris@0 94 $values[$langcode] = ['title' => [['value' => $this->randomMachineName()]]];
Chris@0 95
Chris@0 96 $entity_type_id = $entity->getEntityTypeId();
Chris@0 97 $add_url = Url::fromRoute("entity.$entity_type_id.content_translation_add", [
Chris@0 98 $entity->getEntityTypeId() => $entity->id(),
Chris@0 99 'source' => $default_langcode,
Chris@0 100 'target' => $langcode
Chris@0 101 ], ['language' => $language]);
Chris@0 102 $edit = $this->getEditValues($values, $langcode);
Chris@0 103 $edit['status[value]'] = FALSE;
Chris@0 104 $this->drupalPostForm($add_url, $edit, t('Save (this translation)'));
Chris@0 105
Chris@0 106 $storage->resetCache([$this->entityId]);
Chris@0 107 $entity = $storage->load($this->entityId);
Chris@0 108 $translation = $entity->getTranslation($langcode);
Chris@0 109 // Make sure we unpublished the node correctly.
Chris@0 110 $this->assertFalse($this->manager->getTranslationMetadata($translation)->isPublished(), 'The translation has been correctly unpublished.');
Chris@0 111 }
Chris@0 112
Chris@0 113 /**
Chris@0 114 * {@inheritdoc}
Chris@0 115 */
Chris@0 116 protected function getTranslatorPermissions() {
Chris@0 117 return array_merge(parent::getTranslatorPermissions(), ['administer nodes', "edit any $this->bundle content"]);
Chris@0 118 }
Chris@0 119
Chris@0 120 /**
Chris@0 121 * {@inheritdoc}
Chris@0 122 */
Chris@0 123 protected function getEditorPermissions() {
Chris@0 124 return ['administer nodes', 'create article content'];
Chris@0 125 }
Chris@0 126
Chris@0 127 /**
Chris@0 128 * {@inheritdoc}
Chris@0 129 */
Chris@0 130 protected function getAdministratorPermissions() {
Chris@0 131 return array_merge(parent::getAdministratorPermissions(), ['access administration pages', 'administer content types', 'administer node fields', 'access content overview', 'bypass node access', 'administer languages', 'administer themes', 'view the administration theme']);
Chris@0 132 }
Chris@0 133
Chris@0 134 /**
Chris@0 135 * {@inheritdoc}
Chris@0 136 */
Chris@0 137 protected function getNewEntityValues($langcode) {
Chris@0 138 return ['title' => [['value' => $this->randomMachineName()]]] + parent::getNewEntityValues($langcode);
Chris@0 139 }
Chris@0 140
Chris@0 141 /**
Chris@0 142 * {@inheritdoc}
Chris@0 143 */
Chris@0 144 protected function doTestPublishedStatus() {
Chris@0 145 $storage = $this->container->get('entity_type.manager')
Chris@0 146 ->getStorage($this->entityTypeId);
Chris@0 147 $storage->resetCache([$this->entityId]);
Chris@0 148 $entity = $storage->load($this->entityId);
Chris@0 149 $languages = $this->container->get('language_manager')->getLanguages();
Chris@0 150
Chris@0 151 $statuses = [
Chris@0 152 TRUE,
Chris@0 153 FALSE,
Chris@0 154 ];
Chris@0 155
Chris@0 156 foreach ($statuses as $index => $value) {
Chris@0 157 // (Un)publish the node translations and check that the translation
Chris@0 158 // statuses are (un)published accordingly.
Chris@0 159 foreach ($this->langcodes as $langcode) {
Chris@0 160 $options = ['language' => $languages[$langcode]];
Chris@0 161 $url = $entity->urlInfo('edit-form', $options);
Chris@0 162 $this->drupalPostForm($url, ['status[value]' => $value], t('Save') . $this->getFormSubmitSuffix($entity, $langcode), $options);
Chris@0 163 }
Chris@0 164 $storage->resetCache([$this->entityId]);
Chris@0 165 $entity = $storage->load($this->entityId);
Chris@0 166 foreach ($this->langcodes as $langcode) {
Chris@0 167 // The node is created as unpublished thus we switch to the published
Chris@0 168 // status first.
Chris@0 169 $status = !$index;
Chris@0 170 $translation = $entity->getTranslation($langcode);
Chris@0 171 $this->assertEqual($status, $this->manager->getTranslationMetadata($translation)->isPublished(), 'The translation has been correctly unpublished.');
Chris@0 172 }
Chris@0 173 }
Chris@0 174 }
Chris@0 175
Chris@0 176 /**
Chris@0 177 * {@inheritdoc}
Chris@0 178 */
Chris@0 179 protected function doTestAuthoringInfo() {
Chris@0 180 $storage = $this->container->get('entity_type.manager')
Chris@0 181 ->getStorage($this->entityTypeId);
Chris@0 182 $storage->resetCache([$this->entityId]);
Chris@0 183 $entity = $storage->load($this->entityId);
Chris@0 184 $languages = $this->container->get('language_manager')->getLanguages();
Chris@0 185 $values = [];
Chris@0 186
Chris@0 187 // Post different base field information for each translation.
Chris@0 188 foreach ($this->langcodes as $langcode) {
Chris@0 189 $user = $this->drupalCreateUser();
Chris@0 190 $values[$langcode] = [
Chris@0 191 'uid' => $user->id(),
Chris@0 192 'created' => REQUEST_TIME - mt_rand(0, 1000),
Chris@0 193 'sticky' => (bool) mt_rand(0, 1),
Chris@0 194 'promote' => (bool) mt_rand(0, 1),
Chris@0 195 ];
Chris@0 196 $edit = [
Chris@0 197 'uid[0][target_id]' => $user->getUsername(),
Chris@0 198 'created[0][value][date]' => format_date($values[$langcode]['created'], 'custom', 'Y-m-d'),
Chris@0 199 'created[0][value][time]' => format_date($values[$langcode]['created'], 'custom', 'H:i:s'),
Chris@0 200 'sticky[value]' => $values[$langcode]['sticky'],
Chris@0 201 'promote[value]' => $values[$langcode]['promote'],
Chris@0 202 ];
Chris@0 203 $options = ['language' => $languages[$langcode]];
Chris@0 204 $url = $entity->urlInfo('edit-form', $options);
Chris@0 205 $this->drupalPostForm($url, $edit, $this->getFormSubmitAction($entity, $langcode), $options);
Chris@0 206 }
Chris@0 207
Chris@0 208 $storage->resetCache([$this->entityId]);
Chris@0 209 $entity = $storage->load($this->entityId);
Chris@0 210 foreach ($this->langcodes as $langcode) {
Chris@0 211 $translation = $entity->getTranslation($langcode);
Chris@0 212 $metadata = $this->manager->getTranslationMetadata($translation);
Chris@0 213 $this->assertEqual($metadata->getAuthor()->id(), $values[$langcode]['uid'], 'Translation author correctly stored.');
Chris@0 214 $this->assertEqual($metadata->getCreatedTime(), $values[$langcode]['created'], 'Translation date correctly stored.');
Chris@0 215 $this->assertEqual($translation->isSticky(), $values[$langcode]['sticky'], 'Sticky of Translation correctly stored.');
Chris@0 216 $this->assertEqual($translation->isPromoted(), $values[$langcode]['promote'], 'Promoted of Translation correctly stored.');
Chris@0 217 }
Chris@0 218 }
Chris@0 219
Chris@0 220 /**
Chris@0 221 * Tests that translation page inherits admin status of edit page.
Chris@0 222 */
Chris@0 223 public function testTranslationLinkTheme() {
Chris@0 224 $this->drupalLogin($this->administrator);
Chris@0 225 $article = $this->drupalCreateNode(['type' => 'article', 'langcode' => $this->langcodes[0]]);
Chris@0 226
Chris@0 227 // Set up Seven as the admin theme and use it for node editing.
Chris@0 228 $this->container->get('theme_handler')->install(['seven']);
Chris@0 229 $edit = [];
Chris@0 230 $edit['admin_theme'] = 'seven';
Chris@0 231 $edit['use_admin_theme'] = TRUE;
Chris@0 232 $this->drupalPostForm('admin/appearance', $edit, t('Save configuration'));
Chris@0 233 $this->drupalGet('node/' . $article->id() . '/translations');
Chris@0 234 $this->assertRaw('core/themes/seven/css/base/elements.css', 'Translation uses admin theme if edit is admin.');
Chris@0 235
Chris@0 236 // Turn off admin theme for editing, assert inheritance to translations.
Chris@0 237 $edit['use_admin_theme'] = FALSE;
Chris@0 238 $this->drupalPostForm('admin/appearance', $edit, t('Save configuration'));
Chris@0 239 $this->drupalGet('node/' . $article->id() . '/translations');
Chris@0 240 $this->assertNoRaw('core/themes/seven/css/base/elements.css', 'Translation uses frontend theme if edit is frontend.');
Chris@0 241
Chris@0 242 // Assert presence of translation page itself (vs. DisabledBundle below).
Chris@0 243 $this->assertResponse(200);
Chris@0 244 }
Chris@0 245
Chris@0 246 /**
Chris@0 247 * Tests that no metadata is stored for a disabled bundle.
Chris@0 248 */
Chris@0 249 public function testDisabledBundle() {
Chris@0 250 // Create a bundle that does not have translation enabled.
Chris@0 251 $disabledBundle = $this->randomMachineName();
Chris@0 252 $this->drupalCreateContentType(['type' => $disabledBundle, 'name' => $disabledBundle]);
Chris@0 253
Chris@0 254 // Create a node for each bundle.
Chris@0 255 $node = $this->drupalCreateNode([
Chris@0 256 'type' => $this->bundle,
Chris@0 257 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
Chris@0 258 ]);
Chris@0 259
Chris@0 260 // Make sure that nothing was inserted into the {content_translation} table.
Chris@0 261 $rows = db_query('SELECT nid, count(nid) AS count FROM {node_field_data} WHERE type <> :type GROUP BY nid HAVING count(nid) >= 2', [':type' => $this->bundle])->fetchAll();
Chris@0 262 $this->assertEqual(0, count($rows));
Chris@0 263
Chris@0 264 // Ensure the translation tab is not accessible.
Chris@0 265 $this->drupalGet('node/' . $node->id() . '/translations');
Chris@0 266 $this->assertResponse(403);
Chris@0 267 }
Chris@0 268
Chris@0 269 /**
Chris@0 270 * Tests that translations are rendered properly.
Chris@0 271 */
Chris@0 272 public function testTranslationRendering() {
Chris@0 273 $default_langcode = $this->langcodes[0];
Chris@0 274 $values[$default_langcode] = $this->getNewEntityValues($default_langcode);
Chris@0 275 $this->entityId = $this->createEntity($values[$default_langcode], $default_langcode);
Chris@0 276 $node = \Drupal::entityManager()->getStorage($this->entityTypeId)->load($this->entityId);
Chris@0 277 $node->setPromoted(TRUE);
Chris@0 278
Chris@0 279 // Create translations.
Chris@0 280 foreach (array_diff($this->langcodes, [$default_langcode]) as $langcode) {
Chris@0 281 $values[$langcode] = $this->getNewEntityValues($langcode);
Chris@0 282 $translation = $node->addTranslation($langcode, $values[$langcode]);
Chris@0 283 // Publish and promote the translation to frontpage.
Chris@0 284 $translation->setPromoted(TRUE);
Chris@0 285 $translation->setPublished(TRUE);
Chris@0 286 }
Chris@0 287 $node->save();
Chris@0 288
Chris@0 289 // Test that the frontpage view displays the correct translations.
Chris@0 290 \Drupal::service('module_installer')->install(['views'], TRUE);
Chris@0 291 $this->rebuildContainer();
Chris@0 292 $this->doTestTranslations('node', $values);
Chris@0 293
Chris@0 294 // Enable the translation language renderer.
Chris@0 295 $view = \Drupal::entityManager()->getStorage('view')->load('frontpage');
Chris@0 296 $display = &$view->getDisplay('default');
Chris@0 297 $display['display_options']['rendering_language'] = '***LANGUAGE_entity_translation***';
Chris@0 298 $view->save();
Chris@0 299
Chris@0 300 // Need to check from the beginning, including the base_path, in the url
Chris@0 301 // since the pattern for the default language might be a substring of
Chris@0 302 // the strings for other languages.
Chris@0 303 $base_path = base_path();
Chris@0 304
Chris@0 305 // Check the frontpage for 'Read more' links to each translation.
Chris@0 306 // See also assertTaxonomyPage() in NodeAccessBaseTableTest.
Chris@0 307 $node_href = 'node/' . $node->id();
Chris@0 308 foreach ($this->langcodes as $langcode) {
Chris@0 309 $this->drupalGet('node', ['language' => \Drupal::languageManager()->getLanguage($langcode)]);
Chris@0 310 $num_match_found = 0;
Chris@0 311 if ($langcode == 'en') {
Chris@0 312 // Site default language does not have langcode prefix in the URL.
Chris@0 313 $expected_href = $base_path . $node_href;
Chris@0 314 }
Chris@0 315 else {
Chris@0 316 $expected_href = $base_path . $langcode . '/' . $node_href;
Chris@0 317 }
Chris@0 318 $pattern = '|^' . $expected_href . '$|';
Chris@0 319 foreach ($this->xpath("//a[text()='Read more']") as $link) {
Chris@0 320 if (preg_match($pattern, $link->getAttribute('href'), $matches) == TRUE) {
Chris@0 321 $num_match_found++;
Chris@0 322 }
Chris@0 323 }
Chris@0 324 $this->assertTrue($num_match_found == 1, 'There is 1 Read more link, ' . $expected_href . ', for the ' . $langcode . ' translation of a node on the frontpage. (Found ' . $num_match_found . '.)');
Chris@0 325 }
Chris@0 326
Chris@0 327 // Check the frontpage for 'Add new comment' links that include the
Chris@0 328 // language.
Chris@0 329 $comment_form_href = 'node/' . $node->id() . '#comment-form';
Chris@0 330 foreach ($this->langcodes as $langcode) {
Chris@0 331 $this->drupalGet('node', ['language' => \Drupal::languageManager()->getLanguage($langcode)]);
Chris@0 332 $num_match_found = 0;
Chris@0 333 if ($langcode == 'en') {
Chris@0 334 // Site default language does not have langcode prefix in the URL.
Chris@0 335 $expected_href = $base_path . $comment_form_href;
Chris@0 336 }
Chris@0 337 else {
Chris@0 338 $expected_href = $base_path . $langcode . '/' . $comment_form_href;
Chris@0 339 }
Chris@0 340 $pattern = '|^' . $expected_href . '$|';
Chris@0 341 foreach ($this->xpath("//a[text()='Add new comment']") as $link) {
Chris@0 342 if (preg_match($pattern, $link->getAttribute('href'), $matches) == TRUE) {
Chris@0 343 $num_match_found++;
Chris@0 344 }
Chris@0 345 }
Chris@0 346 $this->assertTrue($num_match_found == 1, 'There is 1 Add new comment link, ' . $expected_href . ', for the ' . $langcode . ' translation of a node on the frontpage. (Found ' . $num_match_found . '.)');
Chris@0 347 }
Chris@0 348
Chris@0 349 // Test that the node page displays the correct translations.
Chris@0 350 $this->doTestTranslations('node/' . $node->id(), $values);
Chris@0 351
Chris@0 352 // Test that the node page has the correct alternate hreflang links.
Chris@0 353 $this->doTestAlternateHreflangLinks($node->urlInfo());
Chris@0 354 }
Chris@0 355
Chris@0 356 /**
Chris@0 357 * Tests that the given path displays the correct translation values.
Chris@0 358 *
Chris@0 359 * @param string $path
Chris@0 360 * The path to be tested.
Chris@0 361 * @param array $values
Chris@0 362 * The translation values to be found.
Chris@0 363 */
Chris@0 364 protected function doTestTranslations($path, array $values) {
Chris@0 365 $languages = $this->container->get('language_manager')->getLanguages();
Chris@0 366 foreach ($this->langcodes as $langcode) {
Chris@0 367 $this->drupalGet($path, ['language' => $languages[$langcode]]);
Chris@0 368 $this->assertText($values[$langcode]['title'][0]['value'], format_string('The %langcode node translation is correctly displayed.', ['%langcode' => $langcode]));
Chris@0 369 }
Chris@0 370 }
Chris@0 371
Chris@0 372 /**
Chris@0 373 * Tests that the given path provides the correct alternate hreflang links.
Chris@0 374 *
Chris@0 375 * @param \Drupal\Core\Url $url
Chris@0 376 * The path to be tested.
Chris@0 377 */
Chris@0 378 protected function doTestAlternateHreflangLinks(Url $url) {
Chris@0 379 $languages = $this->container->get('language_manager')->getLanguages();
Chris@0 380 $url->setAbsolute();
Chris@0 381 $urls = [];
Chris@0 382 foreach ($this->langcodes as $langcode) {
Chris@0 383 $language_url = clone $url;
Chris@0 384 $urls[$langcode] = $language_url->setOption('language', $languages[$langcode]);
Chris@0 385 }
Chris@0 386 foreach ($this->langcodes as $langcode) {
Chris@0 387 $this->drupalGet($urls[$langcode]);
Chris@0 388 foreach ($urls as $alternate_langcode => $language_url) {
Chris@0 389 // Retrieve desired link elements from the HTML head.
Chris@0 390 $links = $this->xpath('head/link[@rel = "alternate" and @href = :href and @hreflang = :hreflang]',
Chris@0 391 [':href' => $language_url->toString(), ':hreflang' => $alternate_langcode]);
Chris@0 392 $this->assert(isset($links[0]), format_string('The %langcode node translation has the correct alternate hreflang link for %alternate_langcode: %link.', ['%langcode' => $langcode, '%alternate_langcode' => $alternate_langcode, '%link' => $url->toString()]));
Chris@0 393 }
Chris@0 394 }
Chris@0 395 }
Chris@0 396
Chris@0 397 /**
Chris@0 398 * {@inheritdoc}
Chris@0 399 */
Chris@0 400 protected function getFormSubmitSuffix(EntityInterface $entity, $langcode) {
Chris@0 401 if (!$entity->isNew() && $entity->isTranslatable()) {
Chris@0 402 $translations = $entity->getTranslationLanguages();
Chris@0 403 if ((count($translations) > 1 || !isset($translations[$langcode])) && ($field = $entity->getFieldDefinition('status'))) {
Chris@0 404 return ' ' . ($field->isTranslatable() ? t('(this translation)') : t('(all translations)'));
Chris@0 405 }
Chris@0 406 }
Chris@0 407 return '';
Chris@0 408 }
Chris@0 409
Chris@0 410 /**
Chris@0 411 * Tests uninstalling content_translation.
Chris@0 412 */
Chris@0 413 protected function doUninstallTest() {
Chris@0 414 // Delete all the nodes so there is no data.
Chris@0 415 $nodes = Node::loadMultiple();
Chris@0 416 foreach ($nodes as $node) {
Chris@0 417 $node->delete();
Chris@0 418 }
Chris@0 419 $language_count = count(\Drupal::configFactory()->listAll('language.content_settings.'));
Chris@0 420 \Drupal::service('module_installer')->uninstall(['content_translation']);
Chris@0 421 $this->rebuildContainer();
Chris@0 422 $this->assertEqual($language_count, count(\Drupal::configFactory()->listAll('language.content_settings.')), 'Languages have been fixed rather than deleted during content_translation uninstall.');
Chris@0 423 }
Chris@0 424
Chris@0 425 /**
Chris@0 426 * {@inheritdoc}
Chris@0 427 */
Chris@0 428 protected function doTestTranslationEdit() {
Chris@0 429 $storage = $this->container->get('entity_type.manager')
Chris@0 430 ->getStorage($this->entityTypeId);
Chris@0 431 $storage->resetCache([$this->entityId]);
Chris@0 432 $entity = $storage->load($this->entityId);
Chris@0 433 $languages = $this->container->get('language_manager')->getLanguages();
Chris@0 434 $type_name = node_get_type_label($entity);
Chris@0 435
Chris@0 436 foreach ($this->langcodes as $langcode) {
Chris@0 437 // We only want to test the title for non-english translations.
Chris@0 438 if ($langcode != 'en') {
Chris@0 439 $options = ['language' => $languages[$langcode]];
Chris@0 440 $url = $entity->urlInfo('edit-form', $options);
Chris@0 441 $this->drupalGet($url);
Chris@0 442
Chris@0 443 $title = t('<em>Edit @type</em> @title [%language translation]', [
Chris@0 444 '@type' => $type_name,
Chris@0 445 '@title' => $entity->getTranslation($langcode)->label(),
Chris@0 446 '%language' => $languages[$langcode]->getName(),
Chris@0 447 ]);
Chris@0 448 $this->assertRaw($title);
Chris@0 449 }
Chris@0 450 }
Chris@0 451 }
Chris@0 452
Chris@0 453 /**
Chris@0 454 * Tests that revision translations are rendered properly.
Chris@0 455 */
Chris@0 456 public function testRevisionTranslationRendering() {
Chris@0 457 $storage = \Drupal::entityTypeManager()->getStorage('node');
Chris@0 458
Chris@0 459 // Create a node.
Chris@0 460 $nid = $this->createEntity(['title' => 'First rev en title'], 'en');
Chris@0 461 $node = $storage->load($nid);
Chris@0 462 $original_revision_id = $node->getRevisionId();
Chris@0 463
Chris@0 464 // Add a French translation.
Chris@0 465 $translation = $node->addTranslation('fr');
Chris@0 466 $translation->title = 'First rev fr title';
Chris@0 467 $translation->setNewRevision(FALSE);
Chris@0 468 $translation->save();
Chris@0 469
Chris@0 470 // Create a new revision.
Chris@0 471 $node->title = 'Second rev en title';
Chris@0 472 $node->setNewRevision(TRUE);
Chris@0 473 $node->save();
Chris@0 474
Chris@0 475 // Get an English view of this revision.
Chris@0 476 $original_revision = $storage->loadRevision($original_revision_id);
Chris@0 477 $original_revision_url = $original_revision->toUrl('revision')->toString();
Chris@0 478
Chris@0 479 // Should be different from regular node URL.
Chris@0 480 $this->assertNotIdentical($original_revision_url, $original_revision->toUrl()->toString());
Chris@0 481 $this->drupalGet($original_revision_url);
Chris@0 482 $this->assertResponse(200);
Chris@0 483
Chris@0 484 // Contents should be in English, of correct revision.
Chris@0 485 $this->assertText('First rev en title');
Chris@0 486 $this->assertNoText('First rev fr title');
Chris@0 487
Chris@0 488 // Get a French view.
Chris@0 489 $url_fr = $original_revision->getTranslation('fr')->toUrl('revision')->toString();
Chris@0 490
Chris@0 491 // Should have different URL from English.
Chris@0 492 $this->assertNotIdentical($url_fr, $original_revision->toUrl()->toString());
Chris@0 493 $this->assertNotIdentical($url_fr, $original_revision_url);
Chris@0 494 $this->drupalGet($url_fr);
Chris@0 495 $this->assertResponse(200);
Chris@0 496
Chris@0 497 // Contents should be in French, of correct revision.
Chris@0 498 $this->assertText('First rev fr title');
Chris@0 499 $this->assertNoText('First rev en title');
Chris@0 500 }
Chris@0 501
Chris@0 502 }