FilterDefaultConfigTest.php 3.26 KB
Newer Older
1 2 3 4 5 6 7 8 9
<?php

/**
 * @file
 * Contains Drupal\filter\Tests\FilterDefaultConfigTest.
 */

namespace Drupal\filter\Tests;

10
use Drupal\simpletest\KernelTestBase;
11 12 13

/**
 * Tests text format default configuration.
14 15
 *
 * @group filter
16
 */
17
class FilterDefaultConfigTest extends KernelTestBase {
18

19
  public static $modules = array('system', 'user', 'filter', 'filter_test', 'entity');
20

21
  protected function setUp() {
22
    parent::setUp();
23

24
    // Drupal\filter\FilterPermissions::permissions() calls into _url() to output
25
    // a link in the description.
26
    $this->installSchema('system', 'url_alias');
27

28
    $this->installEntitySchema('user');
29 30 31

    // Install filter_test module, which ships with custom default format.
    $this->installConfig(array('user', 'filter_test'));
32 33 34 35 36 37 38
  }

  /**
   * Tests installation of default formats.
   */
  function testInstallation() {
    // Verify that the format was installed correctly.
39
    $format = entity_load('filter_format', 'filter_test');
40
    $this->assertTrue((bool) $format);
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
    $this->assertEqual($format->id(), 'filter_test');
    $this->assertEqual($format->label(), 'Test format');
    $this->assertEqual($format->get('weight'), 2);

    // Verify that format default property values have been added/injected.
    $this->assertTrue($format->uuid());

    // Verify that the loaded format does not contain any roles.
    $this->assertEqual($format->get('roles'), NULL);
    // Verify that the defined roles in the default config have been processed.
    $this->assertEqual(array_keys(filter_get_roles_by_format($format)), array(
      DRUPAL_ANONYMOUS_RID,
      DRUPAL_AUTHENTICATED_RID,
    ));

    // Verify enabled filters.
    $filters = $format->get('filters');
    $this->assertEqual($filters['filter_html_escape']['status'], 1);
    $this->assertEqual($filters['filter_html_escape']['weight'], -10);
60
    $this->assertEqual($filters['filter_html_escape']['provider'], 'filter');
61 62 63
    $this->assertEqual($filters['filter_html_escape']['settings'], array());
    $this->assertEqual($filters['filter_autop']['status'], 1);
    $this->assertEqual($filters['filter_autop']['weight'], 0);
64
    $this->assertEqual($filters['filter_autop']['provider'], 'filter');
65 66 67
    $this->assertEqual($filters['filter_autop']['settings'], array());
    $this->assertEqual($filters['filter_url']['status'], 1);
    $this->assertEqual($filters['filter_url']['weight'], 0);
68
    $this->assertEqual($filters['filter_url']['provider'], 'filter');
69 70 71 72 73 74 75 76 77 78
    $this->assertEqual($filters['filter_url']['settings'], array(
      'filter_url_length' => 72,
    ));
  }

  /**
   * Tests that changes to FilterFormat::$roles do not have an effect.
   */
  function testUpdateRoles() {
    // Verify role permissions declared in default config.
79
    $format = entity_load('filter_format', 'filter_test');
80 81 82 83 84 85 86 87 88 89 90 91
    $this->assertEqual(array_keys(filter_get_roles_by_format($format)), array(
      DRUPAL_ANONYMOUS_RID,
      DRUPAL_AUTHENTICATED_RID,
    ));

    // Attempt to change roles.
    $format->set('roles', array(
      DRUPAL_AUTHENTICATED_RID,
    ));
    $format->save();

    // Verify that roles have not been updated.
92
    $format = entity_load('filter_format', 'filter_test');
93 94 95 96 97 98 99
    $this->assertEqual(array_keys(filter_get_roles_by_format($format)), array(
      DRUPAL_ANONYMOUS_RID,
      DRUPAL_AUTHENTICATED_RID,
    ));
  }

}