class UnpublishByKeywordActionTest
Same name and namespace in other branches
- 10 core/modules/node/tests/src/Unit/Action/UnpublishByKeywordActionTest.php \Drupal\Tests\node\Unit\Action\UnpublishByKeywordActionTest
- 10 core/modules/action/tests/src/Kernel/UnpublishByKeywordActionTest.php \Drupal\Tests\action\Kernel\UnpublishByKeywordActionTest
- 8.9.x core/modules/node/tests/src/Kernel/Action/UnpublishByKeywordActionTest.php \Drupal\Tests\node\Kernel\Action\UnpublishByKeywordActionTest
@group node
Hierarchy
- class \Drupal\KernelTests\KernelTestBase extends \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertLegacyTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\Tests\node\Kernel\Action\UnpublishByKeywordActionTest implements \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of UnpublishByKeywordActionTest
File
-
core/
modules/ node/ tests/ src/ Kernel/ Action/ UnpublishByKeywordActionTest.php, line 14
Namespace
Drupal\Tests\node\Kernel\ActionView source
class UnpublishByKeywordActionTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'action',
'node',
'system',
'user',
'field',
];
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->installEntitySchema('node');
$this->installEntitySchema('user');
$this->installSchema('node', [
'node_access',
]);
// Install system's configuration as default date formats are needed.
$this->installConfig([
'system',
]);
// Create a node type for testing.
$type = NodeType::create([
'type' => 'page',
'name' => 'page',
'display_submitted' => FALSE,
]);
$type->save();
}
/**
* Tests creating an action using the node_unpublish_by_keyword_action plugin.
*/
public function testUnpublishByKeywordAction() {
/** @var \Drupal\node\Plugin\Action\UnpublishByKeywordNode $action */
$action = Action::create([
'id' => 'foo',
'label' => 'Foo',
'plugin' => 'node_unpublish_by_keyword_action',
'configuration' => [
'keywords' => [
'test',
],
],
]);
$action->save();
$node1 = Node::create([
'type' => 'page',
'title' => 'test',
'uid' => 1,
]);
$node1->setPublished();
$node1->save();
$node2 = Node::create([
'type' => 'page',
'title' => 'Another node',
'uid' => 1,
]);
$node2->setPublished();
$node2->save();
$this->container
->get('renderer')
->executeInRenderContext(new RenderContext(), function () use (&$node1, &$node2, $action) {
$action->execute([
$node1,
$node2,
]);
});
$this->assertFalse($node1->isPublished());
$this->assertTrue($node2->isPublished());
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.