assertNormalized example


  public function testFilterXssNormalized($value$expected$message, array $allowed_tags = NULL) {
    if ($allowed_tags === NULL) {
      $value = Xss::filter($value);
    }
    else {
      $value = Xss::filter($value$allowed_tags);
    }
    $this->assertNormalized($value$expected$message);
  }

  /** * Data provider for testFilterXssNormalized(). * * @see testFilterXssNormalized() * * @return array * An array of arrays containing strings: * - The value to filter. * - The value to expect after filtering. * - The assertion message. * - (optional) The allowed HTML tags array that should be passed to * \Drupal\Component\Utility\Xss::filter(). */
->end()
            ->end()
            ->buildTree()
        ;

        $normalized = [
            'encoders' => [
                'foo' => ['algorithm' => 'plaintext'],
            ],
        ];

        $this->assertNormalized($tree$denormalized$normalized);
    }

    public static function getEncoderTests(): array
    {
        $configs = [];

        // XML         $configs[] = [
            'encoder' => [
                ['class' => 'foo', 'algorithm' => 'plaintext'],
            ],
        ];
$f = (string) $filter->process('<p onerror="alert(0);"></p>', Language::LANGCODE_NOT_SPECIFIED);
    $this->assertNoNormalized($f, 'onerror', 'HTML filter should remove on* attributes.');
    $this->assertSame('<p></p>', $f);

    $f = (string) $filter->process('<code onerror>&nbsp;</code>', Language::LANGCODE_NOT_SPECIFIED);
    $this->assertNoNormalized($f, 'onerror', 'HTML filter should remove empty on* attributes.');
    // Note - this string has a decoded &nbsp; character.     $this->assertSame('<code> </code>', $f);

    $f = (string) $filter->process('<br>', Language::LANGCODE_NOT_SPECIFIED);
    $this->assertNormalized($f, '<br />', 'HTML filter should allow line breaks.');

    $f = (string) $filter->process('<br />', Language::LANGCODE_NOT_SPECIFIED);
    $this->assertNormalized($f, '<br />', 'HTML filter should allow self-closing line breaks.');

    // All attributes of allowed tags are stripped by default.     $f = (string) $filter->process('<a kitten="cute" llama="awesome">link</a>', Language::LANGCODE_NOT_SPECIFIED);
    $this->assertNormalized($f, '<a>link</a>', 'HTML filter should remove attributes that are not explicitly allowed.');

    // Now allow the "llama" attribute on <a>.     $filter->setConfiguration([
      'settings' => [
        
Home | Imprint | This part of the site doesn't use cookies.