rules-8.x-3.x-dev/tests/src/Unit/Integration/Condition/NodeIsOfTypeTest.php

tests/src/Unit/Integration/Condition/NodeIsOfTypeTest.php
<?php

declare(strict_types=1);

namespace Drupal\Tests\rules\Unit\Integration\Condition;

use Drupal\Tests\rules\Unit\Integration\RulesEntityIntegrationTestBase;
use Drupal\node\NodeInterface;

/**
 * @coversDefaultClass \Drupal\rules\Plugin\Condition\NodeIsOfType
 * @group RulesCondition
 */
class NodeIsOfTypeTest extends RulesEntityIntegrationTestBase {

  /**
   * The condition to be tested.
   *
   * @var \Drupal\rules\Core\RulesConditionInterface
   */
  protected $condition;

  /**
   * {@inheritdoc}
   */
  protected function setUp(): void {
    parent::setUp();

    $this->enableModule('node');
    $this->condition = $this->conditionManager->createInstance('rules_node_is_of_type');
  }

  /**
   * Tests evaluating the condition.
   *
   * @covers ::evaluate
   */
  public function testConditionEvaluation(): void {
    $node = $this->prophesizeEntity(NodeInterface::class);
    $node->getType()->willReturn('page');

    // Set the node context value.
    $this->condition->setContextValue('node', $node->reveal());

    // Test evaluation with a list that contains the actual node type.
    $this->condition->setContextValue('types', ['page', 'article']);
    $this->assertTrue($this->condition->evaluate());

    // Test with a list that does not contain the actual node type.
    $this->condition->setContextValue('types', ['apple', 'banana']);
    $this->assertFalse($this->condition->evaluate());
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc