You are here

public function FunctionalTest::testFormatAdmin in No Non-breaking Space Filter 8

Tests the format administration functionality.

File

src/Tests/FunctionalTest.php, line 42

Class

FunctionalTest
Functional tests.

Namespace

Drupal\no_nbsp\Tests

Code

public function testFormatAdmin() {

  // Check format add page.
  $this
    ->drupalGet('admin/config/content/formats');
  $this
    ->clickLink('Add text format');
  $this
    ->assertText(t('No Non-breaking Space Filter'), 'Title text is shown.');
  $this
    ->assertText(t('Delete all non-breaking space HTML entities.'), 'Description text is shown.');
  $this
    ->assertText(t('Preserve placeholders.'), 'Settings: Title.');
  $this
    ->assertText(t('A placeholder non-breaking space is surrounded by a HTML tag'), 'Settings: Description.');

  // Add new format.
  $format_id = 'no_nbsp_format';
  $name = 'No nbsp filter format';
  $edit = [
    'format' => $format_id,
    'name' => $name,
    'roles[anonymous]' => 1,
    'roles[authenticated]' => 1,
    'filters[filter_no_nbsp][status]' => 1,
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Save configuration'));

  // Text the filters tips.
  $this
    ->drupalGet('filter/tips');
  $this
    ->assertText(t('All non-breaking space HTML entities are replaced by blank space characters.'));
  $this
    ->assertText(t('Multiple contiguous space characters are replaced by a single blank space character.'));

  // Show submitted format edit page.
  $this
    ->drupalGet('admin/config/content/formats/manage/' . $format_id);
  $input = $this
    ->xpath('//input[@id="edit-filters-filter-no-nbsp-status"]');
  $this
    ->assertEqual($input[0]
    ->attributes()->checked, 'checked');

  // Test the format object.
  filter_formats_reset();
  $formats = filter_formats();
  $this
    ->assertIdentical($formats[$format_id]
    ->get('name'), $name);

  // Check format overview page.
  $this
    ->drupalGet('admin/config/content/formats');
  $this
    ->assertText($name);

  // Generate a page without the enabled text filter.
  $node = $this
    ->createFormatAndNode('l   o   l', 0);
  $this
    ->assertRaw('l   o   l');
  $this
    ->drupalGet('node/' . $node
    ->id() . '/edit');

  // no_nbsp_format exists at this time.
  $this
    ->assertText(t('All non-breaking space HTML entities are replaced by blank space characters.'));
  $this
    ->assertNoText(t('Multiple contiguous space characters are replaced by a single blank space character.'));

  // Generate a page with the enabled text filter.
  $node = $this
    ->createFormatAndNode('l   o   l', 1);
  $this
    ->assertRaw('l o l');
  $this
    ->drupalGet('node/' . $node
    ->id() . '/edit');
  $this
    ->assertText(t('All non-breaking space HTML entities are replaced by blank space characters.'));
  $this
    ->assertNoText(t('Multiple contiguous space characters are replaced by a single blank space character.'));
}