‪TYPO3CMS  11.5
OpenGraphMetaTagManagerTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
26 class ‪OpenGraphMetaTagManagerTest extends UnitTestCase
27 {
32  {
33  $manager = new ‪OpenGraphMetaTagManager();
34  $handledProperties = $manager->getAllHandledProperties();
35 
36  self::assertNotEmpty($handledProperties);
37  }
38 
44  public function ‪checkIfPropertyIsStoredAfterAddingProperty(array $property, array $expected, string $expectedRenderedTag): void
45  {
46  $manager = new ‪OpenGraphMetaTagManager();
47  $manager->addProperty(
48  $property['property'],
49  $property['content'],
50  (array)$property['subProperties']
51  );
52 
53  self::assertEquals($expected, $manager->getProperty($property['property']));
54  self::assertEquals($expectedRenderedTag, $manager->renderProperty($property['property']));
55  }
56 
61  {
62  $manager = new ‪OpenGraphMetaTagManager();
63 
64  $this->expectException(\UnexpectedValueException::class);
65  $manager->addProperty('og:image:width', '400');
66  }
67 
72  {
73  $properties = [
74  [
75  'property' => 'og:title',
76  'content' => 'This is a title',
77  'subProperties' => [],
78  'replace' => false,
79  'type' => '',
80  ],
81  [
82  'property' => 'og:image',
83  'content' => '/path/to/image',
84  'subProperties' => [
85  'width' => 400,
86  ],
87  'replace' => false,
88  'type' => '',
89  ],
90  [
91  'property' => 'og:image:height',
92  'content' => '200',
93  'subProperties' => [],
94  'replace' => false,
95  'type' => '',
96  ],
97  [
98  'property' => 'og:title',
99  'content' => 'This is the new title',
100  'subProperties' => [],
101  'replace' => true,
102  'type' => '',
103  ],
104  [
105  'property' => 'og:image',
106  'content' => '/path/to/image2',
107  'subProperties' => [],
108  'replace' => false,
109  'type' => '',
110  ],
111  ];
112 
113  $manager = new ‪OpenGraphMetaTagManager();
114  foreach ($properties as $property) {
115  $manager->addProperty(
116  $property['property'],
117  $property['content'],
118  $property['subProperties'],
119  $property['replace'],
120  $property['type']
121  );
122  }
123 
124  $expected = '<meta property="og:image" content="/path/to/image" />' . PHP_EOL .
125  '<meta property="og:image:width" content="400" />' . PHP_EOL .
126  '<meta property="og:image:height" content="200" />' . PHP_EOL .
127  '<meta property="og:image" content="/path/to/image2" />' . PHP_EOL .
128  '<meta property="og:title" content="This is the new title" />';
129 
130  self::assertEquals($expected, $manager->renderAllProperties());
131  }
132 
137  {
138  $manager = new ‪OpenGraphMetaTagManager();
139  $manager->addProperty('og:title', 'Title');
140  self::assertEquals([['content' => 'Title', 'subProperties' => []]], $manager->getProperty('og:title'));
141 
142  $manager->removeProperty('og:title');
143  self::assertEquals([], $manager->getProperty('og:title'));
144 
145  $manager->addProperty('og:title', 'Title');
146  $manager->addProperty('og:description', 'Description');
147 
148  $manager->removeAllProperties();
149 
150  self::assertEquals([], $manager->getProperty('og:title'));
151  self::assertEquals([], $manager->getProperty('og:description'));
152  }
153 
157  public function ‪propertiesProvider(): array
158  {
159  return [
160  [
161  [
162  'property' => 'og:title',
163  'content' => 'Test title',
164  'subProperties' => [],
165  ],
166  [
167  [
168  'content' => 'Test title',
169  'subProperties' => [],
170  ],
171  ],
172  '<meta property="og:title" content="Test title" />',
173  ],
174  [
175  [
176  'property' => 'og:image',
177  'content' => '/path/to/image',
178  'subProperties' => [],
179  ],
180  [
181  [
182  'content' => '/path/to/image',
183  'subProperties' => [],
184  ],
185  ],
186  '<meta property="og:image" content="/path/to/image" />',
187  ],
188  [
189  [
190  'property' => 'og:image',
191  'content' => '/path/to/image',
192  'subProperties' => ['width' => [400], 'height' => [400]],
193  ],
194  [
195  [
196  'content' => '/path/to/image',
197  'subProperties' => [
198  'width' => [400],
199  'height' => [400],
200  ],
201  ],
202  ],
203  '<meta property="og:image" content="/path/to/image" />' . PHP_EOL .
204  '<meta property="og:image:width" content="400" />' . PHP_EOL .
205  '<meta property="og:image:height" content="400" />',
206  ],
207  ];
208  }
209 }
‪TYPO3\CMS\Seo\Tests\Unit\MetaTag\OpenGraphMetaTagManagerTest\checkIfGetAllHandledPropertiesReturnsNonEmptyArray
‪checkIfGetAllHandledPropertiesReturnsNonEmptyArray()
Definition: OpenGraphMetaTagManagerTest.php:31
‪TYPO3\CMS\Seo\Tests\Unit\MetaTag\OpenGraphMetaTagManagerTest\propertiesProvider
‪array propertiesProvider()
Definition: OpenGraphMetaTagManagerTest.php:157
‪TYPO3\CMS\Seo\Tests\Unit\MetaTag\OpenGraphMetaTagManagerTest
Definition: OpenGraphMetaTagManagerTest.php:27
‪TYPO3\CMS\Seo\Tests\Unit\MetaTag\OpenGraphMetaTagManagerTest\checkIfAddingOnlySubPropertyAndNoMainPropertyIsReturningException
‪checkIfAddingOnlySubPropertyAndNoMainPropertyIsReturningException()
Definition: OpenGraphMetaTagManagerTest.php:60
‪TYPO3\CMS\Seo\Tests\Unit\MetaTag\OpenGraphMetaTagManagerTest\checkRenderAllPropertiesRendersCorrectMetaTags
‪checkRenderAllPropertiesRendersCorrectMetaTags()
Definition: OpenGraphMetaTagManagerTest.php:71
‪TYPO3\CMS\Seo\Tests\Unit\MetaTag\OpenGraphMetaTagManagerTest\checkIfRemovePropertyReallyRemovesProperty
‪checkIfRemovePropertyReallyRemovesProperty()
Definition: OpenGraphMetaTagManagerTest.php:136
‪TYPO3\CMS\Seo\Tests\Unit\MetaTag
Definition: OpenGraphMetaTagManagerTest.php:18
‪TYPO3\CMS\Seo\Tests\Unit\MetaTag\OpenGraphMetaTagManagerTest\checkIfPropertyIsStoredAfterAddingProperty
‪checkIfPropertyIsStoredAfterAddingProperty(array $property, array $expected, string $expectedRenderedTag)
Definition: OpenGraphMetaTagManagerTest.php:44
‪TYPO3\CMS\Seo\MetaTag\OpenGraphMetaTagManager
Definition: OpenGraphMetaTagManager.php:26