first commit

This commit is contained in:
2024-07-15 12:33:27 +02:00
commit ce50ae282b
22084 changed files with 2623791 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
name: action_form_ajax_test
type: module
description: 'module used for testing ajax in action config entity forms.'
package: Core
# version: VERSION
hidden: true
# Information added by Drupal.org packaging script on 2024-07-04
version: '10.3.1'
project: 'drupal'
datestamp: 1720094222

View File

@@ -0,0 +1,90 @@
<?php
namespace Drupal\action_form_ajax_test\Plugin\Action;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Action\ConfigurableActionBase;
use Drupal\Core\Action\Attribute\Action;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
/**
* Plugin used for testing AJAX in action config entity forms.
*/
#[Action(
id: 'action_form_ajax_test',
label: new TranslatableMarkup('action_form_ajax_test'),
type: 'system'
)]
class ActionAjaxTest extends ConfigurableActionBase {
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [
'party_time' => '',
];
}
/**
* {@inheritdoc}
*/
public function access($object, ?AccountInterface $account = NULL, $return_as_object = FALSE) {
$result = AccessResult::allowed();
return $return_as_object ? $result : $result->isAllowed();
}
/**
* {@inheritdoc}
*/
public function execute() {
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$having_a_party = $form_state->getValue('having_a_party', !empty($this->configuration['party_time']));
$form['having_a_party'] = [
'#type' => 'checkbox',
'#title' => $this->t('Are we having a party?'),
'#ajax' => [
'wrapper' => 'party-container',
'callback' => [$this, 'partyCallback'],
],
'#default_value' => $having_a_party,
];
$form['container'] = [
'#type' => 'container',
'#prefix' => '<div id="party-container">',
'#suffix' => '</div>',
];
if ($having_a_party) {
$form['container']['party_time'] = [
'#type' => 'textfield',
'#title' => $this->t('Party time'),
'#default_value' => $this->configuration['party_time'],
];
}
return $form;
}
/**
* Callback for party checkbox.
*/
public function partyCallback(array $form, FormStateInterface $form_state) {
return $form['container'];
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$this->configuration['party_time'] = $form_state->getValue('party_time');
}
}

View File

@@ -0,0 +1 @@
recursion_limit: 35

View File

@@ -0,0 +1,54 @@
<?php
declare(strict_types=1);
namespace Drupal\Tests\action\Functional;
use Drupal\Tests\BrowserTestBase;
/**
* Test behaviors when visiting the action listing page.
*
* @group action
* @group legacy
*/
class ActionListTest extends BrowserTestBase {
/**
* Modules to install.
*
* @var array
*/
protected static $modules = ['action', 'user'];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Tests the behavior when there are no actions to list in the admin page.
*/
public function testEmptyActionList(): void {
// Create a user with permission to view the actions administration pages.
$this->drupalLogin($this->drupalCreateUser(['administer actions']));
// Ensure the empty text appears on the action list page.
/** @var \Drupal\Core\Entity\EntityStorageInterface $storage */
$storage = $this->container->get('entity_type.manager')->getStorage('action');
$actions = $storage->loadMultiple();
$storage->delete($actions);
$this->drupalGet('/admin/config/system/actions');
$this->assertSession()->pageTextContains('There are no actions yet.');
}
/**
* Tests that non-configurable actions can be created by the UI.
*/
public function testNonConfigurableActionsCanBeCreated(): void {
$this->drupalLogin($this->drupalCreateUser(['administer actions']));
$this->drupalGet('/admin/config/system/actions');
$this->assertSession()->elementExists('css', 'select > option[value="user_block_user_action"]');
}
}

View File

@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);
namespace Drupal\Tests\action\Functional;
use Drupal\Tests\BrowserTestBase;
/**
* Tests that uninstalling Actions UI does not remove other modules' actions.
*
* @group action
* @group legacy
* @see \Drupal\views\Plugin\views\field\BulkForm
* @see \Drupal\user\Plugin\Action\BlockUser
*/
class ActionUninstallTest extends BrowserTestBase {
/**
* Modules to install.
*
* @var array
*/
protected static $modules = ['views', 'action'];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Tests Actions UI uninstall.
*/
public function testActionUninstall(): void {
\Drupal::service('module_installer')->uninstall(['action']);
$storage = $this->container->get('entity_type.manager')->getStorage('action');
$storage->resetCache(['user_block_user_action']);
$this->assertNotEmpty($storage->load('user_block_user_action'), 'Configuration entity \'user_block_user_action\' still exists after uninstalling action module.');
$admin_user = $this->drupalCreateUser(['administer users']);
$this->drupalLogin($admin_user);
$this->drupalGet('admin/people');
// Ensure we have the user_block_user_action listed.
$this->assertSession()->responseContains('<option value="user_block_user_action">Block the selected user(s)</option>');
}
}

View File

@@ -0,0 +1,104 @@
<?php
declare(strict_types=1);
namespace Drupal\Tests\action\Functional;
use Drupal\system\Entity\Action;
use Drupal\Tests\BrowserTestBase;
/**
* Tests complex actions configuration.
*
* @group action
* @group legacy
*/
class ConfigurationTest extends BrowserTestBase {
/**
* Modules to install.
*
* @var array
*/
protected static $modules = ['action'];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Tests configuration of advanced actions through administration interface.
*/
public function testActionConfiguration(): void {
// Create a user with permission to view the actions administration pages.
$user = $this->drupalCreateUser(['administer actions']);
$this->drupalLogin($user);
// Make a POST request to admin/config/system/actions.
$edit = [];
$edit['action'] = 'action_goto_action';
$this->drupalGet('admin/config/system/actions');
$this->submitForm($edit, 'Create');
$this->assertSession()->statusCodeEquals(200);
// Make a POST request to the individual action configuration page.
$edit = [];
$action_label = $this->randomMachineName();
$edit['label'] = $action_label;
$edit['id'] = strtolower($action_label);
$edit['url'] = 'admin';
$this->drupalGet('admin/config/system/actions/add/action_goto_action');
$this->submitForm($edit, 'Save');
$this->assertSession()->statusCodeEquals(200);
$action_id = $edit['id'];
// Make sure that the new complex action was saved properly.
$this->assertSession()->pageTextContains('The action has been successfully saved.');
// The action label appears on the configuration page.
$this->assertSession()->pageTextContains($action_label);
// Make another POST request to the action edit page.
$this->clickLink('Configure');
$edit = [];
$new_action_label = $this->randomMachineName();
$edit['label'] = $new_action_label;
$edit['url'] = 'admin';
$this->submitForm($edit, 'Save');
$this->assertSession()->statusCodeEquals(200);
// Make sure that the action updated properly.
$this->assertSession()->pageTextContains('The action has been successfully saved.');
// The old action label does NOT appear on the configuration page.
$this->assertSession()->pageTextNotContains($action_label);
// The action label appears on the configuration page after we've updated
// the complex action.
$this->assertSession()->pageTextContains($new_action_label);
// Make sure the URL appears when re-editing the action.
$this->clickLink('Configure');
$this->assertSession()->fieldValueEquals('url', 'admin');
// Make sure that deletions work properly.
$this->drupalGet('admin/config/system/actions');
$this->clickLink('Delete');
$this->assertSession()->statusCodeEquals(200);
$edit = [];
$this->submitForm($edit, 'Delete');
$this->assertSession()->statusCodeEquals(200);
// Make sure that the action was actually deleted.
$this->assertSession()->pageTextContains("The action $new_action_label has been deleted.");
$this->drupalGet('admin/config/system/actions');
$this->assertSession()->statusCodeEquals(200);
// The action label does not appear on the overview page.
$this->assertSession()->pageTextNotContains($new_action_label);
$action = Action::load($action_id);
$this->assertNull($action, 'Make sure the action is gone after being deleted.');
}
}

View File

@@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
namespace Drupal\Tests\action\Functional;
use Drupal\Tests\system\Functional\Module\GenericModuleTestBase;
/**
* Generic module test for action.
*
* @group action
* @group legacy
*/
class GenericTest extends GenericModuleTestBase {}

View File

@@ -0,0 +1,144 @@
<?php
declare(strict_types=1);
namespace Drupal\Tests\action\Functional\Node;
use Drupal\Component\Serialization\Json;
use Drupal\Tests\BrowserTestBase;
use Drupal\system\Entity\Action;
use Drupal\user\Entity\User;
/**
* Tests configuration of actions provided by the Node module.
*
* @group action
* @group legacy
*/
class NodeActionsConfigurationTest extends BrowserTestBase {
/**
* Modules to install.
*
* @var array
*/
protected static $modules = ['action', 'node'];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Tests configuration of the node_assign_owner_action action.
*/
public function testAssignOwnerNodeActionConfiguration(): void {
// Create a user with permission to view the actions administration pages.
$user = $this->drupalCreateUser(['administer actions']);
$this->drupalLogin($user);
// Make a POST request to admin/config/system/actions.
$edit = [];
$edit['action'] = 'node_assign_owner_action';
$this->drupalGet('admin/config/system/actions');
$this->submitForm($edit, 'Create');
$this->assertSession()->statusCodeEquals(200);
// Make a POST request to the individual action configuration page.
$edit = [];
$action_label = $this->randomMachineName();
$edit['label'] = $action_label;
$edit['id'] = strtolower($action_label);
$edit['owner_uid'] = $user->id();
$this->drupalGet('admin/config/system/actions/add/node_assign_owner_action');
$this->submitForm($edit, 'Save');
$this->assertSession()->statusCodeEquals(200);
$action_id = $edit['id'];
$action_configure = sprintf('/admin/config/system/actions/configure/%s', $action_id);
$action_delete = sprintf('/admin/config/system/actions/configure/%s/delete', $action_id);
// Make sure that the new action was saved properly.
$this->assertSession()->pageTextContains('The action has been successfully saved.');
// Check that the label of the node_assign_owner_action action appears on
// the actions administration page after saving.
$this->assertSession()->pageTextContains($action_label);
// Make another POST request to the action edit page.
$this->assertSession()->linkByHrefExists($action_configure);
$this->drupalGet($action_configure);
$edit = [];
$new_action_label = $this->randomMachineName();
$edit['label'] = $new_action_label;
$edit['owner_uid'] = $user->id();
$this->submitForm($edit, 'Save');
$this->assertSession()->statusCodeEquals(200);
// Make sure that the action updated properly.
$this->assertSession()->pageTextContains('The action has been successfully saved.');
// Check that the old label for the node_assign_owner_action action does not
// appear on the actions administration page after updating.
$this->assertSession()->pageTextNotContains($action_label);
// Check that the new label for the node_assign_owner_action action appears
// on the actions administration page after updating.
$this->assertSession()->pageTextContains($new_action_label);
// Make sure that deletions work properly.
$this->drupalGet('admin/config/system/actions');
$this->assertSession()->linkByHrefExists($action_delete);
$this->drupalGet($action_delete);
$this->assertSession()->statusCodeEquals(200);
$edit = [];
$this->submitForm($edit, 'Delete');
$this->assertSession()->statusCodeEquals(200);
// Make sure that the action was actually deleted.
$this->assertSession()->pageTextContains("The action {$new_action_label} has been deleted.");
$this->drupalGet('admin/config/system/actions');
$this->assertSession()->statusCodeEquals(200);
// Check that the label for the node_assign_owner_action action does not
// appear on the actions administration page after deleting.
$this->assertSession()->pageTextNotContains($new_action_label);
$action = Action::load($action_id);
$this->assertNull($action, 'The node_assign_owner_action action is not available after being deleted.');
}
/**
* Tests the autocomplete field when configuring the AssignOwnerNode action.
*/
public function testAssignOwnerNodeActionAutocomplete(): void {
// Create 200 users to force the action's configuration page to use an
// autocomplete field instead of a select field. See
// \Drupal\node\Plugin\Action\AssignOwnerNode::buildConfigurationForm().
for ($i = 0; $i < 200; $i++) {
$this->drupalCreateUser();
}
// Create a user with permission to view the actions administration pages
// and additionally permission to administer users. Otherwise the user would
// not be able to reference the anonymous user.
$this->drupalLogin($this->drupalCreateUser(['administer actions', 'administer users']));
// Create AssignOwnerNode action.
$this->drupalGet('admin/config/system/actions');
$this->submitForm(['action' => 'node_assign_owner_action'], 'Create');
// Get the autocomplete URL of the owner_uid textfield.
$autocomplete_field = $this->getSession()->getPage()->findField('owner_uid');
$autocomplete_url = $this->getAbsoluteUrl($autocomplete_field->getAttribute('data-autocomplete-path'));
// Make sure that autocomplete works.
$user = $this->drupalCreateUser();
$data = Json::decode($this->drupalGet($autocomplete_url, ['query' => ['q' => $user->getDisplayName(), '_format' => 'json']]));
$this->assertNotEmpty($data);
$anonymous = User::getAnonymousUser();
// Ensure that the anonymous user exists.
$this->assertNotNull($anonymous);
// Make sure the autocomplete does not show the anonymous user.
$data = Json::decode($this->drupalGet($autocomplete_url, ['query' => ['q' => $anonymous->getDisplayName(), '_format' => 'json']]));
$this->assertEmpty($data);
}
}

View File

@@ -0,0 +1,76 @@
<?php
declare(strict_types=1);
namespace Drupal\Tests\action\FunctionalJavascript;
use Drupal\Core\Url;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\system\Entity\Action;
/**
* Tests action plugins using JavaScript.
*
* @group action
* @group legacy
*/
class ActionFormAjaxTest extends WebDriverTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['action', 'action_form_ajax_test'];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$user = $this->drupalCreateUser(['administer actions']);
$this->drupalLogin($user);
}
/**
* Tests action plugins with AJAX save their configuration.
*/
public function testActionConfigurationWithAjax(): void {
$url = Url::fromRoute('action.admin_add', ['action_id' => 'action_form_ajax_test']);
$this->drupalGet($url);
$page = $this->getSession()->getPage();
$id = 'test_plugin';
$this->assertSession()->waitForElementVisible('named', ['button', 'Edit'])->press();
$this->assertSession()->waitForElementVisible('css', '[name="id"]')->setValue($id);
$page->find('css', '[name="having_a_party"]')
->check();
$this->assertSession()->waitForElementVisible('css', '[name="party_time"]');
$party_time = 'Evening';
$page->find('css', '[name="party_time"]')
->setValue($party_time);
$page->find('css', '[value="Save"]')
->click();
$url = Url::fromRoute('entity.action.collection');
$this->assertSession()->pageTextContains('The action has been successfully saved.');
$this->assertSession()->addressEquals($url);
// Check storage.
$instance = Action::load($id);
$configuration = $instance->getPlugin()->getConfiguration();
$this->assertEquals(['party_time' => $party_time], $configuration);
// Configuration should be shown in edit form.
$this->drupalGet($instance->toUrl('edit-form'));
$this->assertSession()->checkboxChecked('having_a_party');
$this->assertSession()->fieldValueEquals('party_time', $party_time);
}
}

View File

@@ -0,0 +1,61 @@
<?php
declare(strict_types=1);
namespace Drupal\Tests\action\Kernel\Migrate\d6;
use Drupal\system\Entity\Action;
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
/**
* Tests migration of action items.
*
* @group migrate_drupal_6
*/
class MigrateActionsTest extends MigrateDrupal6TestBase {
protected static $modules = ['action', 'comment', 'node'];
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->executeMigration('d6_action');
}
/**
* Tests Drupal 6 action migration to Drupal 8.
*/
public function testActions(): void {
// Test advanced actions.
$this->assertEntity('unpublish_comment_containing_keyword_s_', 'Unpublish comment containing keyword(s)', 'comment', ["keywords" => [0 => "drupal"]]);
$this->assertEntity('unpublish_post_containing_keyword_s_', 'Unpublish post containing keyword(s)', 'node', ["keywords" => [0 => "drupal"]]);
}
/**
* Asserts various aspects of an Action entity.
*
* @param string $id
* The expected Action ID.
* @param string $label
* The expected Action label.
* @param string $type
* The expected Action type.
* @param array $configuration
* The expected Action configuration.
*
* @internal
*/
protected function assertEntity(string $id, string $label, string $type, array $configuration): void {
$action = Action::load($id);
$this->assertInstanceOf(Action::class, $action);
/** @var \Drupal\system\Entity\Action $action */
$this->assertSame($id, $action->id());
$this->assertSame($label, $action->label());
$this->assertSame($type, $action->getType());
$this->assertSame($configuration, $action->get('configuration'));
}
}

View File

@@ -0,0 +1,61 @@
<?php
declare(strict_types=1);
namespace Drupal\Tests\action\Kernel\Migrate\d7;
use Drupal\system\Entity\Action;
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
/**
* Tests migration of action items.
*
* @group action
*/
class MigrateActionsTest extends MigrateDrupal7TestBase {
protected static $modules = ['action', 'comment', 'node'];
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->executeMigration('d7_action');
}
/**
* Tests Drupal 7 action migration to Drupal 8.
*/
public function testActions(): void {
// Test advanced actions.
$this->assertEntity('unpublish_comment_containing_keyword_s_', 'Unpublish comment containing keyword(s)', 'comment', ["keywords" => [0 => "drupal"]]);
$this->assertEntity('unpublish_content_containing_keyword_s_', 'Unpublish content containing keyword(s)', 'node', ["keywords" => [0 => "drupal"]]);
}
/**
* Asserts various aspects of an Action entity.
*
* @param string $id
* The expected Action ID.
* @param string $label
* The expected Action label.
* @param string $type
* The expected Action type.
* @param array $configuration
* The expected Action configuration.
*
* @internal
*/
protected function assertEntity(string $id, string $label, string $type, array $configuration): void {
$action = Action::load($id);
$this->assertInstanceOf(Action::class, $action);
/** @var \Drupal\system\Entity\Action $action */
$this->assertSame($id, $action->id());
$this->assertSame($label, $action->label());
$this->assertSame($type, $action->getType());
$this->assertSame($configuration, $action->get('configuration'));
}
}

View File

@@ -0,0 +1,75 @@
<?php
declare(strict_types=1);
namespace Drupal\Tests\action\Kernel;
use Drupal\Core\Render\RenderContext;
use Drupal\KernelTests\KernelTestBase;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\system\Entity\Action;
/**
* @group action
*/
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(): 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());
}
}

View File

@@ -0,0 +1,163 @@
<?php
declare(strict_types=1);
namespace Drupal\Tests\action\Kernel;
use Drupal\comment\Entity\Comment;
use Drupal\comment\Entity\CommentType;
use Drupal\comment\Tests\CommentTestTrait;
use Drupal\Core\Datetime\Entity\DateFormat;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\filter\Entity\FilterFormat;
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
use Drupal\system\Entity\Action;
/**
* {@inheritdoc}
*
* @group action
*/
class UnpublishByKeywordCommentTest extends EntityKernelTestBase {
use CommentTestTrait;
/**
* {@inheritdoc}
*/
protected static $modules = ['action', 'comment', 'entity_test'];
/**
* Keywords used for testing.
*
* @var string[]
*/
protected $keywords;
/**
* The comment entity.
*
* @var \Drupal\comment\CommentInterface
*/
protected $comment;
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->installConfig(['user', 'comment']);
$this->installSchema('comment', ['comment_entity_statistics']);
// Create a comment type.
CommentType::create([
'id' => 'comment',
'label' => 'Default comments',
'description' => 'Default comment field',
'target_entity_type_id' => 'entity_test',
])->save();
$this->addDefaultCommentField('entity_test', 'entity_test', 'comment');
// Setup date format to render comment date.
DateFormat::create([
'id' => 'fallback',
'pattern' => 'D, m/d/Y - H:i',
'label' => 'Fallback',
])->save();
// Create format without filters to prevent filtering.
FilterFormat::create([
'format' => 'no_filters',
'name' => 'No filters',
'filters' => [],
])->save();
// Set current user to allow filters display comment body.
$this->drupalSetCurrentUser($this->drupalCreateUser());
$this->keywords = [$this->randomMachineName(), $this->randomMachineName()];
// Create a comment against a test entity.
$host = EntityTest::create();
$host->save();
$this->comment = Comment::create([
'entity_type' => 'entity_test',
'name' => $this->randomString(),
'hostname' => 'magic.example.com',
'mail' => 'tonythemagicalpony@example.com',
'subject' => $this->keywords[0],
'comment_body' => $this->keywords[1],
'entity_id' => $host->id(),
'comment_type' => 'comment',
'field_name' => 'comment',
]);
$this->comment->get('comment_body')->format = 'no_filters';
$this->comment->setPublished();
}
/**
* Tests comment module's default config actions.
*
* @see \Drupal\Core\Entity\Form\DeleteMultipleForm::submitForm()
* @see \Drupal\Core\Action\Plugin\Action\DeleteAction
* @see \Drupal\Core\Action\Plugin\Action\Derivative\EntityDeleteActionDeriver
* @see \Drupal\Core\Action\Plugin\Action\PublishAction
* @see \Drupal\Core\Action\Plugin\Action\SaveAction
*/
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);
}
/**
* Tests the unpublish comment by keyword action.
*
* @see \Drupal\comment\Plugin\Action\UnpublishByKeywordComment
*/
public function testCommentUnpublishByKeyword(): void {
$this->comment->save();
$action = Action::create([
'id' => 'comment_unpublish_by_keyword_action',
'label' => $this->randomMachineName(),
'type' => 'comment',
'plugin' => 'comment_unpublish_by_keyword_action',
]);
// Tests no keywords.
$action->execute([$this->comment]);
$this->assertTrue($this->comment->isPublished(), 'The comment status was set to published.');
// Tests keyword in subject.
$action->set('configuration', ['keywords' => [$this->keywords[0]]]);
$action->execute([$this->comment]);
$this->assertFalse($this->comment->isPublished(), 'The comment status was set to not published.');
// Tests keyword in comment body.
$this->comment->setPublished();
$action->set('configuration', ['keywords' => [$this->keywords[1]]]);
$action->execute([$this->comment]);
$this->assertFalse($this->comment->isPublished(), 'The comment status was set to not published.');
}
}

View File

@@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
namespace Drupal\Tests\action\Unit\Menu;
use Drupal\Tests\Core\Menu\LocalTaskIntegrationTestBase;
/**
* Tests action local tasks.
*
* @group action
* @group legacy
*/
class ActionLocalTasksTest extends LocalTaskIntegrationTestBase {
/**
* {@inheritdoc}
*/
protected function setUp(): void {
$this->directoryList = ['action' => 'core/modules/action'];
parent::setUp();
}
/**
* Tests local task existence.
*/
public function testActionLocalTasks(): void {
$this->assertLocalTasks('entity.action.collection', [['action.admin']]);
}
}