View source
<?php
namespace Drupal\Tests\diff\FunctionalJavascript;
use Drupal\Tests\diff\Functional\CoreVersionUiTestTrait;
class DiffLocaleTest extends DiffTestBase {
use CoreVersionUiTestTrait;
public static $modules = [
'locale',
'content_translation',
];
protected function setUp() {
parent::setUp();
$this
->drupalLogin($this->rootUser);
$edit = array(
'predefined_langcode' => 'fr',
);
$this
->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
$this
->drupalGet('admin/config/regional/content-language');
$edit = array(
'entity_types[node]' => TRUE,
'settings[node][article][translatable]' => TRUE,
'settings[node][article][settings][language][language_alterable]' => TRUE,
);
$this
->drupalPostForm(NULL, $edit, t('Save configuration'));
}
public function testAll() {
$this
->doTestTranslationRevisions();
$this
->doTestUndefinedTranslationFilter();
$this
->doTestTranslationFilter();
}
protected function doTestTranslationRevisions() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$edit = array(
'title[0][value]' => 'English node',
'langcode[0][value]' => 'en',
);
$this
->drupalPostNodeForm('node/add/article', $edit, t('Save and publish'));
$english_node = $this
->drupalGetNodeByTitle('English node');
$this
->drupalGet('node/' . $english_node
->id() . '/translations');
$this
->clickLink(t('Add'));
$assert_session
->elementExists('css', 'a[href="#edit-revision-information"]')
->click();
$page
->fillField('title[0][value]', 'French node');
$page
->uncheckField('revision');
$this
->drupalPostNodeForm(NULL, [], t('Save and keep published (this translation)'));
$this
->rebuildContainer();
$english_node = $this
->drupalGetNodeByTitle('English node');
$french_node = $english_node
->getTranslation('fr');
$edit = array(
'title[0][value]' => 'Updated title',
'revision' => TRUE,
);
$this
->drupalPostNodeForm('node/' . $english_node
->id() . '/edit', $edit, t('Save and keep published (this translation)'));
$edit = array(
'title[0][value]' => 'Le titre',
'revision' => TRUE,
);
$this
->drupalPostNodeForm('fr/node/' . $english_node
->id() . '/edit', $edit, t('Save and keep published (this translation)'));
$this
->drupalGet('node/' . $english_node
->id() . '/revisions');
$this
->drupalGet('node/' . $english_node
->id() . '/revisions/view/1/2/split_fields');
$assert_session
->pageTextContains('Title');
$assert_session
->pageTextContains('English node');
$assert_session
->pageTextContains('Updated title');
$this
->drupalGet('fr/node/' . $english_node
->id() . '/revisions');
$this
->drupalGet('fr/node/' . $english_node
->id() . '/revisions/view/1/3/split_fields');
$assert_session
->pageTextContains('Title');
$assert_session
->pageTextNotContains('English node');
$assert_session
->pageTextNotContains('Updated title');
$assert_session
->pageTextContains('French node');
$assert_session
->pageTextContains('Le titre');
}
protected function doTestTranslationFilter() {
$node = $this
->drupalCreateNode([
'type' => 'article',
'title' => 'english_revision_0',
]);
$revision1 = $node
->getRevisionId();
$node
->addTranslation('fr', [
'title' => 'french_revision_0',
]);
$node
->save();
$english_node = $node
->getTranslation('en');
$english_node
->setTitle('english_revision_1');
$english_node
->setNewRevision(TRUE);
$english_node
->save();
$revision2 = $node
->getRevisionId();
$french_node = $node
->getTranslation('fr');
$french_node
->setTitle('french_revision_1');
$french_node
->setNewRevision(TRUE);
$french_node
->save();
$english_node = $node
->getTranslation('en');
$english_node
->setTitle('english_revision_2');
$english_node
->setNewRevision(TRUE);
$english_node
->save();
$french_node = $node
->getTranslation('fr');
$french_node
->setTitle('french_revision_2');
$french_node
->setNewRevision(TRUE);
$french_node
->save();
$this
->drupalGet('node/' . $node
->id() . '/revisions/view/' . $revision1 . '/' . $revision2 . '/split_fields');
$diffs = $this
->getSession()
->getPage()
->findAll('xpath', '//span[@class="diffchange"]');
$this
->assertEqual($diffs[0]
->getText(), 'english_revision_0');
$this
->assertEqual($diffs[1]
->getText(), 'english_revision_1');
$this
->clickLink('Next change');
$diffs = $this
->getSession()
->getPage()
->findAll('xpath', '//span[@class="diffchange"]');
$this
->assertEqual($diffs[0]
->getText(), 'english_revision_1');
$this
->assertEqual($diffs[1]
->getText(), 'english_revision_2');
$this
->assertNoLink('Next change');
}
protected function doTestUndefinedTranslationFilter() {
$node = $this
->drupalCreateNode([
'type' => 'article',
'title' => 'undefined_language_revision_0',
'langcode' => 'und',
]);
$revision1 = $node
->getRevisionId();
$node
->setTitle('undefined_language_revision_1');
$node
->setNewRevision(TRUE);
$node
->save();
$revision2 = $node
->getRevisionId();
$node
->setTitle('undefined_language_revision_2');
$node
->setNewRevision(TRUE);
$node
->save();
$node
->setTitle('undefined_language_revision_3');
$node
->setNewRevision(TRUE);
$node
->save();
$this
->drupalGet('node/' . $node
->id() . '/revisions');
$element = $this
->getSession()
->getPage()
->findAll('xpath', '//*[@id="edit-node-revisions-table"]/tbody/tr');
$this
->assertEqual(count($element), 4);
$this
->drupalGet('node/' . $node
->id() . '/revisions/view/' . $revision1 . '/' . $revision2 . '/split_fields');
$diffs = $this
->getSession()
->getPage()
->findAll('xpath', '//span[@class="diffchange"]');
$this
->assertEqual($diffs[0]
->getText(), 'undefined_language_revision_0');
$this
->assertEqual($diffs[1]
->getText(), 'undefined_language_revision_1');
$this
->clickLink('Next change');
$diffs = $this
->getSession()
->getPage()
->findAll('xpath', '//span[@class="diffchange"]');
$this
->assertEqual($diffs[0]
->getText(), 'undefined_language_revision_1');
$this
->assertEqual($diffs[1]
->getText(), 'undefined_language_revision_2');
}
}