rules-8.x-3.x-dev/tests/src/Unit/Integration/Condition/NodeIsPromotedTest.php
tests/src/Unit/Integration/Condition/NodeIsPromotedTest.php
<?php
declare(strict_types=1);
namespace Drupal\Tests\rules\Unit\Integration\Condition;
use Drupal\Tests\rules\Unit\Integration\RulesEntityIntegrationTestBase;
use Drupal\node\NodeInterface;
// cspell:ignore unpromoted
/**
* @coversDefaultClass \Drupal\rules\Plugin\Condition\NodeIsPromoted
* @group RulesCondition
*/
class NodeIsPromotedTest 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_promoted');
}
/**
* Tests evaluating the condition.
*
* @covers ::evaluate
*/
public function testConditionEvaluation(): void {
$promoted_node = $this->prophesizeEntity(NodeInterface::class);
$promoted_node->isPromoted()->willReturn(TRUE)->shouldBeCalledTimes(1);
// Set the node context value.
$this->condition->setContextValue('node', $promoted_node->reveal());
$this->assertTrue($this->condition->evaluate());
$unpromoted_node = $this->prophesizeEntity(NodeInterface::class);
$unpromoted_node->isPromoted()->willReturn(FALSE)->shouldBeCalledTimes(1);
// Set the node context value.
$this->condition->setContextValue('node', $unpromoted_node->reveal());
$this->assertFalse($this->condition->evaluate());
}
}
