From 1b045d389a1bf8ccff0bade61fd1db237edeb1a4 Mon Sep 17 00:00:00 2001 From: Lucas Hedding <24691-lucashedding@users.noreply.drupalcode.org> Date: Fri, 4 Aug 2023 08:57:33 -0600 Subject: [PATCH] Issue #3332499 by heddn, arpeggio: Prepare Smart IP for Drupal 10 --- composer.json | 2 +- includes/smart_ip.region_lookup.inc | 15 ++++------ src/GetLocationEvent.php | 6 ++-- tests/src/Functional/SmartIpTest.php | 43 ++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 14 deletions(-) create mode 100644 tests/src/Functional/SmartIpTest.php diff --git a/composer.json b/composer.json index 63d9a91..b25fdd8 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ } ], "require": { - "drupal/core": "^8.7.7 || ^9", + "drupal/core": "^9.1 || ^10", "geoip2/geoip2": "~2.0", "ip2location/ip2location-php": "~8.0" }, diff --git a/includes/smart_ip.region_lookup.inc b/includes/smart_ip.region_lookup.inc index d7c45d9..6b4184b 100644 --- a/includes/smart_ip.region_lookup.inc +++ b/includes/smart_ip.region_lookup.inc @@ -11,10 +11,10 @@ * ISO 3166 2-character country code. * @param $region_code * Region code (FIPS). - * @return + * @return string * Region name. */ -function smart_ip_get_region($country_code, $region_code) { +function smart_ip_get_region($country_code, $region_code): string { $region_codes = array( 'AD' => array( '02' => t('Canillo'), @@ -4665,11 +4665,6 @@ function smart_ip_get_region($country_code, $region_code) { // Allow other modules to modify country list via // hook_smart_ip_region_predefined_list() \Drupal::moduleHandler()->alter('smart_ip_region_predefined_list', $region_codes); - - if (!isset($region_codes[$country_code][$region_code]) || empty($country_code) || empty($region_code)) { - return ''; - } - else { - return $region_codes[$country_code][$region_code]; - } -} \ No newline at end of file + + return $region_codes[$country_code][$region_code] ?? ''; +} diff --git a/src/GetLocationEvent.php b/src/GetLocationEvent.php index 228cf89..af3e5dc 100644 --- a/src/GetLocationEvent.php +++ b/src/GetLocationEvent.php @@ -26,9 +26,9 @@ class GetLocationEvent extends Event { /** * Contains Smart IP data source info. * - * @var string + * @var string|null */ - protected mixed $dataSource; + protected ?string $dataSource; /** * Constructs a Smart IP event. @@ -67,7 +67,7 @@ class GetLocationEvent extends Event { * @return string * Smart IP's data source. */ - public function getDataSource(): string { + public function getDataSource(): ?string { return $this->dataSource; } diff --git a/tests/src/Functional/SmartIpTest.php b/tests/src/Functional/SmartIpTest.php new file mode 100644 index 0000000..8e18787 --- /dev/null +++ b/tests/src/Functional/SmartIpTest.php @@ -0,0 +1,43 @@ +<?php + +namespace Drupal\Tests\smart_ip\Functional; + +use Drupal\Core\Url; +use Drupal\Tests\BrowserTestBase; + +/** + * Test Smart IP module. + * + * @group smart_ip + */ +class SmartIpTest extends BrowserTestBase { + + /** + * {@inheritdoc} + */ + protected $defaultTheme = 'stark'; + + /** + * {@inheritdoc} + */ + protected static $modules = [ + 'smart_ip', + 'device_geolocation', + 'smart_ip_abstract_web_service', + 'smart_ip_ip2location_bin_db', + 'smart_ip_ipinfodb_web_service', + 'smart_ip_maxmind_geoip2_bin_db', + 'smart_ip_maxmind_geoip2_web_service', + ]; + + /** + * Test settings form. + */ + public function testSettingsForm(): void { + $admin_user = $this->drupalCreateUser(['administer smart_ip']); + $this->drupalLogin($admin_user); + $this->drupalGet(Url::fromRoute('smart_ip.settings')); + $this->assertSession()->pageTextContains('Smart IP source'); + } + +} -- GitLab