You are here

public function FreelinkingMultilingualTest::testFreelinking in Freelinking 8.3

Same name and namespace in other branches
  1. 4.0.x tests/src/Functional/FreelinkingMultilingualTest.php \Drupal\Tests\freelinking\Functional\FreelinkingMultilingualTest::testFreelinking()

Asserts that node title is translated into user's preferred language.

Throws

\Drupal\Core\Entity\EntityStorageException

\Behat\Mink\Exception\ExpectationException

File

tests/src/Functional/FreelinkingMultilingualTest.php, line 91

Class

FreelinkingMultilingualTest
Tests that multilingual capabilities of Freelinking.

Namespace

Drupal\Tests\freelinking\Functional

Code

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();

  // Create an user with preferred language of Spanish.
  $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.');
}