diff --git a/composer.json b/composer.json index 149934362d320f0bf67f3eaed2f013a4ccead10e..82b6a2a20bf4a0ab390bf5f81feae5645feed865 100644 --- a/composer.json +++ b/composer.json @@ -136,7 +136,7 @@ "drupal/magnific_popup": "1.3", "drupal/mathjax": "2.7", "drupal/media_entity_browser": "2.0-alpha2", - "drupal/media_entity_twitter": "2.4", + "drupal/media_entity_twitter": "2.6", "drupal/menu_block": "1.4", "drupal/menu_block_title": "1.1", "drupal/menu_breadcrumb": "1.12", diff --git a/composer.lock b/composer.lock index 173b503248993f2dfaf7599a9360d7f9d6b68a90..3062e405b3734dde41fd169f83b513a105c531e9 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "4c1bdae7927770b326c330931383380c", + "content-hash": "08811f020bb1351a8fc7cb97c8e01682", "packages": [ { "name": "alchemy/zippy", @@ -1982,6 +1982,7 @@ "GPL-2.0-or-later" ], "description": "Composer Plugin for updating the Drupal scaffold files when using drupal/core", + "abandoned": "drupal/core-composer-scaffold", "time": "2018-07-27T10:07:07+00:00" }, { @@ -5711,17 +5712,17 @@ }, { "name": "drupal/media_entity_twitter", - "version": "2.4.0", + "version": "2.6.0", "source": { "type": "git", "url": "https://git.drupalcode.org/project/media_entity_twitter.git", - "reference": "8.x-2.4" + "reference": "8.x-2.6" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/media_entity_twitter-8.x-2.4.zip", - "reference": "8.x-2.4", - "shasum": "11bca09cc6dd678dc7585d16d66167a09c6e42fb" + "url": "https://ftp.drupal.org/files/projects/media_entity_twitter-8.x-2.6.zip", + "reference": "8.x-2.6", + "shasum": "777062eb55314da47ee3878db6d10d022e91bed6" }, "require": { "drupal/core": "^8.8 || ^9", @@ -5729,12 +5730,9 @@ }, "type": "drupal-module", "extra": { - "branch-alias": { - "dev-2.x": "2.x-dev" - }, "drupal": { - "version": "8.x-2.4", - "datestamp": "1585646747", + "version": "8.x-2.6", + "datestamp": "1610375564", "security-coverage": { "status": "covered", "message": "Covered by Drupal's security advisory policy" @@ -7747,13 +7745,10 @@ "shasum": "f959bec1332f2bd45e813eefa3b982df4eb129bb" }, "require": { - "drupal/core": "*" + "drupal/core": "^8" }, "type": "drupal-module", "extra": { - "branch-alias": { - "dev-3.x": "3.x-dev" - }, "drupal": { "version": "8.x-3.0-alpha0", "datestamp": "1489574283", @@ -7792,7 +7787,7 @@ "description": "Provides configurable blocks for a Twitter feed.", "homepage": "http://drupal.org/project/twitter_block", "support": { - "source": "http://cgit.drupalcode.org/twitter_block" + "source": "https://git.drupalcode.org/project/twitter_block" } }, { @@ -8783,12 +8778,12 @@ "version": "0.9.1", "source": { "type": "git", - "url": "https://github.com/njh/easyrdf.git", + "url": "https://github.com/easyrdf/easyrdf.git", "reference": "acd09dfe0555fbcfa254291e433c45fdd4652566" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/njh/easyrdf/zipball/acd09dfe0555fbcfa254291e433c45fdd4652566", + "url": "https://api.github.com/repos/easyrdf/easyrdf/zipball/acd09dfe0555fbcfa254291e433c45fdd4652566", "reference": "acd09dfe0555fbcfa254291e433c45fdd4652566", "shasum": "" }, @@ -12504,6 +12499,7 @@ "i18n", "text" ], + "abandoned": true, "time": "2018-12-05T18:34:18+00:00" }, { @@ -12664,12 +12660,12 @@ "version": "1.4.0", "source": { "type": "git", - "url": "https://github.com/webmozart/assert.git", + "url": "https://github.com/webmozarts/assert.git", "reference": "83e253c8e0be5b0257b881e1827274667c5c17a9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/83e253c8e0be5b0257b881e1827274667c5c17a9", + "url": "https://api.github.com/repos/webmozarts/assert/zipball/83e253c8e0be5b0257b881e1827274667c5c17a9", "reference": "83e253c8e0be5b0257b881e1827274667c5c17a9", "shasum": "" }, @@ -13079,5 +13075,6 @@ "platform-dev": [], "platform-overrides": { "php": "7.0.8" - } + }, + "plugin-api-version": "1.1.0" } diff --git a/vendor/composer/ClassLoader.php b/vendor/composer/ClassLoader.php index fce8549f0781bafdc7da2301b84d048286757445..03b9bb9c40cb86c2c2bbec2ce6ff0ddce9ad586c 100644 --- a/vendor/composer/ClassLoader.php +++ b/vendor/composer/ClassLoader.php @@ -60,7 +60,7 @@ class ClassLoader public function getPrefixes() { if (!empty($this->prefixesPsr0)) { - return call_user_func_array('array_merge', $this->prefixesPsr0); + return call_user_func_array('array_merge', array_values($this->prefixesPsr0)); } return array(); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index 126478a28269276956b4022aaedb7709a0e40256..fe8678ed14c292b8c03c7a03862bd1263f875bd8 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -13,6 +13,9 @@ public static function loadClassLoader($class) } } + /** + * @return \Composer\Autoload\ClassLoader + */ public static function getLoader() { if (null !== self::$loader) { diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index ac8938464ddad80c4ddbd015659edafefa6cd351..a3253321948461c6d25e5ce5430074908de23ec9 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -2043,7 +2043,8 @@ "license": [ "GPL-2.0-or-later" ], - "description": "Composer Plugin for updating the Drupal scaffold files when using drupal/core" + "description": "Composer Plugin for updating the Drupal scaffold files when using drupal/core", + "abandoned": "drupal/core-composer-scaffold" }, { "name": "drupal/address", @@ -5885,18 +5886,18 @@ }, { "name": "drupal/media_entity_twitter", - "version": "2.4.0", - "version_normalized": "2.4.0.0", + "version": "2.6.0", + "version_normalized": "2.6.0.0", "source": { "type": "git", "url": "https://git.drupalcode.org/project/media_entity_twitter.git", - "reference": "8.x-2.4" + "reference": "8.x-2.6" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/media_entity_twitter-8.x-2.4.zip", - "reference": "8.x-2.4", - "shasum": "11bca09cc6dd678dc7585d16d66167a09c6e42fb" + "url": "https://ftp.drupal.org/files/projects/media_entity_twitter-8.x-2.6.zip", + "reference": "8.x-2.6", + "shasum": "777062eb55314da47ee3878db6d10d022e91bed6" }, "require": { "drupal/core": "^8.8 || ^9", @@ -5904,12 +5905,9 @@ }, "type": "drupal-module", "extra": { - "branch-alias": { - "dev-2.x": "2.x-dev" - }, "drupal": { - "version": "8.x-2.4", - "datestamp": "1585646747", + "version": "8.x-2.6", + "datestamp": "1610375564", "security-coverage": { "status": "covered", "message": "Covered by Drupal's security advisory policy" @@ -7975,7 +7973,7 @@ { "name": "drupal/twitter_block", "version": "3.0.0-alpha0", - "version_normalized": "3.0.0.0-alpha", + "version_normalized": "3.0.0.0-alpha0", "source": { "type": "git", "url": "https://git.drupalcode.org/project/twitter_block.git", @@ -7988,13 +7986,10 @@ "shasum": "f959bec1332f2bd45e813eefa3b982df4eb129bb" }, "require": { - "drupal/core": "*" + "drupal/core": "^8" }, "type": "drupal-module", "extra": { - "branch-alias": { - "dev-3.x": "3.x-dev" - }, "drupal": { "version": "8.x-3.0-alpha0", "datestamp": "1489574283", @@ -8034,7 +8029,7 @@ "description": "Provides configurable blocks for a Twitter feed.", "homepage": "http://drupal.org/project/twitter_block", "support": { - "source": "http://cgit.drupalcode.org/twitter_block" + "source": "https://git.drupalcode.org/project/twitter_block" } }, { @@ -9056,12 +9051,12 @@ "version_normalized": "0.9.1.0", "source": { "type": "git", - "url": "https://github.com/njh/easyrdf.git", + "url": "https://github.com/easyrdf/easyrdf.git", "reference": "acd09dfe0555fbcfa254291e433c45fdd4652566" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/njh/easyrdf/zipball/acd09dfe0555fbcfa254291e433c45fdd4652566", + "url": "https://api.github.com/repos/easyrdf/easyrdf/zipball/acd09dfe0555fbcfa254291e433c45fdd4652566", "reference": "acd09dfe0555fbcfa254291e433c45fdd4652566", "shasum": "" }, @@ -12910,7 +12905,8 @@ "keywords": [ "i18n", "text" - ] + ], + "abandoned": true }, { "name": "twig/twig", @@ -13077,12 +13073,12 @@ "version_normalized": "1.4.0.0", "source": { "type": "git", - "url": "https://github.com/webmozart/assert.git", + "url": "https://github.com/webmozarts/assert.git", "reference": "83e253c8e0be5b0257b881e1827274667c5c17a9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/83e253c8e0be5b0257b881e1827274667c5c17a9", + "url": "https://api.github.com/repos/webmozarts/assert/zipball/83e253c8e0be5b0257b881e1827274667c5c17a9", "reference": "83e253c8e0be5b0257b881e1827274667c5c17a9", "shasum": "" }, diff --git a/web/modules/media_entity_twitter/media_entity_twitter.info.yml b/web/modules/media_entity_twitter/media_entity_twitter.info.yml index 0c97051226a80c0915b0e89329ddaabbba4d34a7..03aa469d411658a8a1911666a43a8c437fde586f 100644 --- a/web/modules/media_entity_twitter/media_entity_twitter.info.yml +++ b/web/modules/media_entity_twitter/media_entity_twitter.info.yml @@ -6,7 +6,7 @@ core_version_requirement: ^8.8 || ^9 dependencies: - drupal:media -# Information added by Drupal.org packaging script on 2020-03-31 -version: '8.x-2.4' +# Information added by Drupal.org packaging script on 2021-01-11 +version: '8.x-2.6' project: 'media_entity_twitter' -datestamp: 1585646749 +datestamp: 1610375567 diff --git a/web/modules/media_entity_twitter/src/Plugin/Validation/Constraint/TweetEmbedCodeConstraint.php b/web/modules/media_entity_twitter/src/Plugin/Validation/Constraint/TweetEmbedCodeConstraint.php deleted file mode 100644 index 28aca9571f63f2a894a0035fbc440952fe3a371e..0000000000000000000000000000000000000000 --- a/web/modules/media_entity_twitter/src/Plugin/Validation/Constraint/TweetEmbedCodeConstraint.php +++ /dev/null @@ -1,25 +0,0 @@ -<?php - -namespace Drupal\media_entity_twitter\Plugin\Validation\Constraint; - -use Symfony\Component\Validator\Constraint; - -/** - * Checks if a value is a valid Tweet embed code/URL. - * - * @Constraint( - * id = "TweetEmbedCode", - * label = @Translation("Tweet embed code", context = "Validation"), - * type = { "link", "string", "string_long" } - * ) - */ -class TweetEmbedCodeConstraint extends Constraint { - - /** - * The default violation message. - * - * @var string - */ - public $message = 'Not valid Tweet URL/embed code.'; - -} diff --git a/web/modules/media_entity_twitter/src/Plugin/Validation/Constraint/TweetEmbedCodeConstraintValidator.php b/web/modules/media_entity_twitter/src/Plugin/Validation/Constraint/TweetEmbedCodeConstraintValidator.php deleted file mode 100644 index 699a819416639accfb0f82221d05e101bb512620..0000000000000000000000000000000000000000 --- a/web/modules/media_entity_twitter/src/Plugin/Validation/Constraint/TweetEmbedCodeConstraintValidator.php +++ /dev/null @@ -1,54 +0,0 @@ -<?php - -namespace Drupal\media_entity_twitter\Plugin\Validation\Constraint; - -use Drupal\media_entity_twitter\Plugin\media\Source\Twitter; -use Drupal\Core\Field\FieldItemList; -use Drupal\Core\Field\FieldItemInterface; -use Symfony\Component\Validator\Constraint; -use Symfony\Component\Validator\ConstraintValidator; - -/** - * Validates the TweetEmbedCode constraint. - */ -class TweetEmbedCodeConstraintValidator extends ConstraintValidator { - - /** - * {@inheritdoc} - */ - public function validate($value, Constraint $constraint) { - $data = ''; - if (is_string($value)) { - $data = $value; - } - elseif ($value instanceof FieldItemList) { - $fieldtype = $value->getFieldDefinition()->getType(); - $field_value = $value->getValue(); - if ($fieldtype == 'link') { - $data = empty($field_value[0]['uri']) ? "" : $field_value[0]['uri']; - } - else { - $data = empty($field_value[0]['value']) ? "" : $field_value[0]['value']; - } - } - elseif ($value instanceof FieldItemInterface) { - $class = get_class($value); - $property = $class::mainPropertyName(); - if ($property) { - $data = $value->{$property}; - } - } - if ($data) { - $matches = []; - foreach (Twitter::$validationRegexp as $pattern => $key) { - if (preg_match($pattern, $data, $item_matches)) { - $matches[] = $item_matches; - } - } - if (empty($matches)) { - $this->context->addViolation($constraint->message); - } - } - } - -} diff --git a/web/modules/media_entity_twitter/src/Plugin/Validation/Constraint/TweetVisibleConstraint.php b/web/modules/media_entity_twitter/src/Plugin/Validation/Constraint/TweetVisibleConstraint.php deleted file mode 100644 index 2a16846a9d461d013d885d228336fbbce7b161eb..0000000000000000000000000000000000000000 --- a/web/modules/media_entity_twitter/src/Plugin/Validation/Constraint/TweetVisibleConstraint.php +++ /dev/null @@ -1,25 +0,0 @@ -<?php - -namespace Drupal\media_entity_twitter\Plugin\Validation\Constraint; - -use Symfony\Component\Validator\Constraint; - -/** - * Checks if a Tweet is publicly visible. - * - * @Constraint( - * id = "TweetVisible", - * label = @Translation("Tweet publicly visible", context = "Validation"), - * type = { "entity", "entity_reference", "string", "string_long" } - * ) - */ -class TweetVisibleConstraint extends Constraint { - - /** - * The default violation message. - * - * @var string - */ - public $message = 'Referenced tweet is not publicly visible.'; - -} diff --git a/web/modules/media_entity_twitter/src/Plugin/Validation/Constraint/TweetVisibleConstraintValidator.php b/web/modules/media_entity_twitter/src/Plugin/Validation/Constraint/TweetVisibleConstraintValidator.php deleted file mode 100644 index 81967dab07e16aee442b0743cb16c62a3d90904d..0000000000000000000000000000000000000000 --- a/web/modules/media_entity_twitter/src/Plugin/Validation/Constraint/TweetVisibleConstraintValidator.php +++ /dev/null @@ -1,97 +0,0 @@ -<?php - -namespace Drupal\media_entity_twitter\Plugin\Validation\Constraint; - -use Drupal\Core\DependencyInjection\ContainerInjectionInterface; -use Drupal\Core\Field\FieldItemListInterface; -use Drupal\media_entity_twitter\Plugin\media\Source\Twitter; -use Drupal\Core\Field\FieldItemInterface; -use GuzzleHttp\Client; -use GuzzleHttp\Exception\ClientException; -use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\Validator\Constraint; -use Symfony\Component\Validator\ConstraintValidator; - -/** - * Validates the TweetVisible constraint. - */ -class TweetVisibleConstraintValidator extends ConstraintValidator implements ContainerInjectionInterface { - - /** - * The HTTP client to fetch the feed data with. - * - * @var \GuzzleHttp\Client - */ - protected $httpClient; - - /** - * Constructs a new TweetVisibleConstraintValidator. - * - * @param \GuzzleHttp\Client $http_client - * The http client service. - */ - public function __construct(Client $http_client) { - $this->httpClient = $http_client; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static($container->get('http_client')); - } - - /** - * {@inheritdoc} - */ - public function validate($value, Constraint $constraint) { - $data = ''; - if (is_string($value)) { - $data = $value; - } - elseif ($value instanceof FieldItemListInterface) { - $fieldtype = $value->getFieldDefinition()->getType(); - $field_value = $value->getValue(); - if ($fieldtype == 'link') { - $data = empty($field_value[0]['uri']) ? "" : $field_value[0]['uri']; - } - else { - $data = empty($field_value[0]['value']) ? "" : $field_value[0]['value']; - } - } - elseif ($value instanceof FieldItemInterface) { - $class = get_class($value); - $property = $class::mainPropertyName(); - if ($property) { - $data = $value->{$property}; - } - } - foreach (Twitter::$validationRegexp as $pattern => $key) { - if (preg_match($pattern, $data, $item_matches)) { - $matches[] = $item_matches; - } - } - - if (empty($matches[0][0])) { - // If there are no matches the URL is not correct, so stop validation. - return; - } - - // Fetch content from the given url. - try { - $response = $this->httpClient->get($matches[0][0], ['allow_redirects' => FALSE]); - } - catch (ClientException $e) { - $this->context->addViolation($constraint->message); - return; - } - - if ($response->getStatusCode() == 302 && ($location = $response->getHeader('location'))) { - $effective_url_parts = parse_url($location[0]); - if (!empty($effective_url_parts) && isset($effective_url_parts['query']) && $effective_url_parts['query'] == 'protected_redirect=true') { - $this->context->addViolation($constraint->message); - } - } - } - -} diff --git a/web/modules/media_entity_twitter/src/Plugin/media/Source/Twitter.php b/web/modules/media_entity_twitter/src/Plugin/media/Source/Twitter.php index 72018dfee2a72d58c9117bedeb96ce3b35bbb6b6..22abcfeac576bbcb96582ec7aac2cc10777af7d0 100644 --- a/web/modules/media_entity_twitter/src/Plugin/media/Source/Twitter.php +++ b/web/modules/media_entity_twitter/src/Plugin/media/Source/Twitter.php @@ -14,6 +14,7 @@ use Drupal\media\MediaInterface; use Drupal\media\MediaSourceBase; use Drupal\media\MediaTypeInterface; +use Drupal\media\Plugin\media\Source\OEmbedInterface; use Drupal\media_entity_twitter\TweetFetcherInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\Field\FieldTypePluginManagerInterface; @@ -33,7 +34,7 @@ * } * ) */ -class Twitter extends MediaSourceBase implements MediaSourceFieldConstraintsInterface { +class Twitter extends MediaSourceBase implements MediaSourceFieldConstraintsInterface, OEmbedInterface { /** * The renderer. @@ -114,6 +115,8 @@ public static function create(ContainerInterface $container, array $configuratio * The tweet fetcher. * @param \Drupal\Core\Logger\LoggerChannelInterface $logger * The logger channel. + * @param \Drupal\Core\File\FileSystemInterface $file_system + * The file system. */ public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, EntityFieldManagerInterface $entity_field_manager, FieldTypePluginManagerInterface $field_type_manager, ConfigFactoryInterface $config_factory, RendererInterface $renderer, TweetFetcherInterface $tweet_fetcher, LoggerChannelInterface $logger, FileSystemInterface $file_system) { parent::__construct($configuration, $plugin_id, $plugin_definition, $entity_type_manager, $entity_field_manager, $field_type_manager, $config_factory); @@ -210,7 +213,6 @@ public function getMetadata(MediaInterface $media, $attribute_name) { ]; $svg = $this->renderer->renderRoot($thumbnail); - return $this->fileSystem->saveData($svg, $thumbnail_uri, FileSystemInterface::EXISTS_ERROR) ?: parent::getMetadata($media, $attribute_name); } @@ -379,8 +381,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta */ public function getSourceFieldConstraints() { return [ - 'TweetEmbedCode' => [], - 'TweetVisible' => [], + 'oembed_resource' => [], ]; } @@ -448,7 +449,7 @@ protected function matchRegexp(MediaInterface $media) { $matches = []; $source_field = $this->getSourceFieldDefinition($media->bundle->entity)->getName(); - if ($media->hasField($source_field)) { + if ($media->hasField($source_field) && !$media->get($source_field)->isEmpty()) { $property_name = $media->get($source_field)->first()->mainPropertyName(); foreach (static::$validationRegexp as $pattern => $key) { if (preg_match($pattern, $media->get($source_field)->{$property_name}, $matches)) { @@ -480,4 +481,11 @@ protected function fetchTweet($id) { return $this->tweetFetcher->fetchTweet($id); } + /** + * {@inheritdoc} + */ + public function getProviders() { + return ['Twitter']; + } + } diff --git a/web/modules/media_entity_twitter/tests/src/Functional/TweetEmbedFormatterTest.php b/web/modules/media_entity_twitter/tests/src/Functional/TweetEmbedFormatterTest.php index 2df19dca8c51235ca5050b61838105d4c0496f4d..e928db8dcd55591de5d214e7c47b3655cb7efadb 100644 --- a/web/modules/media_entity_twitter/tests/src/Functional/TweetEmbedFormatterTest.php +++ b/web/modules/media_entity_twitter/tests/src/Functional/TweetEmbedFormatterTest.php @@ -67,14 +67,14 @@ public function testManageEmbedFormatter() { ]; $this->drupalPostForm(NULL, $edit_conf, t('Save and continue')); $this->assertSession() - ->responseContains('These settings apply to the <em class="placeholder">' . $edit_conf['label'] . '</em> field everywhere it is used.'); + ->responseContains('These settings apply to the <em class="placeholder">' . $edit_conf['label'] . '</em> field everywhere it is used.'); $edit = [ 'cardinality' => 'number', 'cardinality_number' => '1', ]; $this->drupalPostForm(NULL, $edit, t('Save field settings')); $this->assertSession() - ->responseContains('Updated field <em class="placeholder">' . $edit_conf['label'] . '</em> field settings.'); + ->responseContains('Updated field <em class="placeholder">' . $edit_conf['label'] . '</em> field settings.'); // Set the new string_long field type as required. $edit = [ @@ -82,7 +82,7 @@ public function testManageEmbedFormatter() { ]; $this->drupalPostForm(NULL, $edit, t('Save settings')); $this->assertSession() - ->responseContains('Saved <em class="placeholder">' . $edit_conf['label'] . '</em> configuration.'); + ->responseContains('Saved <em class="placeholder">' . $edit_conf['label'] . '</em> configuration.'); // Assert that the new field types configurations have been successfully // saved. @@ -139,7 +139,7 @@ public function testManageEmbedFormatter() { // Assert that the link url formatter exists on this page. $this->assertSession()->pageTextContains('Tweet URL'); $this->assertSession() - ->responseContains('<a href="https://twitter.com/RamzyStinson/statuses/670650348319576064">', 'Link in embedded Tweet found.'); + ->responseContains('<a href="https://twitter.com/RamzyStinson/statuses/670650348319576064">', 'Link in embedded Tweet found.'); // Assert that the string_long code formatter exists on this page. $this->assertSession()->pageTextContains('Embed code'); diff --git a/web/modules/media_entity_twitter/tests/src/Kernel/ThumbnailTest.php b/web/modules/media_entity_twitter/tests/src/Kernel/ThumbnailTest.php index 4c43d24c816980b5e9db62234a46c6837ff1075d..1c0d4b66831f17782f7962aece3b3a99cd2672df 100644 --- a/web/modules/media_entity_twitter/tests/src/Kernel/ThumbnailTest.php +++ b/web/modules/media_entity_twitter/tests/src/Kernel/ThumbnailTest.php @@ -107,7 +107,7 @@ protected function setUp() { ->get('media_entity_twitter.settings') ->get('local_images'); - \Drupal::service('file_system')->prepareDirectory($dir, FileSystemInterface::CREATE_DIRECTORY| FileSystemInterface::MODIFY_PERMISSIONS); + \Drupal::service('file_system')->prepareDirectory($dir, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS); } /** diff --git a/web/modules/media_entity_twitter/tests/src/Unit/ConstraintsTest.php b/web/modules/media_entity_twitter/tests/src/Unit/ConstraintsTest.php deleted file mode 100644 index 69e4a1bb0f641ec187b72a584615b4c626625720..0000000000000000000000000000000000000000 --- a/web/modules/media_entity_twitter/tests/src/Unit/ConstraintsTest.php +++ /dev/null @@ -1,198 +0,0 @@ -<?php - -namespace Drupal\Tests\media_entity_twitter\Unit; - -use Drupal\Core\Field\Plugin\Field\FieldType\StringLongItem; -use Drupal\Core\TypedData\ComplexDataDefinitionInterface; -use Drupal\media_entity_twitter\Plugin\Validation\Constraint\TweetEmbedCodeConstraint; -use Drupal\media_entity_twitter\Plugin\Validation\Constraint\TweetEmbedCodeConstraintValidator; -use Drupal\media_entity_twitter\Plugin\Validation\Constraint\TweetVisibleConstraint; -use Drupal\media_entity_twitter\Plugin\Validation\Constraint\TweetVisibleConstraintValidator; -use Drupal\Tests\UnitTestCase; - -/** - * Tests media_entity_twitter constraints. - * - * @group media_entity - */ -class ConstraintsTest extends UnitTestCase { - - /** - * Creates a string_long FieldItemInterface wrapper around a value. - * - * @param string $value - * The wrapped value. - * - * @return \Drupal\Core\Field\FieldItemInterface - * Mocked string field item. - */ - protected function getMockFieldItem($value) { - $definition = $this->prophesize(ComplexDataDefinitionInterface::class); - $definition->getPropertyDefinitions()->willReturn([]); - - $item = new StringLongItem($definition->reveal()); - $item->set('value', $value); - - return $item; - } - - /** - * Tests TweetEmbedCode constraint. - * - * @covers \Drupal\media_entity_twitter\Plugin\Validation\Constraint\TweetEmbedCodeConstraintValidator - * @covers \Drupal\media_entity_twitter\Plugin\Validation\Constraint\TweetEmbedCodeConstraint - * - * @dataProvider embedCodeProvider - */ - public function testTweetEmbedCodeConstraint($embed_code, $expected_violation_count) { - // Check message in constraint. - $constraint = new TweetEmbedCodeConstraint(); - $this->assertEquals('Not valid Tweet URL/embed code.', $constraint->message, 'Correct constraint message found.'); - - $execution_context = $this->getMockBuilder('\Drupal\Core\TypedData\Validation\ExecutionContext') - ->disableOriginalConstructor() - ->getMock(); - - if ($expected_violation_count) { - $execution_context->expects($this->exactly($expected_violation_count)) - ->method('addViolation') - ->with($constraint->message); - } - else { - $execution_context->expects($this->exactly($expected_violation_count)) - ->method('addViolation'); - } - - $validator = new TweetEmbedCodeConstraintValidator(); - $validator->initialize($execution_context); - - $validator->validate($this->getMockFieldItem($embed_code), $constraint); - } - - /** - * Provides test data for testTweetEmbedCodeConstraint(). - */ - public function embedCodeProvider() { - return [ - 'valid tweet URL' => ['https://twitter.com/drupal8changes/status/649167396230578176', 0], - 'valid tweet embed code' => ['<blockquote class="twitter-tweet" lang="en"><p lang="en" dir="ltr">EntityChangedInterface now also defines the function setChangedTime <a href="http://t.co/1Q58UcR8OY">http://t.co/1Q58UcR8OY</a></p>— Drupal 8 Changes (@drupal8changes) <a href="https://twitter.com/drupal8changes/status/649167396230578176">September 30, 2015</a></blockquote><script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>', 0], - 'invalid URL' => ['https://drupal.org/project/media_entity_twitter', 1], - 'invalid text' => ['I want my Tweet!', 1], - 'invalid tweet URL' => ['https://twitter.com/drupal8changes/statustypo/649167396230578176', 1], - 'invalid tweet ID' => ['https://twitter.com/drupal8changes/status/aa64916739bb6230578176', 1], - ]; - } - - /** - * Tests TweetVisible constraint. - * - * @covers \Drupal\media_entity_twitter\Plugin\Validation\Constraint\TweetVisibleConstraintValidator - * @covers \Drupal\media_entity_twitter\Plugin\Validation\Constraint\TweetVisibleConstraint - * - * @dataProvider visibleProvider - */ - public function testTweetVisibleConstraint($embed_code, $mocked_response, $violations) { - // Check message in constraint. - $constraint = new TweetVisibleConstraint(); - $this->assertEquals('Referenced tweet is not publicly visible.', $constraint->message, 'Correct constraint message found.'); - - $http_client = $this->createMock('\GuzzleHttp\Client'); - $http_client->expects($this->once()) - ->method('__call') - ->with('get', [$embed_code, ['allow_redirects' => FALSE]]) - ->willReturn($mocked_response); - - // Make sure no violations are raised for visible tweet. - $execution_context = $this->getMockBuilder('\Drupal\Core\TypedData\Validation\ExecutionContext') - ->disableOriginalConstructor() - ->getMock(); - - if ($violations) { - $execution_context->expects($this->once()) - ->method('addViolation') - ->with($constraint->message); - } - else { - $execution_context->expects($this->exactly($violations)) - ->method('addViolation'); - } - - $validator = new TweetVisibleConstraintValidator($http_client); - $validator->initialize($execution_context); - - $validator->validate($this->getMockFieldItem($embed_code), $constraint); - } - - /** - * Provides test data for testTweetVisibleConstraint(). - */ - public function visibleProvider() { - $visible_response = $this->createMock('\GuzzleHttp\Psr7\Response'); - $visible_response->expects($this->any()) - ->method('getStatusCode') - ->will($this->returnValue(200)); - - $invisible_response = $this->createMock('\GuzzleHttp\Psr7\Response'); - $invisible_response->expects($this->once()) - ->method('getStatusCode') - ->will($this->returnValue(302)); - $invisible_response->expects($this->once()) - ->method('getHeader') - ->with('location') - ->will($this->returnValue(['https://twitter.com/drupal8changes?protected_redirect=true'])); - - return [ - 'valid URL' => [ - 'https://twitter.com/drupal8changes/status/649167396230578176', - $visible_response, - 0, - ], - 'invalid URL' => [ - 'https://twitter.com/drupal8changes/status/649637310024273920', - $invisible_response, - 1, - ], - ]; - } - - /** - * Tests whether the TweetVisible constraint is robust against bad URLs. - * - * @covers \Drupal\media_entity_twitter\Plugin\Validation\Constraint\TweetVisibleConstraintValidator - * @covers \Drupal\media_entity_twitter\Plugin\Validation\Constraint\TweetVisibleConstraint - * - * @dataProvider badUrlsProvider - */ - public function testBadUrlsOnVisibleConstraint($embed_code) { - - $http_client = $this->createMock('\GuzzleHttp\Client'); - $http_client->expects($this->never()) - ->method('__call') - ->with('get', [$embed_code, ['allow_redirects' => FALSE]]); - - $execution_context = $this->getMockBuilder('\Drupal\Core\TypedData\Validation\ExecutionContext') - ->disableOriginalConstructor() - ->getMock(); - - $validator = new TweetVisibleConstraintValidator($http_client); - $validator->initialize($execution_context); - - $constraint = new TweetVisibleConstraint(); - $validator->validate($this->getMockFieldItem($embed_code), $constraint); - } - - /** - * Provides test data for testBadUrlsOnVisibleConstraint(). - */ - public function badUrlsProvider() { - - return [ - ['https://google.com'], - ['https://twitter.com/drupal/ssstatus/725771037837762561'], - ['https://twitter.com/drupal/status'], - ['https://twitter.com/drupal/status/foo'], - ]; - - } - -}