function UnpublishByKeywordActionTest::testUnpublishByKeywordAction

Same name in this branch
  1. 10 core/modules/node/tests/src/Kernel/Action/UnpublishByKeywordActionTest.php \Drupal\Tests\node\Kernel\Action\UnpublishByKeywordActionTest::testUnpublishByKeywordAction()
  2. 10 core/modules/node/tests/src/Unit/Action/UnpublishByKeywordActionTest.php \Drupal\Tests\node\Unit\Action\UnpublishByKeywordActionTest::testUnpublishByKeywordAction()
Same name and namespace in other branches
  1. 9 core/modules/node/tests/src/Kernel/Action/UnpublishByKeywordActionTest.php \Drupal\Tests\node\Kernel\Action\UnpublishByKeywordActionTest::testUnpublishByKeywordAction()
  2. 8.9.x core/modules/node/tests/src/Kernel/Action/UnpublishByKeywordActionTest.php \Drupal\Tests\node\Kernel\Action\UnpublishByKeywordActionTest::testUnpublishByKeywordAction()
  3. 11.x core/modules/node/tests/src/Kernel/Action/UnpublishByKeywordActionTest.php \Drupal\Tests\node\Kernel\Action\UnpublishByKeywordActionTest::testUnpublishByKeywordAction()

Tests creating an action using the node_unpublish_by_keyword_action plugin.

File

core/modules/action/tests/src/Kernel/UnpublishByKeywordActionTest.php, line 41

Class

UnpublishByKeywordActionTest
@group action

Namespace

Drupal\Tests\action\Kernel

Code

public function testUnpublishByKeywordAction() : void {
  /** @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.