FilterSettingsTest.php 1.84 KB
Newer Older
1 2 3 4
<?php

/**
 * @file
5
 * Contains \Drupal\filter\Tests\FilterSettingsTest.
6 7 8 9
 */

namespace Drupal\filter\Tests;

10
use Drupal\simpletest\KernelTestBase;
11 12 13

/**
 * Tests filter settings.
14 15
 *
 * @group filter
16
 */
17
class FilterSettingsTest extends KernelTestBase {
18

19
  /**
20
   * Modules to enable.
21
   *
22
   * @var array
23
   */
24
  public static $modules = array('filter');
25 26 27 28 29

  /**
   * Tests explicit and implicit default settings for filters.
   */
  function testFilterDefaults() {
30
    $filter_info = $this->container->get('plugin.manager.filter')->getDefinitions();
31 32

    // Create text format using filter default settings.
33
    $filter_defaults_format = entity_create('filter_format', array(
34 35
      'format' => 'filter_defaults',
      'name' => 'Filter defaults',
36 37
    ));
    $filter_defaults_format->save();
38 39 40

    // Verify that default weights defined in hook_filter_info() were applied.
    $saved_settings = array();
41 42 43
    foreach ($filter_defaults_format->filters() as $name => $filter) {
      $expected_weight = $filter_info[$name]['weight'];
      $this->assertEqual($filter->weight, $expected_weight, format_string('@name filter weight %saved equals %default', array(
44
        '@name' => $name,
45
        '%saved' => $filter->weight,
46 47 48 49 50 51
        '%default' => $expected_weight,
      )));
      $saved_settings[$name]['weight'] = $expected_weight;
    }

    // Re-save the text format.
52
    $filter_defaults_format->save();
53 54 55 56
    // Reload it from scratch.
    filter_formats_reset();

    // Verify that saved filter settings have not been changed.
57
    foreach ($filter_defaults_format->filters() as $name => $filter) {
58
      $this->assertEqual($filter->weight, $saved_settings[$name]['weight'], format_string('@name filter weight %saved equals %previous', array(
59
        '@name' => $name,
60
        '%saved' => $filter->weight,
61 62 63 64 65
        '%previous' => $saved_settings[$name]['weight'],
      )));
    }
  }
}