You are here

public function AnnotationProcessingTest::testTranslationSquelching in Rules 8.3

Make sure @ Translation annotations do not leak out into the wild.

File

tests/src/Unit/Integration/Engine/AnnotationProcessingTest.php, line 30

Class

AnnotationProcessingTest
Tests processing of the ContextDefinition annotation.

Namespace

Drupal\Tests\rules\Unit\Integration\Engine

Code

public function testTranslationSquelching() {

  // Get a sample Rules plugin.
  $plugin = $this->conditionManager
    ->createInstance('rules_list_contains');
  $context = $plugin
    ->getContext('list');
  $definition = $context
    ->getContextDefinition();

  // These can reasonable be string or TranslatableMarkup, but never
  // a Translation object.
  $label = $definition
    ->getLabel();
  $description = $definition
    ->getDescription();
  $this
    ->assertFalse($label instanceof Translation, 'Label is not a Translation object');
  $this
    ->assertFalse($description instanceof Translation, 'Description is not a Translation object');

  // Check also the toArray() path.
  $definition = $context
    ->getContextDefinition();
  $values = $definition
    ->toArray();
  $label = $values['label'];
  $description = $values['description'];
  $this
    ->assertFalse($label instanceof Translation, "\$values['label'] is not a Translation object");
  $this
    ->assertFalse($description instanceof Translation, "\$values['description'] is not a Translation object");
}