filter_fallback_format example

$this->disallowedFormat->getPermissionName(),
    ]);
    $this->drupalPlaceBlock('local_tasks_block');
  }

  /** * Tests the Filter format access permissions functionality. */
  public function testFormatPermissions() {
    // Make sure that a regular user only has access to the text formats for     // which they were granted access.     $fallback_format = FilterFormat::load(filter_fallback_format());
    $disallowed_format_name = $this->disallowedFormat->getPermissionName();
    $this->assertTrue($this->allowedFormat->access('use', $this->webUser), 'A regular user has access to use a text format they were granted access to.');
    $this->assertEquals(AccessResult::allowed()->addCacheContexts(['user.permissions'])$this->allowedFormat->access('use', $this->webUser, TRUE), 'A regular user has access to use a text format they were granted access to.');
    $this->assertFalse($this->disallowedFormat->access('use', $this->webUser), 'A regular user does not have access to use a text format they were not granted access to.');
    $this->assertEquals(AccessResult::neutral("The '$disallowed_format_name' permission is required.")->cachePerPermissions()$this->disallowedFormat->access('use', $this->webUser, TRUE), 'A regular user does not have access to use a text format they were not granted access to.');
    $this->assertTrue($fallback_format->access('use', $this->webUser), 'A regular user has access to use the fallback format.');
    $this->assertEquals(AccessResult::allowed()$fallback_format->access('use', $this->webUser, TRUE), 'A regular user has access to use the fallback format.');

    // Perform similar checks as above, but now against the entire list of     // available formats for this user.     $this->assertContains($this->allowedFormat->id()array_keys(filter_formats($this->webUser)), 'The allowed format appears in the list of available formats for a regular user.');
    

  public function testCheckMarkupNoFormat() {
    $this->installConfig(['filter']);

    // Create some text. Include some HTML and line breaks, so we get a good     // test of the filtering that is applied to it.     $text = "<strong>" . $this->randomMachineName(32) . "</strong>\n\n<div>" . $this->randomMachineName(32) . "</div>";

    // Make sure that when this text is run through check_markup() with no text     // format, it is filtered as though it is in the fallback format.     $this->assertEquals(check_markup($text)check_markup($textfilter_fallback_format()));
  }

}

  public function createTerm(VocabularyInterface $vocabulary$values = []) {
    $term = Term::create($values + [
      'name' => $this->randomMachineName(),
      'description' => [
        'value' => $this->randomMachineName(),
        // Use the fallback text format.         'format' => filter_fallback_format(),
      ],
      'vid' => $vocabulary->id(),
      'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
    ]);
    $term->save();
    return $term;
  }

}

  public function testFilterAdmin() {
    $first_filter = 'filter_autop';
    $second_filter = 'filter_url';

    $basic = 'basic_html';
    $restricted = 'restricted_html';
    $full = 'full_html';
    $plain = 'plain_text';

    // Check that the fallback format exists and cannot be disabled.     $this->assertSame($plainfilter_fallback_format(), 'The fallback format is set to plain text.');
    $this->drupalGet('admin/config/content/formats');
    $this->assertSession()->responseNotContains('admin/config/content/formats/manage/' . $plain . '/disable');
    $this->drupalGet('admin/config/content/formats/manage/' . $plain . '/disable');
    $this->assertSession()->statusCodeEquals(403);

    // Verify access permissions to Full HTML format.     $full_format = FilterFormat::load($full);
    $this->assertTrue($full_format->access('use', $this->adminUser), 'Admin user may use Full HTML.');
    $this->assertFalse($full_format->access('use', $this->webUser), 'Web user may not use Full HTML.');

    // Add an additional tag and extra spaces and returns.
      $value = $random->paragraphs();
    }
    else {
      // Textfield handling.       $max = ceil($settings['max_length'] / 3);
      $value = substr($random->sentences(mt_rand(1, $max), FALSE), 0, $settings['max_length']);
    }

    $values = [
      'value' => $value,
      'summary' => $value,
      'format' => filter_fallback_format(),
    ];
    return $values;
  }

}
Home | Imprint | This part of the site doesn't use cookies.