You are here

public function NoNbspIntegrationTestCase::testFormatAdmin in No Non-breaking Space Filter 7

Tests the format administration functionality.

File

./no_nbsp.test, line 130
Tests for the no_nbsp.module.

Class

NoNbspIntegrationTestCase
Tests the administrative functionality of the Filter module.

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 = array(
    'format' => $format_id,
    'name' => $name,
    'roles[1]' => 1,
    'roles[2]' => 1,
    'filters[filter_no_nbsp][status]' => 1,
  );
  $this
    ->drupalPost(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/' . $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->user);
  $this
    ->assertIdentical($formats[$format_id]->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);
  $node_without_filter = $node;
  $this
    ->assertRaw('l   o   l');
  $this
    ->drupalGet('node/' . $node->nid . '/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->nid . '/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.'));

  // Field formatter.
  $this
    ->drupalGet('admin/structure/types/manage/page/display');
  $this
    ->assertText(t('No Non-breaking Space Filter'));
  $edit = array(
    'fields[body][type]' => 'no_nbsp',
  );
  $this
    ->drupalPost(NULL, $edit, t('Save'));
  $this
    ->drupalGet('node/' . $node_without_filter->nid);
  $this
    ->assertRaw('l o l');
}