You are here

public function PageSpecificTest::doTestForm in Page Specific Class 2.0.x

Check class added by page_specific_class.

1 call to PageSpecificTest::doTestForm()
PageSpecificTest::testFunctional in test/src/Functional/PageSpecificTest.php

File

test/src/Functional/PageSpecificTest.php, line 71

Class

PageSpecificTest
Ensure that the page_specific_class forms work properly.

Namespace

Drupal\Tests\page_specific_class\Functional

Code

public function doTestForm() {
  $assertion = $this
    ->assertSession();

  // Create node.
  $node = Node::create([
    'type' => 'page',
    'title' => 'Node Example',
  ]);
  $node
    ->save();
  $nid = $node
    ->id();

  // Go to configuration page and enter details and save the form.
  $path = Url::fromRoute("page_specific_class.settings");
  $this
    ->drupalGet($path);
  $edit = [
    'url_with_class' => "/node/{$nid}|custom-node",
  ];
  $this
    ->drupalPostForm(Url::fromRoute('page_specific_class.settings'), $edit, 'Save configuration');

  // Check configuration is saved.
  $assertion
    ->pageTextContains('The configuration options have been saved.');

  // Go to the node page,  and chek on body tag "custom-node" class
  // is present.
  $this
    ->drupalGet("/node/{$nid}");
  $body_class_element = $this
    ->xpath("//body[contains(@class, 'custom-node')]");
  $this
    ->assertTrue(!empty($body_class_element), 'custom-node class not found.');
}