View source
<?php
namespace Drupal\filter\Tests;
use Drupal\simpletest\KernelTestBase;
use Drupal\user\RoleInterface;
class FilterDefaultConfigTest extends KernelTestBase {
public static $modules = array(
'system',
'user',
'filter',
'filter_test',
);
protected function setUp() {
parent::setUp();
$this
->installSchema('system', 'url_alias');
$this
->installEntitySchema('user');
$this
->installConfig(array(
'user',
'filter_test',
));
}
function testInstallation() {
$format = entity_load('filter_format', 'filter_test');
$this
->assertTrue((bool) $format);
$this
->assertEqual($format
->id(), 'filter_test');
$this
->assertEqual($format
->label(), 'Test format');
$this
->assertEqual($format
->get('weight'), 2);
$this
->assertTrue($format
->uuid());
$this
->assertEqual($format
->get('roles'), NULL);
$this
->assertEqual(array_keys(filter_get_roles_by_format($format)), array(
RoleInterface::ANONYMOUS_ID,
RoleInterface::AUTHENTICATED_ID,
));
$filters = $format
->get('filters');
$this
->assertEqual($filters['filter_html_escape']['status'], 1);
$this
->assertEqual($filters['filter_html_escape']['weight'], -10);
$this
->assertEqual($filters['filter_html_escape']['provider'], 'filter');
$this
->assertEqual($filters['filter_html_escape']['settings'], array());
$this
->assertEqual($filters['filter_autop']['status'], 1);
$this
->assertEqual($filters['filter_autop']['weight'], 0);
$this
->assertEqual($filters['filter_autop']['provider'], 'filter');
$this
->assertEqual($filters['filter_autop']['settings'], array());
$this
->assertEqual($filters['filter_url']['status'], 1);
$this
->assertEqual($filters['filter_url']['weight'], 0);
$this
->assertEqual($filters['filter_url']['provider'], 'filter');
$this
->assertEqual($filters['filter_url']['settings'], array(
'filter_url_length' => 72,
));
}
function testUpdateRoles() {
$format = entity_load('filter_format', 'filter_test');
$this
->assertEqual(array_keys(filter_get_roles_by_format($format)), array(
RoleInterface::ANONYMOUS_ID,
RoleInterface::AUTHENTICATED_ID,
));
$format
->set('roles', array(
RoleInterface::AUTHENTICATED_ID,
));
$format
->save();
$format = entity_load('filter_format', 'filter_test');
$this
->assertEqual(array_keys(filter_get_roles_by_format($format)), array(
RoleInterface::ANONYMOUS_ID,
RoleInterface::AUTHENTICATED_ID,
));
}
}