function FilterCRUDTestCase::testTextFormatCRUD

7.x filter.test FilterCRUDTestCase::testTextFormatCRUD()

Tests CRUD operations for text formats and filters.

File

drupal-7.x/modules/filter/filter.test, line 27
Tests for filter.module.

Class

FilterCRUDTestCase
Tests for text format and filter CRUD operations.

Code

function testTextFormatCRUD() {
  // Add a text format with minimum data only.
  $format = new stdClass();
  $format->format = 'empty_format';
  $format->name = 'Empty format';
  filter_format_save($format);
  $this->verifyTextFormat($format);
  $this->verifyFilters($format);

  // Add another text format specifying all possible properties.
  $format = new stdClass();
  $format->format = 'custom_format';
  $format->name = 'Custom format';
  $format->filters = array(
    'filter_url' => array(
      'status' => 1,
      'settings' => array(
        'filter_url_length' => 30,
      ),
    ),
  );
  filter_format_save($format);
  $this->verifyTextFormat($format);
  $this->verifyFilters($format);

  // Alter some text format properties and save again.
  $format->name = 'Altered format';
  $format->filters['filter_url']['status'] = 0;
  $format->filters['filter_autop']['status'] = 1;
  filter_format_save($format);
  $this->verifyTextFormat($format);
  $this->verifyFilters($format);

  // Add a uncacheable filter and save again.
  $format->filters['filter_test_uncacheable']['status'] = 1;
  filter_format_save($format);
  $this->verifyTextFormat($format);
  $this->verifyFilters($format);

  // Disable the text format.
  filter_format_disable($format);

  $db_format = db_query("SELECT * FROM {filter_format} WHERE format = :format", array(':format' => $format->format))->fetchObject();
  $this->assertFalse($db_format->status, 'Database: Disabled text format is marked as disabled.');
  $formats = filter_formats();
  $this->assertTrue(!isset($formats[$format->format]), 'filter_formats: Disabled text format no longer exists.');
}