Skip to content
Snippets Groups Projects
Commit bc5dcaac authored by Richard Haeser's avatar Richard Haeser Committed by Jigal van Hemert
Browse files

[BUGFIX] Correctly define allowedSubProperties of TwitterCardMetaTagManager

The properties within the allowedSubProperties have to be arrays
because the AbstractMetaTagManager checks if the property as a key
exists in the allowSubProperties.

Resolves: #85126
Releases: master
Change-Id: Ie57a77f8d4100e0861958de73faa56d80709daad
Reviewed-on: https://review.typo3.org/57099


Tested-by: default avatarTYPO3com <no-reply@typo3.com>
Reviewed-by: default avatarMona Muzaffar <mona.muzaffar@gmx.de>
Tested-by: default avatarMona Muzaffar <mona.muzaffar@gmx.de>
Reviewed-by: default avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: default avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: default avatarJigal van Hemert <jigal.van.hemert@typo3.org>
Tested-by: default avatarJigal van Hemert <jigal.van.hemert@typo3.org>
parent 4fe45e4d
Branches
Tags
No related merge requests found
......@@ -27,39 +27,39 @@ class TwitterCardMetaTagManager extends AbstractMetaTagManager
'twitter:card' => [],
'twitter:site' => [
'allowedSubProperties' => [
'id',
'id' => [],
]
],
'twitter:creator' => [
'allowedSubProperties' => [
'id',
'id' => [],
]
],
'twitter:description' => [],
'twitter:title' => [],
'twitter:image' => [
'allowedSubProperties' => [
'alt',
'alt' => [],
]
],
'twitter:player' => [
'allowedSubProperties' => [
'width',
'height',
'stream',
'width' => [],
'height' => [],
'stream' => [],
]
],
'twitter:app' => [
'allowedSubProperties' => [
'name:iphone',
'id:iphone',
'url:iphone',
'name:ipad',
'id:ipad',
'url:ipad',
'name:googleplay',
'id:googleplay',
'url:googleplay',
'name:iphone' => [],
'id:iphone' => [],
'url:iphone' => [],
'name:ipad' => [],
'id:ipad' => [],
'url:ipad' => [],
'name:googleplay' => [],
'id:googleplay' => [],
'url:googleplay' => [],
]
],
];
......
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Core\Tests\Unit\MetaTag;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\MetaTag\TwitterCardMetaTagManager;
/**
* Test case
*/
class TwitterCardMetaTagManagerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
{
/**
* @test
*/
public function checkIfGetAllHandledPropertiesReturnsNonEmptyArray()
{
$manager = new TwitterCardMetaTagManager();
$handledProperties = $manager->getAllHandledProperties();
$this->assertNotEmpty($handledProperties);
}
/**
* @dataProvider propertiesProvider
*
* @test
*
* @param array $property
* @param array $expected
* @param string $expectedRenderedTag
*/
public function checkIfPropertyIsStoredAfterAddingProperty(array $property, array $expected, string $expectedRenderedTag)
{
$manager = new TwitterCardMetaTagManager();
$manager->addProperty(
$property['property'],
$property['content'],
(array)$property['subProperties']
);
$this->assertEquals($expected, $manager->getProperty($property['property']));
$this->assertEquals($expectedRenderedTag, $manager->renderProperty($property['property']));
}
/**
* @return array
*/
public function propertiesProvider()
{
return [
'title is set' => [
[
'property' => 'twitter:title',
'content' => 'Test title',
'subProperties' => []
],
[
[
'content' => 'Test title',
'subProperties' => []
]
],
'<meta name="twitter:title" content="Test title" />'
],
'image path is set' => [
[
'property' => 'twitter:image',
'content' => '/path/to/image',
'subProperties' => []
],
[
[
'content' => '/path/to/image',
'subProperties' => []
]
],
'<meta name="twitter:image" content="/path/to/image" />'
],
'remove not used subproperties' => [
[
'property' => 'twitter:image',
'content' => '/path/to/image',
'subProperties' => ['width' => [400], 'height' => [400]]
],
[
[
'content' => '/path/to/image',
'subProperties' => []
]
],
'<meta name="twitter:image" content="/path/to/image" />'
],
'set alt to twitter:image' => [
[
'property' => 'twitter:image',
'content' => '/path/to/image',
'subProperties' => ['alt' => ['Alternative title']]
],
[
[
'content' => '/path/to/image',
'subProperties' => [
'alt' => ['Alternative title']
]
]
],
'<meta name="twitter:image" content="/path/to/image" />' . PHP_EOL .
'<meta name="twitter:image:alt" content="Alternative title" />'
]
];
}
/**
* @test
*/
public function checkIfAddingOnlySubPropertyAndNoMainPropertyIsReturningException()
{
$manager = new TwitterCardMetaTagManager();
$this->expectException(\UnexpectedValueException::class);
$manager->addProperty('og:image:width', '400');
}
/**
* @test
*/
public function checkRenderAllPropertiesRendersCorrectMetaTags()
{
$properties = [
[
'property' => 'twitter:title',
'content' => 'This is a title',
'subProperties' => [],
'replace' => false,
'type' => ''
],
[
'property' => 'twitter:image',
'content' => '/path/to/image',
'subProperties' => [
'width' => 400
],
'replace' => false,
'type' => ''
],
[
'property' => 'twitter:title',
'content' => 'This is the new title',
'subProperties' => [],
'replace' => true,
'type' => ''
],
[
'property' => 'twitter:image',
'content' => '/path/to/image2',
'subProperties' => [],
'replace' => false,
'type' => ''
],
];
$manager = new TwitterCardMetaTagManager();
foreach ($properties as $property) {
$manager->addProperty(
$property['property'],
$property['content'],
$property['subProperties'],
$property['replace'],
$property['type']
);
}
$expected = '<meta name="twitter:image" content="/path/to/image" />' . PHP_EOL .
'<meta name="twitter:title" content="This is the new title" />';
$this->assertEquals($expected, $manager->renderAllProperties());
}
/**
* @test
*/
public function checkIfRemovePropertyReallyRemovesProperty()
{
$manager = new TwitterCardMetaTagManager();
$manager->addProperty('twitter:title', 'Title');
$this->assertEquals([['content' => 'Title', 'subProperties' => []]], $manager->getProperty('twitter:title'));
$manager->removeProperty('twitter:title');
$this->assertEquals([], $manager->getProperty('twitter:title'));
$manager->addProperty('twitter:title', 'Title');
$manager->addProperty('twitter:description', 'Description');
$manager->removeAllProperties();
$this->assertEquals([], $manager->getProperty('twitter:title'));
$this->assertEquals([], $manager->getProperty('twitter:description'));
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment