You are here

public function FreelinkingPrepopulateTest::testFreelinkingPrepopulate in Freelinking 4.0.x

Same name and namespace in other branches
  1. 8.3 modules/freelinking_prepopulate/tests/src/Functional/FreelinkingPrepopulateTest.php \Drupal\Tests\freelinking_prepopulate\Functional\FreelinkingPrepopulateTest::testFreelinkingPrepopulate()

Asserts that prepopulate links are displayed correctly.

Throws

\Behat\Mink\Exception\ExpectationException

File

modules/freelinking_prepopulate/tests/src/Functional/FreelinkingPrepopulateTest.php, line 113

Class

FreelinkingPrepopulateTest
Tests embedded prepopulate links.

Namespace

Drupal\Tests\freelinking_prepopulate\Functional

Code

public function testFreelinkingPrepopulate() {

  // Creates a node for the assertions.
  $edit = [];
  $edit['title[0][value]'] = t('Testing all freelinking plugins');
  $edit['body[0][value]'] = <<<EOF
      <ul>
        <li>Default with body: [[create:Alex|Alex|Add Alex|body="A page about Alex."]]</li>
        <li>Basic page: [[create:History of Programming|History of Programming|Create New Page|type=page]]</li>
        <li>With fields: [[create:Sam|Sam|Add Sam|body="A page about Sam."|field_basic="test"|field_tags="tag1,tag2,tag3"]]</li>
      </ul>
EOF;
  $this
    ->drupalGet('node/add/page');
  $this
    ->submitForm($edit, 'Save');

  // This is the most ridiculous developer-unfriendly way to test hrefs ever.
  // DrupalWTF. MinkWTF.
  $defaultLinkHref = '/node/add/person?' . rawurlencode('edit[title][widget][0][value]') . '=' . rawurlencode('Alex') . '&' . rawurlencode('edit[body][widget][0][value]') . '=' . rawurlencode('&quot;A page about Alex.&quot;');
  $pageLinkHref = '/node/add/page?' . rawurlencode('edit[title][widget][0][value]') . '=History%20of%20Programming';
  $fieldsLinkHref = '/node/add/person?' . rawurlencode('edit[title][widget][0][value]') . '=Sam&' . rawurlencode('edit[body][widget][0][value]') . '=' . rawurlencode('&quot;A page about Sam.&quot;') . '&' . rawurlencode('edit[field_basic][widget][0][value]') . '=' . rawurlencode('&quot;test&quot;') . '&' . rawurlencode('edit[field_tags][widget][target_id]') . '=' . rawurlencode('&quot;tag1,tag2,tag3&quot;');
  $this
    ->assertSession()
    ->linkByHrefExists($defaultLinkHref);
  $this
    ->assertSession()
    ->linkByHrefExists($pageLinkHref);
  $this
    ->assertSession()
    ->linkByHrefExists($fieldsLinkHref);

  // Logout and visit the page.
  $this
    ->drupalLogout();
  $this
    ->drupalGet('/node/3');
  $this
    ->assertSession()
    ->pageTextContains('Freelinking: Access denied to create missing content.');
  $this
    ->assertSession()
    ->linkByHrefNotExists($defaultLinkHref, 'Link to create default content type not found.');
  $this
    ->assertSession()
    ->linkByHrefNotExists($pageLinkHref, 'Link to create specified content type not found.');
  $this
    ->assertSession()
    ->linkByHrefNotExists($fieldsLinkHref, 'Link to create content with fields not found.');
}