Mercurial > hg > isophonics-drupal-site
comparison core/tests/Drupal/KernelTests/Component/Utility/SafeMarkupKernelTest.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 4c8ae668cc8c |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
1 <?php | 1 <?php |
2 | 2 |
3 namespace Drupal\KernelTests\Component\Utility; | 3 namespace Drupal\KernelTests\Component\Utility; |
4 | 4 |
5 use Drupal\Component\Utility\SafeMarkup; | 5 use Drupal\Component\Render\FormattableMarkup; |
6 use Drupal\Core\Url; | 6 use Drupal\Core\Url; |
7 use Drupal\KernelTests\KernelTestBase; | 7 use Drupal\KernelTests\KernelTestBase; |
8 | 8 |
9 /** | 9 /** |
10 * Provides a test covering integration of SafeMarkup with other systems. | 10 * Provides a test covering integration of SafeMarkup with other systems. |
26 | 26 |
27 $this->container->get('router.builder')->rebuild(); | 27 $this->container->get('router.builder')->rebuild(); |
28 } | 28 } |
29 | 29 |
30 /** | 30 /** |
31 * Gets arguments for SafeMarkup::format() based on Url::fromUri() parameters. | 31 * Gets arguments for FormattableMarkup based on Url::fromUri() parameters. |
32 * | 32 * |
33 * @param string $uri | 33 * @param string $uri |
34 * The URI of the resource. | 34 * The URI of the resource. |
35 * @param array $options | 35 * @param array $options |
36 * The options to pass to Url::fromUri(). | 36 * The options to pass to Url::fromUri(). |
37 * | 37 * |
38 * @return array | 38 * @return array |
39 * Array containing: | 39 * Array containing: |
40 * - ':url': A URL string. | 40 * - ':url': A URL string. |
41 * | |
42 * @see \Drupal\Component\Render\FormattableMarkup | |
41 */ | 43 */ |
42 protected static function getSafeMarkupUriArgs($uri, $options = []) { | 44 protected static function getSafeMarkupUriArgs($uri, $options = []) { |
43 $args[':url'] = Url::fromUri($uri, $options)->toString(); | 45 $args[':url'] = Url::fromUri($uri, $options)->toString(); |
44 return $args; | 46 return $args; |
45 } | 47 } |
46 | 48 |
47 /** | 49 /** |
48 * Tests URL ":placeholders" in SafeMarkup::format(). | 50 * Tests URL ":placeholders" in \Drupal\Component\Render\FormattableMarkup. |
49 * | 51 * |
50 * @dataProvider providerTestSafeMarkupUri | 52 * @dataProvider providerTestSafeMarkupUri |
51 */ | 53 */ |
52 public function testSafeMarkupUri($string, $uri, $options, $expected) { | 54 public function testSafeMarkupUri($string, $uri, $options, $expected) { |
53 $args = self::getSafeMarkupUriArgs($uri, $options); | 55 $args = self::getSafeMarkupUriArgs($uri, $options); |
54 $this->assertEquals($expected, SafeMarkup::format($string, $args)); | 56 $this->assertEquals($expected, new FormattableMarkup($string, $args)); |
55 } | 57 } |
56 | 58 |
57 /** | 59 /** |
58 * @return array | 60 * @return array |
59 */ | 61 */ |
111 public function testSafeMarkupUriWithExceptionUri($string, $uri) { | 113 public function testSafeMarkupUriWithExceptionUri($string, $uri) { |
112 // Should throw an \InvalidArgumentException, due to Uri::toString(). | 114 // Should throw an \InvalidArgumentException, due to Uri::toString(). |
113 $this->setExpectedException(\InvalidArgumentException::class); | 115 $this->setExpectedException(\InvalidArgumentException::class); |
114 $args = self::getSafeMarkupUriArgs($uri); | 116 $args = self::getSafeMarkupUriArgs($uri); |
115 | 117 |
116 SafeMarkup::format($string, $args); | 118 new FormattableMarkup($string, $args); |
117 } | 119 } |
118 | 120 |
119 /** | 121 /** |
120 * @return array | 122 * @return array |
121 */ | 123 */ |