AnonymousPrivateTempStoreTest.php in Drupal 10
File
core/tests/Drupal/KernelTests/Core/TempStore/AnonymousPrivateTempStoreTest.php
View source
<?php
namespace Drupal\KernelTests\Core\TempStore;
use Drupal\KernelTests\KernelTestBase;
use Symfony\Component\HttpFoundation\Request;
class AnonymousPrivateTempStoreTest extends KernelTestBase {
protected static $modules = [
'system',
];
protected $tempStore;
protected function setUp() : void {
parent::setUp();
$request = Request::create('/');
$stack = $this->container
->get('request_stack');
$stack
->pop();
$stack
->push($request);
$this->tempStore = $this->container
->get('tempstore.private')
->get('anonymous_private_temp_store');
}
public function testAnonymousCanUsePrivateTempStoreGet() {
$actual = $this->tempStore
->get('foo');
$this
->assertNull($actual);
}
public function testAnonymousCanUsePrivateTempStoreSet() {
$this->tempStore
->set('foo', 'bar');
$metadata1 = $this->tempStore
->getMetadata('foo');
$this
->assertEquals('bar', $this->tempStore
->get('foo'));
$this
->assertNotEmpty($metadata1
->getOwnerId());
$this->tempStore
->set('foo', 'bar2');
$metadata2 = $this->tempStore
->getMetadata('foo');
$this
->assertEquals('bar2', $this->tempStore
->get('foo'));
$this
->assertNotEmpty($metadata2
->getOwnerId());
$this
->assertEquals($metadata2
->getOwnerId(), $metadata1
->getOwnerId());
}
}