TimezoneResolverTest.php in Drupal 10
File
core/modules/system/tests/src/Kernel/TimezoneResolverTest.php
View source
<?php
namespace Drupal\Tests\system\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\user\Traits\UserCreationTrait;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\KernelEvents;
class TimezoneResolverTest extends KernelTestBase {
use UserCreationTrait;
protected static $modules = [
'system',
'user',
];
public function testGetTimeZone() {
$this
->installEntitySchema('user');
$this
->installSchema('system', [
'sequences',
]);
$this
->installConfig([
'system',
]);
$this
->assertEquals('Australia/Sydney', date_default_timezone_get());
$configFactory = $this->container
->get('config.factory');
$timeZoneConfig = $configFactory
->getEditable('system.date');
$timeZoneConfig
->set('timezone.default', 'Australia/Adelaide');
$timeZoneConfig
->save();
$eventDispatcher = $this->container
->get('event_dispatcher');
$kernel = $this->container
->get('kernel');
$eventDispatcher
->dispatch(new RequestEvent($kernel, Request::create('http://www.example.com'), HttpKernelInterface::MAIN_REQUEST, KernelEvents::REQUEST));
$this
->assertEquals('Australia/Adelaide', date_default_timezone_get());
$user = $this
->createUser([]);
$user
->set('timezone', 'Australia/Lord_Howe');
$user
->save();
$this
->setCurrentUser($user);
$this
->assertEquals('Australia/Lord_Howe', date_default_timezone_get());
}
}