diff --git a/composer.json b/composer.json index 63d9a917c5263533f8be8a803a0b42002b44798f..b25fdd895b12f3e59b537b2a14dfcbca20c11b41 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 d7c45d92a8a22545eb640ff3e2f158d83d695685..6b4184b8587f3bd912d2977674f9b9828f0e1d39 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 228cf89715cd295b8092a649e777496595aa7da8..af3e5dc086302edac41ae55f07cb2afdd83222dc 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 0000000000000000000000000000000000000000..8e1878738295613bf0f361902668a03e78bbea88 --- /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'); + } + +}