1 filter.test FilterAdminTestCase::testFormatAdmin()

Tests the format administration functionality.

File

core/modules/filter/tests/filter.test, line 165
Tests for filter.module.

Class

FilterAdminTestCase
Tests the administrative functionality of the Filter module.

Code

function testFormatAdmin() {
  // Add text format.
  $this->backdropGet('admin/config/content/formats');
  $this->clickLink('Add text format');
  $format_id = backdrop_strtolower($this->randomName());
  $name = $this->randomName();
  $edit = array(
    'format' => $format_id,
    'name' => $name,
  );
  $this->backdropPost(NULL, $edit, t('Save configuration'));

  // Attempt to create a format of the same human readable name as the
  // format but with a different machine name.
  $edit = array(
    'format' => 'new_format',
    'name' => $name,
  );
  $this->backdropPost('admin/config/content/formats/add', $edit, t('Save configuration'));
  $this->assertRaw(t('Text format names must be unique. A format named %name already exists.', array(
    '%name' => $name,
  )));

  // Verify default weight of the text format.
  $this->backdropGet('admin/config/content/formats');
  $this->assertFieldByName("formats[$format_id][weight]", 0, 'Text format weight was saved.');

  // Change the weight of the text format.
  $edit = array(
    "formats[$format_id][weight]" => 5,
  );
  $this->backdropPost('admin/config/content/formats', $edit, t('Save changes'));
  $this->assertFieldByName("formats[$format_id][weight]", 5, 'Text format weight was saved.');

  // Edit text format.
  $this->backdropGet('admin/config/content/formats');
  $this->assertLinkByHref('admin/config/content/formats/' . $format_id);
  $this->backdropGet('admin/config/content/formats/' . $format_id);
  $this->backdropPost(NULL, array(), t('Save configuration'));

  // Verify that the custom weight of the text format has been retained.
  $this->backdropGet('admin/config/content/formats');
  $this->assertFieldByName("formats[$format_id][weight]", 5, 'Text format weight was retained.');

  // Disable text format.
  $this->assertLinkByHref('admin/config/content/formats/' . $format_id . '/disable');
  $this->backdropGet('admin/config/content/formats/' . $format_id . '/disable');
  $this->backdropPost(NULL, array(), t('Disable'));

  // Verify that disabled text format no longer exists.
  $this->backdropGet('admin/config/content/formats/' . $format_id);
  $this->assertResponse(404, 'Disabled text format no longer exists.');

  // Attempt to create a format of the same machine name as the disabled
  // format but with a different human readable name.
  $edit = array(
    'format' => $format_id,
    'name' => 'New format',
  );
  $this->backdropPost('admin/config/content/formats/add', $edit, t('Save configuration'));
  $this->assertText('The machine-readable name is already in use. It must be unique.');
}