You are here

public function PathAliasExistsTest::testConditionEvaluationAliasWithPath in Rules 8.3

Tests evaluating the condition for an alias that can be resolved.

@covers ::evaluate

File

tests/src/Unit/Integration/Condition/PathAliasExistsTest.php, line 67

Class

PathAliasExistsTest
@coversDefaultClass \Drupal\rules\Plugin\Condition\PathAliasExists @group RulesCondition

Namespace

Drupal\Tests\rules\Unit\Integration\Condition

Code

public function testConditionEvaluationAliasWithPath() {

  // If the path exists, getPathByAlias() should return the path.
  $this->aliasManager
    ->getPathByAlias('/alias-for-path', NULL)
    ->willReturn('/path-with-alias')
    ->shouldBeCalledTimes(1);
  $this->aliasManager
    ->getPathByAlias('/alias-for-path', 'en')
    ->willReturn('/path-with-alias')
    ->shouldBeCalledTimes(1);

  // First, only set the path context.
  $this->condition
    ->setContextValue('alias', '/alias-for-path');

  // Test without language context set. This should return true because the
  // alias is defined.
  $this
    ->assertTrue($this->condition
    ->evaluate());

  // Test with language context set. Again, this should return true because
  // the alias is defined.
  $this->condition
    ->setContextValue('language', $this->englishLanguage
    ->reveal());
  $this
    ->assertTrue($this->condition
    ->evaluate());
}