summaryrefslogtreecommitdiffstats
path: root/tests/src/FunctionalJavascript/LinkitFormatAdminTest.php
blob: 7d2d79c64c6904210b352eecea61f47e5a73b3cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php

namespace Drupal\Tests\linkit\FunctionalJavascript;

use Drupal\FunctionalJavascriptTests\JavascriptTestBase;

/**
 * Tests the linkit alterations on the text format forms.
 *
 * @group linkit
 */
class LinkitFormatAdminTest extends JavascriptTestBase {

  /**
   * Modules to enable.
   *
   * @var array
   */
  public static $modules = ['editor', 'filter', 'linkit'];

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();

    $account = $this->drupalCreateUser([
      'administer filters',
    ]);
    $this->drupalLogin($account);
  }

  /**
   * Tests that linkit filter is toggling the filter_html allowed tags.
   */
  public function testToggleLinkitFilter() {
    $session = $this->getSession();
    $page = $session->getPage();

    // Go to add filter page.
    $this->drupalGet('admin/config/content/formats/add');
    $this->assertSession()->statusCodeEquals(200);

    // Enable the 'Limit allowed HTML tags and correct faulty HTML' filter.
    $page->findField('filters[filter_html][status]')->check();

    $javascript = "(function (){ return jQuery('p.editor-update-message > strong').text(); })()";
    $this->assertNotContains('<a href hreflang data-entity-substitution data-entity-type data-entity-uuid title>', $session->evaluateScript($javascript));

    // Enable the 'Linkit filter' filter.
    $page->findField('filters[linkit][status]')->check();
    $this->assertContains('<a href hreflang data-entity-substitution data-entity-type data-entity-uuid title>', $session->evaluateScript($javascript));

    // Disable the 'Linkit filter' filter.
    $page->findField('filters[linkit][status]')->uncheck();
    $this->assertNotContains('<a href hreflang data-entity-substitution data-entity-type data-entity-uuid title>', $session->evaluateScript($javascript));
  }

}