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() : void {
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
->drupalGet('admin/config/regional/language/detection');
$this
->submitForm($edit, 'Save settings');
$edit = [
'language_configuration[language_alterable]' => TRUE,
'language_configuration[content_translation]' => TRUE,
];
$this
->drupalGet('admin/structure/types/manage/page');
$this
->submitForm($edit, '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
->drupalGet('node/1/translations/add/en/es');
$this
->submitForm($edit, '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
->drupalGet('node/add/page');
$this
->submitForm($edit, '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.');
}
}