You are here

public function PluginTestBase::testPluginIdAndDefinition in Purge 8.3

Test retrieving the plugin ID and definition.

See also

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

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

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

File

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

Class

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

Namespace

Drupal\Tests\purge\Kernel\Invalidation

Code

public function testPluginIdAndDefinition() : void {

  // Test mutable objects.
  $mutable = $this
    ->getInstance();
  $this
    ->assertEquals($this->pluginId, $mutable
    ->getPluginId());
  $this
    ->assertEquals($this->pluginId, $mutable
    ->getType());
  $d = $mutable
    ->getPluginDefinition();
  $this
    ->assertTrue(is_array($d));
  $this
    ->assertTrue(is_array($d['examples']));
  $this
    ->assertTrue($d['label'] instanceof TranslatableMarkup);
  $this
    ->assertFalse(empty((string) $d['label']));
  $this
    ->assertTrue($d['description'] instanceof TranslatableMarkup);
  $this
    ->assertFalse(empty((string) $d['description']));
  $this
    ->assertTrue(isset($d['expression_required']));
  $this
    ->assertTrue(isset($d['expression_can_be_empty']));
  $this
    ->assertTrue(isset($d['expression_must_be_string']));
  if (!$d["expression_required"]) {
    $this
      ->assertFalse($d["expression_can_be_empty"]);
  }

  // Test the immutable objects.
  $immutable = $this
    ->getImmutableInstance();
  $this
    ->assertEquals($this->pluginId, $immutable
    ->getPluginId());
  $this
    ->assertEquals($this->pluginId, $immutable
    ->getType());
  $d = $immutable
    ->getPluginDefinition();
  $this
    ->assertTrue(is_array($d));
  $this
    ->assertTrue(is_array($d['examples']));
  $this
    ->assertTrue($d['label'] instanceof TranslatableMarkup);
  $this
    ->assertFalse(empty((string) $d['label']));
  $this
    ->assertTrue($d['description'] instanceof TranslatableMarkup);
  $this
    ->assertFalse(empty((string) $d['description']));
  $this
    ->assertTrue(isset($d['expression_required']));
  $this
    ->assertTrue(isset($d['expression_can_be_empty']));
  $this
    ->assertTrue(isset($d['expression_must_be_string']));
  if (!$d["expression_required"]) {
    $this
      ->assertFalse($d["expression_can_be_empty"]);
  }
}