You are here

public function PluginTestBase::testPropertyStorageModel in Purge 8.3

Test that properties are stored by context.

See also

\Drupal\purge\Plugin\Purge\Invalidation\ImmutableInvalidationInterface::getProperties

\Drupal\purge\Plugin\Purge\Invalidation\ImmutableInvalidationInterface::getProperty

\Drupal\purge\Plugin\Purge\Invalidation\InvalidationInterface::deleteProperty

\Drupal\purge\Plugin\Purge\Invalidation\InvalidationInterface::setProperty

File

tests/src/Kernel/Invalidation/PluginTestBase.php, line 174

Class

PluginTestBase
Provides an abstract test class to thoroughly test invalidation types.

Namespace

Drupal\Tests\purge\Kernel\Invalidation

Code

public function testPropertyStorageModel() : void {
  $i = $this
    ->getInstance();

  // Verify retrieving and setting properties.
  $i
    ->setStateContext('purger1');
  $this
    ->assertSame(NULL, $i
    ->getProperty('doesntexist'));
  $this
    ->assertSame(NULL, $i
    ->setProperty('key1', 'foobar'));
  $this
    ->assertSame('foobar', $i
    ->getProperty('key1'));
  $this
    ->assertSame(NULL, $i
    ->deleteProperty('key1'));
  $this
    ->assertSame(NULL, $i
    ->getProperty('key1'));
  $this
    ->assertSame(NULL, $i
    ->setProperty('key1', 'foobar2'));
  $this
    ->assertSame('foobar2', $i
    ->getProperty('key1'));

  // Switch state to add some more properties.
  $i
    ->setState(InvalidationInterface::FAILED);
  $i
    ->setStateContext('purger2');
  $i
    ->setProperty('key2', 'baz');
  $i
    ->setState(InvalidationInterface::FAILED);
  $i
    ->setStateContext(NULL);

  // Verify that every property is stored by context.
  $p = $i
    ->getProperties();
  $this
    ->assertSame(2, count($p));
  $this
    ->assertSame(TRUE, isset($p['purger1']['key1']));
  $this
    ->assertSame('foobar2', $p['purger1']['key1']);
  $this
    ->assertSame(TRUE, isset($p['purger2']['key2']));
  $this
    ->assertSame('baz', $p['purger2']['key2']);
}