public function MigrateIp2CountryUserDataTest::testIp2CountryUserData in IP-based Determination of a Visitor's Country 8
Same name in this branch
- 8 tests/src/Kernel/Migrate/d6/MigrateIp2CountryUserDataTest.php \Drupal\Tests\ip2country\Kernel\Migrate\d6\MigrateIp2CountryUserDataTest::testIp2CountryUserData()
- 8 tests/src/Kernel/Migrate/d7/MigrateIp2CountryUserDataTest.php \Drupal\Tests\ip2country\Kernel\Migrate\d7\MigrateIp2CountryUserDataTest::testIp2CountryUserData()
Tests the Drupal6 Ip2Country user settings migration.
File
- tests/
src/ Kernel/ Migrate/ d6/ MigrateIp2CountryUserDataTest.php, line 40
Class
- MigrateIp2CountryUserDataTest
- Tests migration of Ip2Country {user}.data into {user_data}.
Namespace
Drupal\Tests\ip2country\Kernel\Migrate\d6Code
public function testIp2CountryUserData() {
// In D6 and D7, {users}.data stores a serialized array containing
// at most one key => value pair of ip2country data in the form
// 's:18:"country_iso_code_2";s:2:"US";'.
//
// In D8, the user.data service stores data as rows in {users_data}.
// Each row contains the values 'uid', 'module', 'name', 'value',
// and 'serialized'.
//
// $userData->get($module, $uid, $key); returns a string (the 'value')
// for the row identified by the $module, $uid, and the $key.
// The ip2country module uses the country_iso_code_2 'key' to store a
// 2-character country code 'value'. Unserialization is done automatically
// if necessary.
$userData = \Drupal::service('user.data');
$module = 'ip2country';
$key = 'country_iso_code_2';
$uid = 2;
$setting = $userData
->get($module, $uid, $key);
$this
->assertSame('CA', $setting);
$uid = 8;
$setting = $userData
->get($module, $uid, $key);
$this
->assertSame(NULL, $setting);
$uid = 15;
$setting = $userData
->get($module, $uid, $key);
$this
->assertSame('ES', $setting);
}