View source
<?php
namespace Drupal\Tests\freelinking\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
class FreelinkingMultilingualTest extends FreelinkingBrowserTestBase {
public static $modules = [
'node',
'user',
'file',
'filter',
'search',
'language',
'content_translation',
'freelinking',
];
protected $adminUser;
protected function setUp() {
parent::setUp();
$this
->updateFilterSettings();
ConfigurableLanguage::createFromLangcode('es')
->save();
$this->adminUser = $this
->drupalCreateUser([
'access administration pages',
'access content',
'administer content types',
'administer filters',
'administer languages',
'administer content translation',
'access user profiles',
'create page content',
'create content translations',
'edit own page content',
'update content translations',
'translate any entity',
]);
$this
->drupalLogin($this->adminUser);
$edit = [
'language_interface[enabled][language-url]' => '1',
'language_interface[enabled][language-user]' => '1',
];
$this
->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings'));
$edit = [
'language_configuration[language_alterable]' => TRUE,
];
$edit = [
'language_configuration[content_translation]' => TRUE,
];
$this
->drupalPostForm('admin/structure/types/manage/page', $edit, t('Save content type'));
$this
->assertSession()
->pageTextContains('The content type Basic page has been updated.');
$edit = [
'title[0][value]' => 'Primera página',
'body[0][value]' => 'Contenido traducido.',
];
$this
->drupalPostForm('node/1/translations/add/en/es', $edit, t('Save'));
}
public function testFreelinking() {
$edit = [];
$edit['title[0][value]'] = t('Testing all freelinking plugins');
$edit['body[0][value]'] = <<<EOF
<ul>
<li>Default plugin (nodetitle): [[First page]]</li>
<li>Nodetitle: [[nodetitle:First page]]</li>
<li>Nid: [[nid:1]]</li>
</ul>
EOF;
$this
->drupalPostForm('node/add/page', $edit, t('Save'));
$this
->assertSession()
->linkExists('First page', 0, 'Generate default plugin (nodetitle) freelink.');
$this
->assertSession()
->linkExists('First page', 0, 'Generate Nodetitle freelink.');
$this
->assertSession()
->linkExists('First page', 0, 'Generate Nid freelink.');
$this
->drupalLogout();
$esUser = $this
->createUser([
'access content',
]);
$esUser
->set('preferred_langcode', 'es');
$esUser
->save();
$this
->assertEquals('es', $esUser
->getPreferredLangcode());
$this
->drupalLogin($esUser);
$this
->drupalGet('/node/3');
$this
->assertSession()
->linkExists('Primera página', 0, 'Generate default plugin (nodetitle) freelink in Spanish.');
$this
->assertSession()
->linkExists('Primera página', 0, 'Generate Nodetitle freelink in Spanish.');
$this
->assertSession()
->linkExists('Primera página', 0, 'Generate Nid freelink in Spanish.');
}
}