You are here

public function FreelinkingFilterTest::testFreelinkingPlugins in Freelinking 4.0.x

Same name and namespace in other branches
  1. 8.3 tests/src/Functional/FreelinkingFilterTest.php \Drupal\Tests\freelinking\Functional\FreelinkingFilterTest::testFreelinkingPlugins()

Tests all plugins.

Throws

\Behat\Mink\Exception\ResponseTextException

\Behat\Mink\Exception\ExpectationException

File

tests/src/Functional/FreelinkingFilterTest.php, line 54

Class

FreelinkingFilterTest
Tests that freelinking filter is functional.

Namespace

Drupal\Tests\freelinking\Functional

Code

public function testFreelinkingPlugins() {

  // Create node that will contain a sample of each plugin.
  $edit = [];
  $edit['title[0][value]'] = t('Testing all freelinking plugins');
  $edit['body[0][value]'] = $this
    ->getNodeBodyValue();
  $this
    ->drupalGet('/node/add/page');
  $this
    ->submitForm($edit, 'Save');
  $this
    ->assertSession()
    ->pageTextContains(t('Basic page @title has been created.', [
    '@title' => $edit['title[0][value]'],
  ]));

  // Verify each freelink plugin.
  $this
    ->assertSession()
    ->linkExists(t('First page'), 0, 'Generate default plugin (nodetitle) freelink.');
  $this
    ->assertSession()
    ->linkExists(t('Second page'), 0, 'Generate Nodetitle freelink.');
  $this
    ->assertSession()
    ->linkExists(t('Second page'), 0, 'Generate Nid freelink.');
  $this
    ->assertSession()
    ->linkExists($this->privilegedUser
    ->getAccountName(), 0, 'Generate User freelink my uid.');
  $this
    ->assertSession()
    ->linkExists($this->privilegedUser
    ->getAccountName(), 1, 'Generate User freelink by user name.');
  $this
    ->assertSession()
    ->linkByHrefExists('https://drupal.org/project/freelinking', 0, 'Generate Drupalproject freelink.');
  $this
    ->assertSession()
    ->linkByHrefExists('https://drupal.org/node/1', 0, 'Generate Drupalorg freelink.');
  $this
    ->assertSession()
    ->linkByHrefExists('/search/node?keys=test', 0, 'Generate Search freelink.');

  // Query parameters are not guaranteed to be in a specific order based on
  // PHP version changes. This should be covered better by
  // \Drupal\Tests\freelinking\Unit\Plugin\freelinking\GoogleSearchTest.
  $this
    ->assertSession()
    ->linkByHrefExists('https://google.com/search', 0, 'Generate Google freelink.');
  $this
    ->assertSession()
    ->linkExists('logo.svg', 0, 'Generate File freelink.');
  $this
    ->assertSession()
    ->linkByHrefExists('https://en.wikipedia.org/wiki/Main_Page', 0, 'Generate Wikipedia freelink.');
  $this
    ->assertSession()
    ->linkByHrefExists('https://en.wikisource.org/wiki/Main_Page', 0, 'Generate Wikisource freelink.');
  $this
    ->assertSession()
    ->linkByHrefExists('https://en.wiktionary.org/wiki/Main_Page', 0, 'Generate Wiktionary freelink.');
  $this
    ->assertSession()
    ->linkByHrefExists('https://en.wikiquote.org/wiki/Main_Page', 0, 'Generate Wikiquote freelink.');
  $this
    ->assertSession()
    ->linkByHrefExists('https://en.wikibooks.org/wiki/Main_Page', 0, 'Generate Wikibooks freelink.');
  $this
    ->assertSession()
    ->linkByHrefExists('https://en.wikinews.org/wiki/Main_Page', 0, 'Generate Wikinews freelink.');
  $this
    ->assertSession()
    ->linkByHrefExists('/third-page', 0, 'Generate Path Alias freelink.');
  $this
    ->assertSession()
    ->pageTextContains('Shown Text');
  $this
    ->assertSession()
    ->pageTextContains('[[No Wiki]]');

  // @todo Media module parse test.
}