public function FilterFormatUpgradePathTest::testFilterFormatUpgrade

Tests expected filter formats entities after a successful upgrade.

File

drupal/core/modules/system/lib/Drupal/system/Tests/Upgrade/FilterFormatUpgradePathTest.php, line 40
Contains \Drupal\system\Tests\Upgrade\FilterFormatUpgradePathTest.

Class

FilterFormatUpgradePathTest
Tests upgrading a bare database with user filter format data.

Namespace

Drupal\system\Tests\Upgrade

Code

public function testFilterFormatUpgrade() {
  $this
    ->assertTrue($this
    ->performUpgrade(), 'The upgrade was completed successfully.');

  // Checks that all the formats were upgraded
  $one = filter_format_load('format_one');
  $this
    ->assertTrue(!empty($one), 'Filter Format one was successfully upgraded');
  $two = filter_format_load('format_two');
  $this
    ->assertTrue(!empty($two), 'Filter Format two was successfully upgraded');

  // Filter format 'Three' is disabled, and filter_format_load should return
  // FALSE. However the entity should be accessible using entity_load.
  $three_disabled = filter_format_load('format_three');
  $three_entity = entity_load('filter_format', 'format_three');
  $this
    ->assertTrue(empty($three_disabled) && !empty($three_entity), 'Filter Format three was successfully upgraded and it is disabled');

  // Check the access to the text formats.
  // Check that the anonymous user role ID has been converted from "1" to
  // "anonymous" and text formats permissions were updated.
  $this
    ->drupalGet('admin/people/permissions');
  $this
    ->assertFieldChecked('edit-anonymous-use-text-format-format-one', 'Use text format format_one permission for "anonymous" is set correctly.');
  $this
    ->assertNoFieldChecked('edit-anonymous-use-text-format-format-two', 'Use text format format_two permission for "anonymous" is set correctly.');

  // Check that the anonymous user role ID has been converted from "2" to
  // "authenticated" and text formats permissions were updated.
  $this
    ->assertNoFieldChecked('edit-authenticated-use-text-format-format-one', 'Use text format format_one permission for "authenticated" is set correctly.');
  $this
    ->assertFieldChecked('edit-authenticated-use-text-format-format-two', 'Use text format format_two permission for "authenticated" is set correctly.');

  // Check that the permission for "gärtner" still exists and text formats
  // permissions were updated.
  $this
    ->assertFieldChecked('edit-4-use-text-format-format-one', 'Use text format format_one permission for role is set correctly.');
  $this
    ->assertNoFieldChecked('edit-4-use-text-format-format-two', 'Use text format format_two permission for role is set correctly.');

  // Check that role 5 cannot access to the defined text formats
  $this
    ->assertNoFieldChecked('edit-5-use-text-format-format-one', 'Use text format format_one permission for role is set correctly.');
  $this
    ->assertNoFieldChecked('edit-5-use-text-format-format-two', 'Use text format format_two permission for role is set correctly.');
}