Upgraded drupal core with security updates
[yaffs-website] / web / core / tests / Drupal / Tests / Core / Field / FieldFilteredMarkupTest.php
1 <?php
2
3 namespace Drupal\Tests\Core\Field;
4
5 use Drupal\Tests\UnitTestCase;
6 use Drupal\Core\Field\FieldFilteredMarkup;
7 use Drupal\Component\Render\MarkupInterface;
8
9 /**
10  * @coversDefaultClass \Drupal\Core\Field\FieldFilteredMarkup
11  * @group Field
12  */
13 class FieldFilteredMarkupTest extends UnitTestCase {
14
15   /**
16    * @covers ::create
17    * @dataProvider providerTestCreate
18    */
19   public function testCreate($string, $expected, $instance_of_check) {
20     $filtered_string = FieldFilteredMarkup::create($string);
21
22     if ($instance_of_check) {
23       $this->assertInstanceOf(FieldFilteredMarkup::class, $filtered_string);
24     }
25     $this->assertSame($expected, (string) $filtered_string);
26   }
27
28   /**
29    * Provides data for testCreate().
30    */
31   public function providerTestCreate() {
32     $data = [];
33     $data[] = ['', '', FALSE];
34     // Certain tags are filtered.
35     $data[] = ['<script>teststring</script>', 'teststring', TRUE];
36     // Certain tags are not filtered.
37     $data[] = ['<em>teststring</em>', '<em>teststring</em>', TRUE];
38     // HTML will be normalized.
39     $data[] = ['<em>teststring', '<em>teststring</em>', TRUE];
40
41     // Even safe strings will be escaped.
42     $safe_string = $this->prophesize(MarkupInterface::class);
43     $safe_string->__toString()->willReturn('<script>teststring</script>');
44     $data[] = [$safe_string->reveal(), 'teststring', TRUE];
45
46     return $data;
47   }
48
49   /**
50    * @covers: ::displayAllowedTags
51    */
52   public function testdisplayAllowedTags() {
53     $expected = '<a> <b> <big> <code> <del> <em> <i> <ins> <pre> <q> <small> <span> <strong> <sub> <sup> <tt> <ol> <ul> <li> <p> <br> <img>';
54
55     $this->assertSame($expected, FieldFilteredMarkup::displayAllowedTags());
56   }
57
58 }