function UnpublishByKeywordCommentTest::testCommentDefaultConfigActions

Tests comment module's default config actions.

See also

\Drupal\Core\Entity\Form\DeleteMultipleForm::submitForm()

\Drupal\Core\Action\Plugin\Action\DeleteAction

\Drupal\Core\Action\Plugin\Action\Derivative\EntityDeleteActionDeriver

\Drupal\Core\Action\Plugin\Action\PublishAction

\Drupal\Core\Action\Plugin\Action\SaveAction

File

core/modules/action/tests/src/Kernel/UnpublishByKeywordCommentTest.php, line 107

Class

UnpublishByKeywordCommentTest
@group action

Namespace

Drupal\Tests\action\Kernel

Code

public function testCommentDefaultConfigActions() : void {
    $this->assertTrue($this->comment
        ->isNew());
    $action = Action::load('comment_save_action');
    $action->execute([
        $this->comment,
    ]);
    $this->assertFalse($this->comment
        ->isNew());
    $this->assertTrue($this->comment
        ->isPublished());
    // Tests comment unpublish.
    $action = Action::load('comment_unpublish_action');
    $action->execute([
        $this->comment,
    ]);
    $this->assertFalse($this->comment
        ->isPublished(), 'Comment was unpublished');
    $this->assertSame([
        'module' => [
            'comment',
        ],
    ], $action->getDependencies());
    // Tests comment publish.
    $action = Action::load('comment_publish_action');
    $action->execute([
        $this->comment,
    ]);
    $this->assertTrue($this->comment
        ->isPublished(), 'Comment was published');
    $action = Action::load('comment_delete_action');
    $action->execute([
        $this->comment,
    ]);
    
    /** @var \Drupal\Core\TempStore\PrivateTempStoreFactory $temp_store */
    $temp_store = $this->container
        ->get('tempstore.private');
    $account_id = $this->container
        ->get('current_user')
        ->id();
    $store_entries = $temp_store->get('entity_delete_multiple_confirm')
        ->get($account_id . ':comment');
    $this->assertSame([
        $account_id => [
            'en' => 'en',
        ],
    ], $store_entries);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.