Mercurial > hg > isophonics-drupal-site
comparison core/tests/Drupal/Tests/Component/Utility/SafeMarkupTest.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 1fec387a4317 |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
16 | 16 |
17 /** | 17 /** |
18 * Tests marking strings as safe. | 18 * Tests marking strings as safe. |
19 * | 19 * |
20 * @group Utility | 20 * @group Utility |
21 * @group legacy | |
21 * @coversDefaultClass \Drupal\Component\Utility\SafeMarkup | 22 * @coversDefaultClass \Drupal\Component\Utility\SafeMarkup |
22 */ | 23 */ |
23 class SafeMarkupTest extends TestCase { | 24 class SafeMarkupTest extends TestCase { |
24 | 25 |
25 /** | 26 /** |
33 | 34 |
34 /** | 35 /** |
35 * Tests SafeMarkup::isSafe() with different objects. | 36 * Tests SafeMarkup::isSafe() with different objects. |
36 * | 37 * |
37 * @covers ::isSafe | 38 * @covers ::isSafe |
39 * @expectedDeprecation SafeMarkup::isSafe() is scheduled for removal in Drupal 9.0.0. Instead, you should just check if a variable is an instance of \Drupal\Component\Render\MarkupInterface. See https://www.drupal.org/node/2549395. | |
38 */ | 40 */ |
39 public function testIsSafe() { | 41 public function testIsSafe() { |
40 $safe_string = $this->getMockBuilder('\Drupal\Component\Render\MarkupInterface')->getMock(); | 42 $safe_string = $this->getMockBuilder('\Drupal\Component\Render\MarkupInterface')->getMock(); |
41 $this->assertTrue(SafeMarkup::isSafe($safe_string)); | 43 $this->assertTrue(SafeMarkup::isSafe($safe_string)); |
42 $string_object = new SafeMarkupTestString('test'); | 44 $string_object = new SafeMarkupTestString('test'); |
46 /** | 48 /** |
47 * Tests SafeMarkup::checkPlain(). | 49 * Tests SafeMarkup::checkPlain(). |
48 * | 50 * |
49 * @dataProvider providerCheckPlain | 51 * @dataProvider providerCheckPlain |
50 * @covers ::checkPlain | 52 * @covers ::checkPlain |
53 * @expectedDeprecation SafeMarkup::checkPlain() is scheduled for removal in Drupal 9.0.0. Rely on Twig's auto-escaping feature, or use the @link theme_render #plain_text @endlink key when constructing a render array that contains plain text in order to use the renderer's auto-escaping feature. If neither of these are possible, \Drupal\Component\Utility\Html::escape() can be used in places where explicit escaping is needed. See https://www.drupal.org/node/2549395. | |
51 * | 54 * |
52 * @param string $text | 55 * @param string $text |
53 * The text to provide to SafeMarkup::checkPlain(). | 56 * The text to provide to SafeMarkup::checkPlain(). |
54 * @param string $expected | 57 * @param string $expected |
55 * The expected output from the function. | 58 * The expected output from the function. |
105 /** | 108 /** |
106 * Tests string formatting with SafeMarkup::format(). | 109 * Tests string formatting with SafeMarkup::format(). |
107 * | 110 * |
108 * @dataProvider providerFormat | 111 * @dataProvider providerFormat |
109 * @covers ::format | 112 * @covers ::format |
113 * @expectedDeprecation SafeMarkup::format() is scheduled for removal in Drupal 9.0.0. Use \Drupal\Component\Render\FormattableMarkup. See https://www.drupal.org/node/2549395. | |
110 * | 114 * |
111 * @param string $string | 115 * @param string $string |
112 * The string to run through SafeMarkup::format(). | 116 * The string to run through SafeMarkup::format(). |
113 * @param string[] $args | 117 * @param string[] $args |
114 * The arguments to pass into SafeMarkup::format(). | 118 * The arguments to pass into SafeMarkup::format(). |
123 UrlHelper::setAllowedProtocols(['http', 'https', 'mailto']); | 127 UrlHelper::setAllowedProtocols(['http', 'https', 'mailto']); |
124 | 128 |
125 $result = SafeMarkup::format($string, $args); | 129 $result = SafeMarkup::format($string, $args); |
126 $this->assertEquals($expected, (string) $result, $message); | 130 $this->assertEquals($expected, (string) $result, $message); |
127 $this->assertEquals($expected_is_safe, $result instanceof MarkupInterface, 'SafeMarkup::format correctly sets the result as safe or not safe.'); | 131 $this->assertEquals($expected_is_safe, $result instanceof MarkupInterface, 'SafeMarkup::format correctly sets the result as safe or not safe.'); |
128 | |
129 foreach ($args as $arg) { | |
130 $this->assertSame($arg instanceof SafeMarkupTestMarkup, SafeMarkup::isSafe($arg)); | |
131 } | |
132 } | 132 } |
133 | 133 |
134 /** | 134 /** |
135 * Data provider for testFormat(). | 135 * Data provider for testFormat(). |
136 * | 136 * |