1 filter.test FilterAdminTestCase::testFormatAdmin()

Tests the format administration functionality.

File

core/modules/filter/tests/filter.test, line 213
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.');

  // Verify that the disabled section is not shown.
  $this->assertNoRaw(t('Enable'), 'A disabled text format is NOT shown.');

  // 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'));
  $this->assertRaw(t('Disabled text format %name.', array('%name' => $name)), 'Text format has been disabled.');
  $this->assertRaw(t('Enable'), 'A disabled text format is shown.');

  // Verify that the text format has been disabled. Links exist for it to be
  // enabled/configured...
  $this->assertLinkByHref('admin/config/content/formats/' . $format_id . '/enable');
  $this->assertLinkByHref('admin/config/content/formats/' . $format_id);
  // ...but no link for it to be disabled.
  $this->assertNoLinkByHref('admin/config/content/formats/' . $format_id . '/disable');

  // Enable the text format.
  $this->clickTextFormatOperationLink(t('Enable'), 'admin/config/content/formats/' . $format_id . '/enable');
  $this->assertRaw(t('Enabled text format %name.', array('%name' => $name)), 'Text format has been enabled.');

  // Verify that the text format has been enabled. Links exist for it to be
  // disabled/configured...
  $this->assertLinkByHref('admin/config/content/formats/' . $format_id);
  $this->assertLinkByHref('admin/config/content/formats/' . $format_id . '/disable');
  // ...but no link for it to be enabled.
  $this->assertNoLinkByHref('admin/config/content/formats/' . $format_id . '/enable');

  // Attempt to create a format of the same machine name as the disabled
  // format, but with a different human readable na
  $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.');
}