Skip to content

Commit

Permalink
Fix deprecated methods in Drupal 8/9 is removed from Drupal 10 (#673)
Browse files Browse the repository at this point in the history
* Fix deprecated method which is removed from Drupal 10
  • Loading branch information
shishir-intelli authored Mar 28, 2022
1 parent 6057a42 commit f9177ad
Show file tree
Hide file tree
Showing 38 changed files with 169 additions and 125 deletions.
6 changes: 2 additions & 4 deletions .circleci/RoboFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -487,13 +487,11 @@ public function drupalVersion($drupalCoreVersion)
$config->require->{"drupal/core-recommended"} = '^8.9@stable';
$config->require->{"drupal/core-dev"} = '^8.9';

// We require Drupal drush and console for some tests.
$config->require->{"drupal/console"} = "~1.0";

default:
break;
}

// We require Drupal drush and console for some tests.
$config->require->{"drupal/console"} = "~1.0";
// Add rules for testing apigee_edge_actions.
$config->require->{"drupal/rules"} = "3.0.0-alpha7";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

use Drupal\apigee_edge_actions\Event\ApigeeEdgeActionsEventInterface;
use Drupal\Core\Logger\LoggerChannelInterface;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
Expand Down Expand Up @@ -50,7 +50,7 @@ public function __construct(LoggerChannelInterface $logger) {
/**
* Responds to rules events.
*
* @param \Symfony\Component\EventDispatcher\Event $event
* @param \Symfony\Contracts\EventDispatcher\Event $event
* The event object.
* @param string $event_name
* The event name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Logger\LoggerChannelInterface;
use Drupal\Core\Session\AccountInterface;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

Expand Down Expand Up @@ -121,7 +121,7 @@ public static function getSubscribedEvents() {
*
* @param string $rules_event_name
* The name of the rules event.
* @param \Symfony\Component\EventDispatcher\Event $event
* @param \Symfony\Contracts\EventDispatcher\Event $event
* The api credential event.
* @param array $api_products
* An array of api products.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ protected function saveAccessSettings(array $settings) {
}
}
$this->drupalLogin($this->users[self::USER_WITH_ADMIN_PERM]);
$this->drupalPostForm(Url::fromRoute('apigee_edge.settings.developer.api_product_access'), $post, 'Save configuration');
$this->drupalGet(Url::fromRoute('apigee_edge.settings.developer.api_product_access'));
$this->submitForm($post, 'Save configuration');
$this->drupalLogout();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Plugin\PluginBase;
use GuzzleHttp\Psr7;
use GuzzleHttp\Psr7\Utils;
use GuzzleHttp\TransferStats;
use Http\Message\Formatter;
use Psr\Http\Message\RequestInterface;
Expand Down Expand Up @@ -101,7 +101,7 @@ public function formatRequest(RequestInterface $request): string {
$body = preg_replace('/(.*mfa_token=)([^\&]+)(.*)/', '$1***mfa-token***$3', $body);
$body = preg_replace('/(.*username=)([^\&]+)(.*)/', '$1***username***$3', $body);
$body = preg_replace('/(.*password=)([^\&]+)(.*)/', '$1***password***$3', $body);
$request = $request->withBody(Psr7\stream_for($body));
$request = $request->withBody(Utils::streamFor($body));
}
}
if ($this->maskOrganization) {
Expand Down Expand Up @@ -139,7 +139,7 @@ public function formatResponse(ResponseInterface $response, RequestInterface $re
$value = $masks[$key];
}
});
$response = $response->withBody(Psr7\stream_for(json_encode((object) $json, JSON_PRETTY_PRINT)));
$response = $response->withBody(Utils::streamFor(json_encode((object) $json, JSON_PRETTY_PRINT)));
}

if ($request->getMethod() === 'POST' && $request->getUri()->getPath() === '/oauth/token') {
Expand All @@ -151,7 +151,7 @@ public function formatResponse(ResponseInterface $response, RequestInterface $re
if (isset($json['refresh_token'])) {
$json['refresh_token'] = '***refresh-token***';
}
$response = $response->withBody(Psr7\stream_for(json_encode((object) $json)));
$response = $response->withBody(Utils::streamFor(json_encode((object) $json)));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion modules/apigee_edge_teams/apigee_edge_teams.install
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function apigee_edge_teams_update_8702() {
];
/** @var \Drupal\Core\Config\StorageInterface $config_storage */
$config_storage = \Drupal::service('config.storage');
$module_path = drupal_get_path('module', 'apigee_edge_teams');
$module_path = \Drupal::service('extension.list.module')->getPath('apigee_edge_teams');
$source = new FileStorage("$module_path/config/install");
$new_team_settings = $source->read('apigee_edge_teams.team_settings');
$team_settings = $config_storage->read('apigee_edge_teams.team_settings');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
namespace Drupal\apigee_edge_teams\Event;

use Drupal\apigee_edge_teams\Entity\TeamInvitationInterface;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;

/**
* Defines the team_invitation event.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;

/**
Expand Down Expand Up @@ -87,10 +87,10 @@ public function __construct(ClassResolverInterface $class_resolver, RouteMatchIn
/**
* Display an error message on inactive team routes.
*
* @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
* @param \Symfony\Component\HttpKernel\Event\ResponseEvent $event
* The event to process.
*/
public function onRespond(FilterResponseEvent $event) {
public function onRespond(ResponseEvent $event) {
if ($this->currentUser->isAnonymous() || !in_array($this->routeMatch->getRouteName(), $this->getDisabledRoutes())) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
use Drupal\apigee_edge\Event\AppCredentialDeleteEvent;
use Drupal\apigee_edge\Event\AppCredentialGenerateEvent;
use Drupal\apigee_edge_teams\TeamMemberApiProductAccessHandlerInterface;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
Expand Down Expand Up @@ -67,7 +67,7 @@ public static function getSubscribedEvents() {
/**
* Clears API product entity access cache.
*
* @param \Symfony\Component\EventDispatcher\Event $event
* @param \Symfony\Contracts\EventDispatcher\Event $event
* Event that triggered this subscriber.
*/
public function clearApiProductCache(Event $event): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;

/**
Expand Down Expand Up @@ -94,10 +94,10 @@ public function __construct(AccountInterface $current_user, RouteMatchInterface
/**
* Display's a warning message if team's status is inactive.
*
* @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
* @param \Symfony\Component\HttpKernel\Event\ResponseEvent $event
* The event to process.
*/
public function onRespond(FilterResponseEvent $event) {
public function onRespond(ResponseEvent $event) {
// Anonymous user's does not have access to these routes.
if ($this->currentUser->isAuthenticated() && strpos($this->routeMatch->getRouteName(), 'entity.team_app.') === 0) {
// Team is available in most of the team app routes as a route parameter.
Expand Down
6 changes: 4 additions & 2 deletions modules/apigee_edge_teams/tests/src/Functional/AccessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,8 @@ protected function teamRoleAccessTest() {
// Create roles for every team membership level permission.
$this->drupalLogin($this->rootUser);
foreach (array_keys(self::TEAM_MEMBER_PERMISSION_MATRIX) as $permission) {
$this->drupalPostForm(Url::fromRoute('entity.team_role.add_form'), [
$this->drupalGet(Url::fromRoute('entity.team_role.add_form'));
$this->submitForm([
'label' => $permission,
'id' => $permission,
], 'Save');
Expand Down Expand Up @@ -677,7 +678,8 @@ protected function setTeamRolePermissionsOnUi(string $role_name, array $permissi
$permission_changes["{$role_name}[{$permission}]"] = in_array($permission, $permissions);
}

$this->drupalPostForm(Url::fromRoute('apigee_edge_teams.settings.team.permissions'), $permission_changes, 'Save permissions');
$this->drupalGet(Url::fromRoute('apigee_edge_teams.settings.team.permissions'));
$this->submitForm($permission_changes, 'Save permissions');
// Dump permission configuration to the HTML output.
$this->drupalGet(Url::fromRoute('apigee_edge_teams.settings.team.permissions'));
// Because changes made on the UI therefore _this_ instance of the team role
Expand Down
3 changes: 2 additions & 1 deletion modules/apigee_edge_teams/tests/src/Functional/UiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ protected function teamsWorkflowTest() {
]);

// Team members have access to every team app and membership operations.
$this->drupalPostForm(Url::fromRoute('apigee_edge_teams.settings.team.permissions'), [
$this->drupalGet(Url::fromRoute('apigee_edge_teams.settings.team.permissions'));
$this->submitForm([
'member[team_manage_members]' => TRUE,
'member[team_app_create]' => TRUE,
'member[team_app_update]' => TRUE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ public function testViewCacheExpiration() {
$entity_type_manager = $this->container->get('entity_type.manager');
$build = $entity_type_manager->getViewBuilder(static::ENTITY_TYPE)->view($this->entity);

static::assertEqual(900, $build['#cache']['max-age']);
static::assertEquals(900, $build['#cache']['max-age']);

// Update the cache setting.
$this->config('apigee_edge_teams.team_settings')
->set('cache_expiration', 0)
->save();

$build = $entity_type_manager->getViewBuilder(static::ENTITY_TYPE)->view($this->entity);
static::assertEqual(0, $build['#cache']['max-age']);
static::assertEquals(0, $build['#cache']['max-age']);
}

}
2 changes: 1 addition & 1 deletion src/Controller/DeveloperSyncController.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static function create(ContainerInterface $container) {
* Job tag.
*/
protected static function generateTag(string $type): string {
return "developer_sync_{$type}_" . user_password();
return "developer_sync_{$type}_" . \Drupal::service('password_generator')->generate();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Event/AbstractAppCredentialEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
namespace Drupal\apigee_edge\Event;

use Apigee\Edge\Api\Management\Entity\AppCredentialInterface;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;

/**
* Base class for app credential create, generate and add products events.
Expand Down
2 changes: 1 addition & 1 deletion src/Event/EdgeEntityFieldConfigListAlterEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

namespace Drupal\apigee_edge\Event;

use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;

/**
* Triggered when an Apigee Edge entity's field config UI gets built.
Expand Down
4 changes: 2 additions & 2 deletions src/EventSubscriber/ApiProductEntityAccessCacheReset.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
use Drupal\apigee_edge\Event\AppCredentialDeleteEvent;
use Drupal\apigee_edge\Event\AppCredentialGenerateEvent;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
Expand Down Expand Up @@ -71,7 +71,7 @@ public static function getSubscribedEvents() {
/**
* Clears API product entity access cache.
*
* @param \Symfony\Component\EventDispatcher\Event $event
* @param \Symfony\Contracts\EventDispatcher\Event $event
* Event that triggered this subscriber.
*/
public function clearApiProductCache(Event $event): void {
Expand Down
6 changes: 3 additions & 3 deletions src/EventSubscriber/DeveloperStatusWarningSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\Core\Url;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;

/**
Expand Down Expand Up @@ -92,10 +92,10 @@ public function __construct(AccountInterface $current_user, RouteMatchInterface
/**
* Display's a warning message if developer's status is inactive.
*
* @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
* @param \Symfony\Component\HttpKernel\Event\ResponseEvent $event
* The event to process.
*/
public function onRespond(FilterResponseEvent $event) {
public function onRespond(ResponseEvent $event) {
// Anonymous user's does not have access to these routes.
if ($this->currentUser->isAuthenticated() && strpos($this->routeMatch->getRouteName(), 'entity.developer_app.') === 0) {
$developer_storage = $this->entityTypeManager->getStorage('developer');
Expand Down
6 changes: 3 additions & 3 deletions src/EventSubscriber/EdgeExceptionSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ protected static function getPriority() {
/**
* Displays the Edge connection error page.
*
* @param \Symfony\Component\HttpKernel\Event\ExceptionEvent|\Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event
* @param \Symfony\Component\HttpKernel\Event\ExceptionEvent $event
* The exception event.
*/
public function onException($event) {
$exception = ($event instanceof ExceptionEvent) ? $event->getThrowable() : $event->getException();
public function onException(ExceptionEvent $event) {
$exception = $event->getThrowable();
if ($exception instanceof ApiException || $exception->getPrevious() instanceof ApiException) {
$context = Error::decodeException($exception);
$this->logger->critical('@message %function (line %line of %file). <pre>@backtrace_string</pre>', $context);
Expand Down
2 changes: 1 addition & 1 deletion src/UserDeveloperConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public function convertDeveloper(DeveloperInterface $developer) : DeveloperToUse
if (!$user) {
// Initialize new user object with minimum data.
$user = $user_storage->create([
'pass' => user_password(),
'pass' => \Drupal::service('password_generator')->generate(),
]);
// Suppress invalid email validation errors.
DeveloperEmailUniqueValidator::whitelist($developer->id());
Expand Down
8 changes: 4 additions & 4 deletions tests/src/Functional/DeveloperAppApiKeyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public function testAppApiKeyAddSingle() {
'product' => $this->apiProducts[0],
],
]);
$this->drupalPostForm(NULL, [
$this->submitForm([
'expiry' => 'date',
'expiry_date' => "07/20/2030",
], 'Confirm');
Expand Down Expand Up @@ -314,7 +314,7 @@ public function testAppApiKeyAddMultiple() {
'product' => $this->apiProducts[1],
],
]);
$this->drupalPostForm(NULL, [
$this->submitForm([
'expiry' => 'date',
'expiry_date' => "07/20/2030",
], 'Confirm');
Expand Down Expand Up @@ -359,7 +359,7 @@ public function testAppApiKeyRevoke() {
$this->stack->queueMockResponse('no_content');

$this->queueDeveloperAppResponse($this->developerApp, 200, $credentials);
$this->drupalPostForm(NULL, [], 'Revoke');
$this->submitForm([], 'Revoke');
$this->assertSession()->pageTextContains('API key ' . $this->consumer_key . ' revoked from ' . $this->developerApp->getName() . '.');

// Access denied for the only active key.
Expand Down Expand Up @@ -413,7 +413,7 @@ public function testAppApiKeyDelete() {
$this->queueDeveloperAppResponse($this->developerApp, 200, $credentials);
$this->queueDeveloperAppResponse($this->developerApp, 200, $credentials);
$this->stack->queueMockResponse('no_content');
$this->drupalPostForm(NULL, [], 'Delete');
$this->submitForm([], 'Delete');
$this->assertSession()->pageTextContains('API key ' . $this->consumer_key . ' deleted from ' . $this->developerApp->getName() . '.');

// Access denied for the only active key.
Expand Down
10 changes: 6 additions & 4 deletions tests/src/Functional/DeveloperAppFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -479,11 +479,11 @@ protected function credentialsViewTest() {
* Whether to expect success or a validation error.
*/
protected function submitBaseFieldConfigForm(bool $description_required = FALSE, bool $callback_url_required = FALSE, bool $expect_success = TRUE) {
$this->drupalPostForm(Url::fromRoute('entity.developer_app.field_ui_fields'), [
$this->drupalGet(Url::fromRoute('entity.developer_app.field_ui_fields'));
$this->submitForm([
'table[description][required]' => $description_required,
'table[callbackUrl][required]' => $callback_url_required,
], 'Save');

if ($expect_success) {
$this->assertSession()->pageTextContains('Field settings have been saved successfully.');
}
Expand All @@ -506,7 +506,8 @@ protected function submitFormDisplay(array $region_overrides = [], bool $expect_
foreach ($region_overrides as $field => $region) {
$edit["fields[{$field}][region]"] = $region;
}
$this->drupalPostForm(Url::fromRoute('entity.entity_form_display.developer_app.default'), $edit, 'Save');
$this->drupalGet(Url::fromRoute('entity.entity_form_display.developer_app.default'));
$this->submitForm($edit, 'Save');

if ($expect_success) {
$this->assertSession()->pageTextContains('Your settings have been saved.');
Expand All @@ -528,7 +529,8 @@ protected function submitViewDisplay(array $region_overrides = []) {
foreach ($region_overrides as $field => $region) {
$edit["fields[{$field}][region]"] = $region;
}
$this->drupalPostForm(Url::fromRoute('entity.entity_view_display.developer_app.default'), $edit, 'Save');
$this->drupalGet(Url::fromRoute('entity.entity_view_display.developer_app.default'));
$this->submitForm($edit, 'Save');

$this->assertSession()->pageTextContains('Your settings have been saved.');
}
Expand Down
Loading

0 comments on commit f9177ad

Please sign in to comment.