function FilterCrudTest::verifyTextFormat

Verifies that a text format is properly stored.

1 call to FilterCrudTest::verifyTextFormat()
FilterCrudTest::testTextFormatCrud in drupal/core/modules/filter/lib/Drupal/filter/Tests/FilterCrudTest.php
Tests CRUD operations for text formats and filters.

File

drupal/core/modules/filter/lib/Drupal/filter/Tests/FilterCrudTest.php, line 88
Definition of Drupal\filter\Tests\FilterCrudTest.

Class

FilterCrudTest
Tests for text format and filter CRUD operations.

Namespace

Drupal\filter\Tests

Code

function verifyTextFormat($format) {
  $t_args = array(
    '%format' => $format->name,
  );
  $default_langcode = language_default()->langcode;

  // Verify filter_format_load().
  $filter_format = filter_format_load($format->format);
  $this
    ->assertEqual($filter_format->format, $format->format, format_string('filter_format_load: Proper format id for text format %format.', $t_args));
  $this
    ->assertEqual($filter_format->name, $format->name, format_string('filter_format_load: Proper title for text format %format.', $t_args));
  $this
    ->assertEqual($filter_format->cache, $format->cache, format_string('filter_format_load: Proper cache indicator for text format %format.', $t_args));
  $this
    ->assertEqual($filter_format->weight, $format->weight, format_string('filter_format_load: Proper weight for text format %format.', $t_args));

  // Check that the filter was created in site default language.
  $this
    ->assertEqual($format->langcode, $default_langcode, format_string('filter_format_load: Proper language code for text format %format.', $t_args));

  // Verify the 'cache' text format property according to enabled filters.
  $filters = filter_list_format($filter_format->format);
  $cacheable = TRUE;
  foreach ($filters as $name => $filter) {

    // If this filter is not cacheable, update $cacheable accordingly, so we
    // can verify $format->cache after iterating over all filters.
    if ($filter->status && !$filter->cache) {
      $cacheable = FALSE;
      break;
    }
  }
  $this
    ->assertEqual($filter_format->cache, $cacheable, 'Text format contains proper cache property.');
}