class AnonymousPrivateTempStoreTest
Same name and namespace in other branches
- 11.x core/tests/Drupal/KernelTests/Core/TempStore/AnonymousPrivateTempStoreTest.php \Drupal\KernelTests\Core\TempStore\AnonymousPrivateTempStoreTest
- 10 core/tests/Drupal/KernelTests/Core/TempStore/AnonymousPrivateTempStoreTest.php \Drupal\KernelTests\Core\TempStore\AnonymousPrivateTempStoreTest
- 8.9.x core/tests/Drupal/KernelTests/Core/TempStore/AnonymousPrivateTempStoreTest.php \Drupal\KernelTests\Core\TempStore\AnonymousPrivateTempStoreTest
Tests the PrivateTempStore for anonymous users.
@group TempStore
Hierarchy
- class \Drupal\KernelTests\KernelTestBase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertLegacyTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\KernelTests\Core\TempStore\AnonymousPrivateTempStoreTest extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of AnonymousPrivateTempStoreTest
File
-
core/
tests/ Drupal/ KernelTests/ Core/ TempStore/ AnonymousPrivateTempStoreTest.php, line 13
Namespace
Drupal\KernelTests\Core\TempStoreView source
class AnonymousPrivateTempStoreTest extends KernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'system',
];
/**
* The private temp store.
*
* @var \Drupal\Core\TempStore\PrivateTempStore
*/
protected $tempStore;
/**
* {@inheritdoc}
*/
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');
}
/**
* Tests anonymous can get without a previous set.
*/
public function testAnonymousCanUsePrivateTempStoreGet() {
$actual = $this->tempStore
->get('foo');
$this->assertNull($actual);
}
/**
* Tests anonymous can use the PrivateTempStore.
*/
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());
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.