Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / metatag / tests / src / Kernel / MetatagManagerTest.php
1 <?php
2
3 namespace Drupal\Tests\metatag\Kernel;
4
5 use Drupal\KernelTests\KernelTestBase;
6
7 /**
8  * Test the Metatag Manager class.
9  *
10  * @group metatag
11  */
12 class MetatagManagerTest extends KernelTestBase {
13
14   /**
15    * {@inheritdoc}
16    */
17   public static $modules = [
18     'metatag',
19     'metatag_open_graph',
20   ];
21
22   /**
23    * Test the order of the meta tags as they are output.
24    */
25   public function testMetatagOrder() {
26     /** @var \Drupal\metatag\MetatagManager $metatag_manager */
27     $metatag_manager = \Drupal::service('metatag.manager');
28
29     $tags = $metatag_manager->generateElements([
30       'og_image_width' => 100,
31       'og_image_height' => 100,
32       'og_image_url' => 'http://www.example.com/example/foo.png',
33     ]);
34
35     $expected = [
36       '#attached' => [
37         'html_head' => [
38           [
39             [
40               '#tag' => 'meta',
41               '#attributes' => [
42                 'property' => 'og:image:url',
43                 'content' => 'http://www.example.com/example/foo.png',
44               ],
45             ],
46             'og_image_url_0',
47           ],
48           [
49             [
50               '#tag' => 'meta',
51               '#attributes' => [
52                 'property' => 'og:image:width',
53                 'content' => 100,
54               ],
55             ],
56             'og_image_width',
57           ],
58           [
59             [
60               '#tag' => 'meta',
61               '#attributes' => [
62                 'property' => 'og:image:height',
63                 'content' => 100,
64               ],
65             ],
66             'og_image_height',
67           ],
68         ],
69       ],
70     ];
71     $this->assertEquals($expected, $tags);
72   }
73
74   /**
75    * Tests metatags with multiple values return multiple metatags.
76    */
77   public function testMetatagMultiple() {
78     /** @var \Drupal\metatag\MetatagManager $metatag_manager */
79     $metatag_manager = \Drupal::service('metatag.manager');
80
81     $tags = $metatag_manager->generateElements([
82       'og_image_width' => 100,
83       'og_image_height' => 100,
84       'og_image_url' => 'http://www.example.com/example/foo.png, http://www.example.com/example/foo2.png',
85     ]);
86
87     $expected = [
88       '#attached' => [
89         'html_head' => [
90           [
91             [
92               '#tag' => 'meta',
93               '#attributes' => [
94                 'property' => 'og:image:url',
95                 'content' => 'http://www.example.com/example/foo.png',
96               ],
97             ],
98             'og_image_url_0',
99           ],
100           [
101             [
102               '#tag' => 'meta',
103               '#attributes' => [
104                 'property' => 'og:image:url',
105                 'content' => 'http://www.example.com/example/foo2.png',
106               ],
107             ],
108             'og_image_url_1',
109           ],
110           [
111             [
112               '#tag' => 'meta',
113               '#attributes' => [
114                 'property' => 'og:image:width',
115                 'content' => 100,
116               ],
117             ],
118             'og_image_width',
119           ],
120           [
121             [
122               '#tag' => 'meta',
123               '#attributes' => [
124                 'property' => 'og:image:height',
125                 'content' => 100,
126               ],
127             ],
128             'og_image_height',
129           ],
130         ],
131       ],
132     ];
133     $this->assertEquals($expected, $tags);
134   }
135
136 }