You are here

public function FieldFormatterTest::testFieldFormatter in No Non-breaking Space Filter 8

Field formatter.

File

src/Tests/FieldFormatterTest.php, line 41

Class

FieldFormatterTest
The no non-breaking space filter acts as a field formatter.

Namespace

Drupal\no_nbsp\Tests

Code

public function testFieldFormatter() {
  $this
    ->createTextFormatWeb('with_no_nbsp', TRUE);
  $this
    ->createTextFormatWeb('without_no_nbsp', FALSE);

  // Check admin interface.
  $this
    ->drupalGet('admin/structure/types/manage/page/display');
  $this
    ->assertText(t('No Non-breaking Space Filter'));

  // Create node with full html support.
  $edit = [];
  $title = $this
    ->randomMachineName();
  $edit['title[0][value]'] = $title;
  $edit['body[0][value]'] = 'l   o   l';
  $edit['body[0][format]'] = 'without_no_nbsp';
  $this
    ->drupalPostForm('node/add/page', $edit, t('Save'));
  $node = $this
    ->drupalGetNodeByTitle($title);

  // The field formatter is not set.
  $this
    ->assertRaw('l   o   l');

  // Change display.
  $edit = [
    'fields[body][type]' => 'no_nbsp',
  ];
  $this
    ->drupalPostForm('admin/structure/types/manage/page/display', $edit, t('Save'));

  // Check if the field formatter works.
  $this
    ->drupalGet('node/' . $node
    ->id());
  $this
    ->assertRaw('l o l');
}