summaryrefslogtreecommitdiffstats
path: root/tests/src/FunctionalJavascript/LinkitDialogTest.php
diff options
context:
space:
mode:
authorEmil Stjerneman2017-01-21 04:16:47 +0100
committerEmil Stjerneman2017-01-21 04:16:47 +0100
commita59f1fbe664ed06bbdc71062d21826d90c6f4101 (patch)
tree58d1db4472da622fa3dc30f27dbe1e8bf6812f80 /tests/src/FunctionalJavascript/LinkitDialogTest.php
parentabd037276aff63b1dbfafaa8708d07b1792c5960 (diff)
Issue #2844688 by LeisureLarry, anon: Wrong language in Linkit dialog
Diffstat (limited to 'tests/src/FunctionalJavascript/LinkitDialogTest.php')
-rw-r--r--tests/src/FunctionalJavascript/LinkitDialogTest.php109
1 files changed, 106 insertions, 3 deletions
diff --git a/tests/src/FunctionalJavascript/LinkitDialogTest.php b/tests/src/FunctionalJavascript/LinkitDialogTest.php
index f6d201d..002000f 100644
--- a/tests/src/FunctionalJavascript/LinkitDialogTest.php
+++ b/tests/src/FunctionalJavascript/LinkitDialogTest.php
@@ -4,10 +4,12 @@ namespace Drupal\Tests\linkit\FunctionalJavascript;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\editor\Entity\Editor;
+use Drupal\entity_test\Entity\EntityTestMul;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\filter\Entity\FilterFormat;
use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
+use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\linkit\Tests\ProfileCreationTrait;
use Drupal\node\Entity\NodeType;
@@ -25,7 +27,7 @@ class LinkitDialogTest extends JavascriptTestBase {
*
* @var array
*/
- public static $modules = ['node', 'ckeditor', 'filter', 'linkit'];
+ public static $modules = ['node', 'ckeditor', 'filter', 'linkit', 'entity_test', 'language'];
/**
* An instance of the "CKEditor" text editor plugin.
@@ -56,8 +58,9 @@ class LinkitDialogTest extends JavascriptTestBase {
$matcherManager = $this->container->get('plugin.manager.linkit.matcher');
/** @var \Drupal\linkit\MatcherInterface $plugin */
- $plugin = $matcherManager->createInstance('entity:node', []);
+
$this->linkitProfile = $this->createProfile();
+ $plugin = $matcherManager->createInstance('entity:entity_test_mul');
$this->linkitProfile->addMatcher($plugin->getConfiguration());
$this->linkitProfile->save();
@@ -127,8 +130,18 @@ class LinkitDialogTest extends JavascriptTestBase {
$web_assert = $this->assertSession();
$page = $session->getPage();
+ // Adds additional languages.
+ $langcodes = ['sv', 'da', 'fi'];
+ foreach ($langcodes as $langcode) {
+ ConfigurableLanguage::createFromLangcode($langcode)->save();
+ }
+
+ // Create a test entity.
+ $entity = EntityTestMul::create(['name' => 'Foo']);
+ $entity->save();
+
// Create test nodes.
- $this->demoEntity = $this->createNode(['title' => 'Foo']);
+ $this->demoEntity = $entity;
// Go to node creation page.
$this->drupalGet('node/add/page');
@@ -221,6 +234,8 @@ class LinkitDialogTest extends JavascriptTestBase {
JS;
$session->executeScript($javascript);
+ // Test edit link in the editor.
+
// Click on the drupallink plugin.
$page->find('css', 'a.cke_button__drupallink')->click();
@@ -289,6 +304,94 @@ JS;
}
/**
+ * Test the link dialog with translated entities.
+ */
+ public function testLinkDialogTranslations() {
+ $session = $this->getSession();
+ $web_assert = $this->assertSession();
+ $page = $session->getPage();
+
+ // Adds additional languages.
+ $langcodes = ['sv', 'da', 'fi'];
+ foreach ($langcodes as $langcode) {
+ ConfigurableLanguage::createFromLangcode($langcode)->save();
+ }
+
+ // Create a test entity.
+ $entity = EntityTestMul::create(['name' => 'Foo']);
+
+ foreach ($langcodes as $langcode) {
+ $entity->addTranslation($langcode, ['name' => 'Foo ' . $langcode]);
+ }
+
+ $entity->save();
+
+ // Create test nodes.
+ $this->demoEntity = $entity;
+
+ $this->config('system.site')->set('default_langcode', 'sv')->save();
+
+ // Go to node creation page.
+ $this->drupalGet('node/add/page');
+
+ // Wait until the editor has been loaded.
+ $ckeditor_loaded = $this->getSession()->wait(5000, "jQuery('.cke_contents').length > 0");
+ $this->assertTrue($ckeditor_loaded, 'The editor has been loaded.');
+
+ // Click on the drupallink plugin.
+ $page->find('css', 'a.cke_button__drupallink')->click();
+
+ // Wait for the form to load.
+ $web_assert->assertWaitOnAjaxRequest();
+
+ // Find the linkit field.
+ $linkit_field = $page->findField('linkit');
+
+ // Trigger a keydown event to active a autocomplete search.
+ $linkit_field->keyDown('f');
+
+ // Wait for the results to load.
+ $this->getSession()->wait(5000, "jQuery('.linkit-result.ui-menu-item').length > 0");
+
+ // Find all the autocomplete results.
+ $results = $page->findAll('css', '.linkit-result.ui-menu-item');
+ $this->assertEquals(1, count($results), 'Found autocomplete result');
+
+ // Find the first result and click it.
+ $page->find('xpath', '(//li[contains(@class, "linkit-result") and contains(@class, "ui-menu-item")])[1]')->click();
+
+ // Save the dialog input.
+ $page->find('css', '.editor-link-dialog')->find('css', '.button.form-submit span')->click();
+
+ // Wait for the dialog to close.
+ $web_assert->assertWaitOnAjaxRequest();
+
+ // Select the link in the editor.
+ $javascript = <<<JS
+ (function(){
+ var editor = window.CKEDITOR.instances['edit-body-0-value'];
+ console.log(editor);
+ var element = editor.document.findOne( 'a' );
+ editor.getSelection().selectElement( element );
+ })()
+JS;
+ $session->executeScript($javascript);
+
+ // Click on the drupallink plugin.
+ $page->find('css', 'a.cke_button__drupallink')->click();
+
+ // Wait for the form to load.
+ $web_assert->assertWaitOnAjaxRequest();
+
+ // Find the linkit field.
+ $linkit_field = $page->findField('linkit');
+ $this->assertEquals($this->demoEntity->getTranslation('sv')->label(), $linkit_field->getValue(), 'Linkit field has the correct value.');
+
+ // Make sure the link information is populated with the old label.
+ $this->assertEquals($this->demoEntity->getTranslation('sv')->label(), $this->getLinkInfoText(), 'Link information is populated');
+ }
+
+ /**
* Asserts that a variable is empty.
*
* @param string $field_name