From 023ee2ffc0cc22b8fe1b36efb47b66e028b2b64c Mon Sep 17 00:00:00 2001 From: Brian Canini <canini.16@osu.edu> Date: Wed, 25 Mar 2020 12:11:57 -0400 Subject: [PATCH] Updating drupal/media_entity_twitter (2.0.0-alpha2 => 2.3.0) --- composer.json | 4 +- composer.lock | 31 +++++----- vendor/composer/installed.json | 28 +++++---- .../media_entity_twitter/js/twitter.js | 16 +++--- .../media_entity_twitter.info.yml | 13 ++--- .../media_entity_twitter.install | 8 ++- .../media_entity_twitter.libraries.yml | 1 - .../media_entity_twitter.post_update.php | 14 +++++ .../media_entity_twitter.services.yml | 10 ++-- .../TweetVisibleConstraintValidator.php | 12 +++- .../src/Plugin/media/Source/Twitter.php | 43 +++++++++++--- .../media_entity_twitter/src/TweetFetcher.php | 2 +- .../Functional/TweetEmbedFormatterTest.php | 57 ++++++++++--------- .../tests/src/Kernel/ThumbnailTest.php | 5 +- .../tests/src/Unit/ConstraintsTest.php | 12 ++-- 15 files changed, 161 insertions(+), 95 deletions(-) create mode 100644 web/modules/media_entity_twitter/media_entity_twitter.post_update.php diff --git a/composer.json b/composer.json index 1a392f6d64..765ba3a469 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.0-alpha2", + "drupal/media_entity_twitter": "2.3", "drupal/menu_block": "1.4", "drupal/menu_block_title": "1.1", "drupal/menu_breadcrumb": "1.12", @@ -318,4 +318,4 @@ "php": "7.0.8" } } -} \ No newline at end of file +} diff --git a/composer.lock b/composer.lock index fd58f43968..3cfa302ea5 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": "f3f9a51e6c09cc6554fa012dbf1ad64d", + "content-hash": "2a360f2c481e8fc30575fcbbbda15969", "packages": [ { "name": "alchemy/zippy", @@ -5711,17 +5711,17 @@ }, { "name": "drupal/media_entity_twitter", - "version": "2.0.0-alpha2", + "version": "2.3.0", "source": { "type": "git", "url": "https://git.drupalcode.org/project/media_entity_twitter.git", - "reference": "8.x-2.0-alpha2" + "reference": "8.x-2.3" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/media_entity_twitter-8.x-2.0-alpha2.zip", - "reference": "8.x-2.0-alpha2", - "shasum": "21925e1e1b02bbbcd6d8e9730bc587669edc0e5c" + "url": "https://ftp.drupal.org/files/projects/media_entity_twitter-8.x-2.3.zip", + "reference": "8.x-2.3", + "shasum": "de0f25deaa97e09c6851c09ee01c1e2f3f505f48" }, "require": { "drupal/core": "^8.4", @@ -5733,11 +5733,11 @@ "dev-2.x": "2.x-dev" }, "drupal": { - "version": "8.x-2.0-alpha2", - "datestamp": "1507907344", + "version": "8.x-2.3", + "datestamp": "1579597383", "security-coverage": { - "status": "not-covered", - "message": "Alpha releases are not covered by Drupal security advisories." + "status": "covered", + "message": "Covered by Drupal's security advisory policy" } } }, @@ -5758,15 +5758,19 @@ "name": "chr.fritsch", "homepage": "https://www.drupal.org/user/2103716" }, + { + "name": "phenaproxima", + "homepage": "https://www.drupal.org/user/205645" + }, { "name": "slashrsm", "homepage": "https://www.drupal.org/user/744628" } ], - "description": "Media entity Twitter provider.", + "description": "Media Entity Twitter provider.", "homepage": "https://www.drupal.org/project/media_entity_twitter", "support": { - "source": "http://cgit.drupalcode.org/media_entity_twitter" + "source": "https://git.drupalcode.org/project/media_entity_twitter" } }, { @@ -6064,8 +6068,7 @@ "homepage": "https://www.drupal.org/project/migrate_devel", "support": { "source": "http://cgit.drupalcode.org/migrate_devel" - }, - "time": "2017-06-25T23:46:13+00:00" + } }, { "name": "drupal/migrate_plus", diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 1dcf950ce4..26b557ccb4 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -5885,18 +5885,18 @@ }, { "name": "drupal/media_entity_twitter", - "version": "2.0.0-alpha2", - "version_normalized": "2.0.0.0-alpha2", + "version": "2.3.0", + "version_normalized": "2.3.0.0", "source": { "type": "git", "url": "https://git.drupalcode.org/project/media_entity_twitter.git", - "reference": "8.x-2.0-alpha2" + "reference": "8.x-2.3" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/media_entity_twitter-8.x-2.0-alpha2.zip", - "reference": "8.x-2.0-alpha2", - "shasum": "21925e1e1b02bbbcd6d8e9730bc587669edc0e5c" + "url": "https://ftp.drupal.org/files/projects/media_entity_twitter-8.x-2.3.zip", + "reference": "8.x-2.3", + "shasum": "de0f25deaa97e09c6851c09ee01c1e2f3f505f48" }, "require": { "drupal/core": "^8.4", @@ -5908,11 +5908,11 @@ "dev-2.x": "2.x-dev" }, "drupal": { - "version": "8.x-2.0-alpha2", - "datestamp": "1507907344", + "version": "8.x-2.3", + "datestamp": "1579597383", "security-coverage": { - "status": "not-covered", - "message": "Alpha releases are not covered by Drupal security advisories." + "status": "covered", + "message": "Covered by Drupal's security advisory policy" } } }, @@ -5934,15 +5934,19 @@ "name": "chr.fritsch", "homepage": "https://www.drupal.org/user/2103716" }, + { + "name": "phenaproxima", + "homepage": "https://www.drupal.org/user/205645" + }, { "name": "slashrsm", "homepage": "https://www.drupal.org/user/744628" } ], - "description": "Media entity Twitter provider.", + "description": "Media Entity Twitter provider.", "homepage": "https://www.drupal.org/project/media_entity_twitter", "support": { - "source": "http://cgit.drupalcode.org/media_entity_twitter" + "source": "https://git.drupalcode.org/project/media_entity_twitter" } }, { diff --git a/web/modules/media_entity_twitter/js/twitter.js b/web/modules/media_entity_twitter/js/twitter.js index 92297172c0..3734e0b9a2 100644 --- a/web/modules/media_entity_twitter/js/twitter.js +++ b/web/modules/media_entity_twitter/js/twitter.js @@ -2,24 +2,24 @@ * @file */ -(function ($, Drupal) { +(function (Drupal) { "use strict"; Drupal.behaviors.twitterMediaEntity = { attach: function (context) { - function _init () { - twttr.widgets.load(context); + function _init() { + twttr.widgets.load((context && context.nodeType === 1) ? context : null); } // If the tweet is being embedded in a CKEditor's iFrame the widgets // library might not have been loaded yet. if (typeof twttr == 'undefined') { - $.getScript('//platform.twitter.com/widgets.js', _init); - } - else { - _init(); + var script = document.createElement("script"); + script.src = '//platform.twitter.com/widgets.js'; + document.head.appendChild(script); } + _init(); } }; -})(jQuery, Drupal); +})(Drupal); 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 0fcd6afec4..718e5679d6 100644 --- a/web/modules/media_entity_twitter/media_entity_twitter.info.yml +++ b/web/modules/media_entity_twitter/media_entity_twitter.info.yml @@ -1,13 +1,12 @@ -name: Media entity Twitter -description: 'Media entity Twitter provider.' +name: Media Entity Twitter +description: 'Media Entity Twitter provider.' type: module package: Media -# core: 8.x +core: 8.x dependencies: - drupal:media (>= 8.4) -# Information added by Drupal.org packaging script on 2017-10-13 -version: '8.x-2.0-alpha2' -core: '8.x' +# Information added by Drupal.org packaging script on 2020-01-21 +version: '8.x-2.3' project: 'media_entity_twitter' -datestamp: 1507907346 +datestamp: 1579597387 diff --git a/web/modules/media_entity_twitter/media_entity_twitter.install b/web/modules/media_entity_twitter/media_entity_twitter.install index 50be0d8d93..daa65ab75b 100644 --- a/web/modules/media_entity_twitter/media_entity_twitter.install +++ b/web/modules/media_entity_twitter/media_entity_twitter.install @@ -5,13 +5,15 @@ * Install, uninstall and update hooks for Media entity Twitter module. */ +use Drupal\Core\File\FileSystemInterface; + /** * Implements hook_install(). */ function media_entity_twitter_install() { $source = drupal_get_path('module', 'media_entity_twitter') . '/images/icons'; $destination = \Drupal::config('media.settings')->get('icon_base_uri'); - file_prepare_directory($destination, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); + \Drupal::service('file_system')->prepareDirectory($destination, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS); $files = file_scan_directory($source, '/.*\.(svg|png|jpg|jpeg|gif)$/'); foreach ($files as $file) { @@ -22,7 +24,7 @@ function media_entity_twitter_install() { // referenced somewhere else. Since showing an error that it was not // possible to copy the files is also confusing, we silently do nothing. if (!file_exists($destination . DIRECTORY_SEPARATOR . $file->filename)) { - file_unmanaged_copy($file->uri, $destination, FILE_EXISTS_ERROR); + \Drupal::service('file_system')->copy($file->uri, $destination, FileSystemInterface::EXISTS_ERROR); } } } @@ -34,7 +36,7 @@ function media_entity_twitter_requirements($phase) { $requirements = []; if ($phase == 'install') { $destination = \Drupal::config('media.settings')->get('icon_base_uri'); - file_prepare_directory($destination, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); + \Drupal::service('file_system')->prepareDirectory($destination, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS); $is_writable = is_writable($destination); $is_directory = is_dir($destination); if (!$is_writable || !$is_directory) { diff --git a/web/modules/media_entity_twitter/media_entity_twitter.libraries.yml b/web/modules/media_entity_twitter/media_entity_twitter.libraries.yml index d22dc483c5..e55869159a 100644 --- a/web/modules/media_entity_twitter/media_entity_twitter.libraries.yml +++ b/web/modules/media_entity_twitter/media_entity_twitter.libraries.yml @@ -4,7 +4,6 @@ integration: 'js/twitter.js': {} dependencies: - core/drupal - - core/jquery - media_entity_twitter/twttr.widgets twttr.widgets: remote: //platform.twitter.com/widgets.js diff --git a/web/modules/media_entity_twitter/media_entity_twitter.post_update.php b/web/modules/media_entity_twitter/media_entity_twitter.post_update.php new file mode 100644 index 0000000000..d61cb74eda --- /dev/null +++ b/web/modules/media_entity_twitter/media_entity_twitter.post_update.php @@ -0,0 +1,14 @@ +<?php + +/** + * @file + * Post update functions for Media entity Twitter module. + */ + +/** + * Rename the cache bin. + */ +function media_entity_twitter_post_update_rename_cache_bin() { + // An empty update will force service definitions to be cleared and create a + // new bin with new name. +} diff --git a/web/modules/media_entity_twitter/media_entity_twitter.services.yml b/web/modules/media_entity_twitter/media_entity_twitter.services.yml index a520e35817..1072dfa0ab 100644 --- a/web/modules/media_entity_twitter/media_entity_twitter.services.yml +++ b/web/modules/media_entity_twitter/media_entity_twitter.services.yml @@ -1,13 +1,13 @@ services: media_entity_twitter.tweet_fetcher: - class: '\Drupal\media_entity_twitter\TweetFetcher' + class: Drupal\media_entity_twitter\TweetFetcher arguments: - - '@media_entity_twitter.cache.tweets' + - '@cache.tweets' - media_entity_twitter.cache.tweets: - class: '\Drupal\Core\Cache\CacheBackendInterface' + cache.tweets: + class: Drupal\Core\Cache\CacheBackendInterface tags: - - { name: cache.bin, default_backend: cache.backend.chainedfast } + - { name: cache.bin } factory: cache_factory:get arguments: - tweets 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 index ccf13fe127..81967dab07 100644 --- a/web/modules/media_entity_twitter/src/Plugin/Validation/Constraint/TweetVisibleConstraintValidator.php +++ b/web/modules/media_entity_twitter/src/Plugin/Validation/Constraint/TweetVisibleConstraintValidator.php @@ -3,9 +3,11 @@ 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; @@ -47,7 +49,7 @@ public function validate($value, Constraint $constraint) { if (is_string($value)) { $data = $value; } - elseif ($value instanceof FieldItemList) { + elseif ($value instanceof FieldItemListInterface) { $fieldtype = $value->getFieldDefinition()->getType(); $field_value = $value->getValue(); if ($fieldtype == 'link') { @@ -76,7 +78,13 @@ public function validate($value, Constraint $constraint) { } // Fetch content from the given url. - $response = $this->httpClient->get($matches[0][0], ['allow_redirects' => FALSE]); + 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]); 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 38fdf83324..a1d994039d 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 @@ -3,10 +3,13 @@ namespace Drupal\media_entity_twitter\Plugin\media\Source; use Drupal\Core\Config\ConfigFactoryInterface; +use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Core\Entity\EntityFieldManagerInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; +use Drupal\Core\File\FileSystemInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Logger\LoggerChannelInterface; +use Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface; use Drupal\Core\Render\RendererInterface; use Drupal\media\MediaInterface; use Drupal\media\MediaSourceBase; @@ -50,6 +53,13 @@ class Twitter extends MediaSourceBase implements MediaSourceFieldConstraintsInte */ protected $logger; + /** + * The file system service. + * + * @var \Drupal\Core\File\FileSystemInterface + */ + protected $fileSystem; + /** * {@inheritdoc} */ @@ -64,7 +74,8 @@ public static function create(ContainerInterface $container, array $configuratio $container->get('config.factory'), $container->get('renderer'), $container->get('media_entity_twitter.tweet_fetcher'), - $container->get('logger.factory')->get('media_entity_twitter') + $container->get('logger.factory')->get('media_entity_twitter'), + $container->get('file_system') ); } @@ -101,11 +112,12 @@ public static function create(ContainerInterface $container, array $configuratio * @param \Drupal\Core\Logger\LoggerChannelInterface $logger * The logger channel. */ - 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) { + 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); $this->renderer = $renderer; $this->tweetFetcher = $tweet_fetcher; $this->logger = $logger; + $this->fileSystem = $file_system; } /** @@ -140,6 +152,8 @@ public function getMetadataAttributes() { 'content' => $this->t('This tweet content'), 'retweet_count' => $this->t('Retweet count for this tweet'), 'profile_image_url_https' => $this->t('Link to profile image'), + 'created_time' => $this->t('Date/time created'), + 'user_name' => $this->t('User name'), ]; } @@ -193,7 +207,8 @@ public function getMetadata(MediaInterface $media, $attribute_name) { ]; $svg = $this->renderer->renderRoot($thumbnail); - return file_unmanaged_save_data($svg, $thumbnail_uri, FILE_EXISTS_ERROR) ?: parent::getMetadata($media, $attribute_name); + + return $this->fileSystem->saveData($svg, $thumbnail_uri, FileSystemInterface::EXISTS_ERROR) ?: parent::getMetadata($media, $attribute_name); } // If we have auth settings return the other fields. @@ -217,7 +232,7 @@ public function getMetadata(MediaInterface $media, $attribute_name) { // @TODO: Use Guzzle, possibly in a service, for this. $image_data = file_get_contents($image_url); if ($image_data) { - return file_unmanaged_save_data($image_data, $local_uri, FILE_EXISTS_REPLACE); + return $this->fileSystem->saveData($image_data, $local_uri, FileSystemInterface::EXISTS_REPLACE); } } } @@ -231,8 +246,8 @@ public function getMetadata(MediaInterface $media, $attribute_name) { return NULL; case 'content': - if (isset($tweet['text'])) { - return $tweet['text']; + if (isset($tweet['full_text'])) { + return $tweet['full_text']; } return NULL; @@ -248,6 +263,20 @@ public function getMetadata(MediaInterface $media, $attribute_name) { } return NULL; + case 'created_time': + if (isset($tweet['created_at'])) { + if ($datetime = DrupalDateTime::createFromFormat('D M d H:i:s O Y', $tweet['created_at'])) { + return $datetime->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT); + } + } + return NULL; + + case 'user_name': + if (isset($tweet['user']['name'])) { + return $tweet['user']['name']; + } + return NULL; + case 'default_name': $user = $this->getMetadata($media, 'user'); $id = $this->getMetadata($media, 'id'); @@ -380,7 +409,7 @@ protected function getLocalImageUri($id, MediaInterface $media, $media_url = NUL // Ensure that the destination directory is writable. If not, log a warning // and return the default thumbnail. - $ready = file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); + $ready = $this->fileSystem->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS); if (!$ready) { $this->logger->warning('Could not prepare thumbnail destination directory @dir', [ '@dir' => $directory, diff --git a/web/modules/media_entity_twitter/src/TweetFetcher.php b/web/modules/media_entity_twitter/src/TweetFetcher.php index 88b442bd7e..6c72f99a55 100644 --- a/web/modules/media_entity_twitter/src/TweetFetcher.php +++ b/web/modules/media_entity_twitter/src/TweetFetcher.php @@ -59,7 +59,7 @@ public function fetchTweet($id) { // Query Twitter's API. $response = $this->twitter - ->setGetfield('?id=' . $id) + ->setGetfield('?id=' . $id . '&tweet_mode=extended') ->buildOAuth('https://api.twitter.com/1.1/statuses/show.json', 'GET') ->performRequest(); 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 bfdeca2b6c..8470b3a36b 100644 --- a/web/modules/media_entity_twitter/tests/src/Functional/TweetEmbedFormatterTest.php +++ b/web/modules/media_entity_twitter/tests/src/Functional/TweetEmbedFormatterTest.php @@ -21,19 +21,12 @@ class TweetEmbedFormatterTest extends MediaFunctionalTestBase { 'link', ]; - /** - * {@inheritdoc} - */ - protected function setUp() { - parent::setUp(); - } - /** * Tests adding and editing a twitter embed formatter. */ public function testManageEmbedFormatter() { // Test and create one media type. - $bundle = $this->createMediaType(['bundle' => 'twitter'], 'twitter'); + $bundle = $this->createMediaType('twitter', ['id' => 'twitter']); // We need to fix widget and formatter config for the default field. $source = $bundle->getSource(); @@ -42,6 +35,13 @@ public function testManageEmbedFormatter() { $component = \Drupal::service('plugin.manager.field.widget') ->prepareConfiguration('string', []); + // Enable the conical URL. + \Drupal::configFactory() + ->getEditable('media.settings') + ->set('standalone_url', TRUE) + ->save(TRUE); + $this->container->get('router.builder')->rebuild(); + // @todo Replace entity_get_form_display() when #2367933 is done. // https://www.drupal.org/node/2872159. entity_get_form_display('media', $bundle->id(), 'default') @@ -50,8 +50,8 @@ public function testManageEmbedFormatter() { // Assert that the media type has the expected values before proceeding. $this->drupalGet('admin/structure/media/manage/' . $bundle->id()); - $this->assertFieldByName('label', $bundle->label()); - $this->assertFieldByName('source', 'twitter'); + $this->assertSession()->fieldValueEquals('label', $bundle->label()); + $this->assertSession()->fieldValueEquals('source', 'twitter'); // Add and save string_long field type settings (Embed code). $this->drupalGet('admin/structure/media/manage/' . $bundle->id() . '/fields/add-field'); @@ -61,33 +61,36 @@ public function testManageEmbedFormatter() { 'field_name' => 'embed_code', ]; $this->drupalPostForm(NULL, $edit_conf, t('Save and continue')); - $this->assertText('These settings apply to the ' . $edit_conf['label'] . ' field everywhere it is used.'); + $this->assertSession() + ->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->assertText('Updated field ' . $edit_conf['label'] . ' field settings.'); + $this->assertSession() + ->responseContains('Updated field <em class="placeholder">' . $edit_conf['label'] . '</em> field settings.'); // Set the new string_long field type as required. $edit = [ 'required' => TRUE, ]; $this->drupalPostForm(NULL, $edit, t('Save settings')); - $this->assertText('Saved ' . $edit_conf['label'] . ' configuration.'); + $this->assertSession() + ->responseContains('Saved <em class="placeholder">' . $edit_conf['label'] . '</em> configuration.'); // Assert that the new field types configurations have been successfully // saved. $this->drupalGet('admin/structure/media/manage/' . $bundle->id() . '/fields'); $xpath = $this->xpath('//*[@id=:id]/td', [':id' => 'field-media-twitter']); - $this->assertEqual((string) $xpath[0]->getText(), 'Tweet Url'); - $this->assertEqual((string) $xpath[1]->getText(), 'field_media_twitter'); - $this->assertEqual((string) $xpath[2]->find('css', 'a')->getText(), 'Text (plain)'); + $this->assertEquals((string) $xpath[0]->getText(), 'Tweet URL'); + $this->assertEquals((string) $xpath[1]->getText(), 'field_media_twitter'); + $this->assertEquals((string) $xpath[2]->find('css', 'a')->getText(), 'Text (plain)'); $xpath = $this->xpath('//*[@id=:id]/td', [':id' => 'field-embed-code']); - $this->assertEqual((string) $xpath[0]->getText(), 'Embed code'); - $this->assertEqual((string) $xpath[1]->getText(), 'field_embed_code'); - $this->assertEqual((string) $xpath[2]->find('css', 'a')->getText(), 'Text (plain, long)'); + $this->assertEquals((string) $xpath[0]->getText(), 'Embed code'); + $this->assertEquals((string) $xpath[1]->getText(), 'field_embed_code'); + $this->assertEquals((string) $xpath[2]->find('css', 'a')->getText(), 'Text (plain, long)'); $this->drupalGet('admin/structure/media/manage/' . $bundle->id() . '/display'); @@ -101,13 +104,13 @@ public function testManageEmbedFormatter() { 'fields[field_embed_code][type]' => 'twitter_embed', ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('Your settings have been saved.'); + $this->assertSession()->responseContains('Your settings have been saved.'); // Create and save the media with a twitter media code. $this->drupalGet('media/add/' . $bundle->id()); // Random image url from twitter. - $tweet_url = 'https://twitter.com/RamzyStinson/status/670650348319576064'; + $tweet_url = 'https://twitter.com/DrupalConEur/status/1176518741208817664'; // Random image from twitter. $tweet = '<blockquote class="twitter-tweet" lang="it"><p lang="en" dir="ltr">' . @@ -123,17 +126,19 @@ public function testManageEmbedFormatter() { 'field_embed_code[0][value]' => $tweet, ]; $this->drupalPostForm(NULL, $edit, t('Save')); + $this->drupalGet('media/1'); // Assert that the media has been successfully saved. - $this->assertText('Title'); + $this->assertSession()->pageTextContains('Title'); // Assert that the link url formatter exists on this page. - $this->assertText('Tweet Url'); - $this->assertRaw('<a href="https://twitter.com/RamzyStinson/statuses/670650348319576064">', 'Link in embedded Tweet found.'); + $this->assertSession()->pageTextContains('Tweet URL'); + $this->assertSession() + ->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->assertText('Embed code'); - $this->assertRaw('<blockquote class="twitter-tweet', 'Embedded Tweet found.'); + $this->assertSession()->pageTextContains('Embed code'); + $this->assertSession()->responseContains('<blockquote class="twitter-tweet', 'Embedded Tweet found.'); } } 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 a39cda295b..4c43d24c81 100644 --- a/web/modules/media_entity_twitter/tests/src/Kernel/ThumbnailTest.php +++ b/web/modules/media_entity_twitter/tests/src/Kernel/ThumbnailTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\media_entity_twitter\Kernel; +use Drupal\Core\File\FileSystemInterface; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; use Drupal\KernelTests\KernelTestBase; @@ -61,7 +62,7 @@ protected function setUp() { $this->installEntitySchema('media'); $this->installConfig(['media_entity_twitter', 'system']); - $this->tweetFetcher = $this->getMock(TweetFetcherInterface::class); + $this->tweetFetcher = $this->createMock(TweetFetcherInterface::class); $this->container->set('media_entity_twitter.tweet_fetcher', $this->tweetFetcher); MediaType::create([ @@ -106,7 +107,7 @@ protected function setUp() { ->get('media_entity_twitter.settings') ->get('local_images'); - file_prepare_directory($dir, FILE_CREATE_DIRECTORY | FILE_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 index fdbc1148ce..69e4a1bb0f 100644 --- a/web/modules/media_entity_twitter/tests/src/Unit/ConstraintsTest.php +++ b/web/modules/media_entity_twitter/tests/src/Unit/ConstraintsTest.php @@ -96,7 +96,7 @@ public function testTweetVisibleConstraint($embed_code, $mocked_response, $viola $constraint = new TweetVisibleConstraint(); $this->assertEquals('Referenced tweet is not publicly visible.', $constraint->message, 'Correct constraint message found.'); - $http_client = $this->getMock('\GuzzleHttp\Client'); + $http_client = $this->createMock('\GuzzleHttp\Client'); $http_client->expects($this->once()) ->method('__call') ->with('get', [$embed_code, ['allow_redirects' => FALSE]]) @@ -127,12 +127,12 @@ public function testTweetVisibleConstraint($embed_code, $mocked_response, $viola * Provides test data for testTweetVisibleConstraint(). */ public function visibleProvider() { - $visible_response = $this->getMock('\GuzzleHttp\Psr7\Response'); + $visible_response = $this->createMock('\GuzzleHttp\Psr7\Response'); $visible_response->expects($this->any()) ->method('getStatusCode') ->will($this->returnValue(200)); - $invisible_response = $this->getMock('\GuzzleHttp\Psr7\Response'); + $invisible_response = $this->createMock('\GuzzleHttp\Psr7\Response'); $invisible_response->expects($this->once()) ->method('getStatusCode') ->will($this->returnValue(302)); @@ -165,8 +165,10 @@ public function visibleProvider() { */ public function testBadUrlsOnVisibleConstraint($embed_code) { - $http_client = $this->getMock('\GuzzleHttp\Client'); - $http_client->expects($this->never())->method('get'); + $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() -- GitLab