/** * Tests the dependency calculation of actions. */ public function testDependencies() { // Create a new action that depends on a user role. $action = Action::create(array('id' => 'user_add_role_action.' . RoleInterface::ANONYMOUS_ID, 'type' => 'user', 'label' => t('Add the anonymous role to the selected users'), 'configuration' => array('rid' => RoleInterface::ANONYMOUS_ID), 'plugin' => 'user_add_role_action')); $action->save(); $expected = array('config' => array('user.role.' . RoleInterface::ANONYMOUS_ID), 'module' => array('user')); $this->assertIdentical($expected, $action->calculateDependencies()->getDependencies()); }
/** * Tests updating a action during import. */ protected function doActionUpdate() { // Create a test action with a known label. $name = 'system.action.apple'; $entity = Action::create(array('id' => 'apple', 'plugin' => 'action_message_action')); $entity->save(); $this->checkSinglePluginConfigSync($entity, 'configuration', 'message', ''); // Read the existing data, and prepare an altered version in sync. $custom_data = $original_data = $this->container->get('config.storage')->read($name); $custom_data['configuration']['message'] = 'Granny Smith'; $this->assertConfigUpdateImport($name, $original_data, $custom_data); }
/** * Tests the unpublish comment by keyword action. */ function testCommentUnpublishByKeyword() { $this->drupalLogin($this->adminUser); $keyword_1 = $this->randomMachineName(); $keyword_2 = $this->randomMachineName(); $action = Action::create(array('id' => 'comment_unpublish_by_keyword_action', 'label' => $this->randomMachineName(), 'type' => 'comment', 'configuration' => array('keywords' => array($keyword_1, $keyword_2)), 'plugin' => 'comment_unpublish_by_keyword_action')); $action->save(); $comment = $this->postComment($this->node, $keyword_2, $this->randomMachineName()); // Load the full comment so that status is available. $comment = Comment::load($comment->id()); $this->assertTrue($comment->isPublished() === TRUE, 'The comment status was set to published.'); $action->execute(array($comment)); $this->assertTrue($comment->isPublished() === FALSE, 'The comment status was set to not published.'); }
public function testAction() { /** @var \Drupal\system\ActionConfigEntityInterface $action */ $action = Action::create(['id' => 'enhanced_entity_delete_action', 'label' => 'Delete enhanced entity', 'plugin' => 'entity_delete_action:entity_test_enhanced']); $status = $action->save(); $this->assertEquals(SAVED_NEW, $status); $this->assertInstanceOf(DeleteAction::class, $action->getPlugin()); $entities = []; for ($i = 0; $i < 2; $i++) { $entity = EnhancedEntity::create(['type' => 'default']); $entity->save(); $entities[$entity->id()] = $entity; } $action->execute($entities); // Confirm that the entity ids and langcodes are now in the tempstore. $tempstore = \Drupal::service('user.private_tempstore')->get('entity_delete_multiple_confirm'); $selection = $tempstore->get($this->user->id()); $this->assertEquals(array_keys($entities), array_keys($selection)); $this->assertEquals([['en' => 'en'], ['en' => 'en']], array_values($selection)); }
/** * Performs setup tasks before each individual test method is run. * * Installs commonly used schemas and sets up a search server and an index, * with the specified processor enabled. * * @param string|null $processor * (optional) The plugin ID of the processor that should be set up for * testing. */ public function setUp($processor = NULL) { parent::setUp(); $this->installSchema('node', array('node_access')); $this->installSchema('search_api', array('search_api_item', 'search_api_task')); $this->installEntitySchema('user'); $this->installEntitySchema('node'); $this->installEntitySchema('comment'); $this->installConfig(array('field')); Action::create(['id' => 'foo', 'label' => 'Foobaz', 'plugin' => 'comment_publish_action'])->save(); \Drupal::configFactory()->getEditable('search_api.settings')->set('tracking_page_size', 100)->save(); // Do not use a batch for tracking the initial items after creating an // index when running the tests via the GUI. Otherwise, it seems Drupal's // Batch API gets confused and the test fails. \Drupal::state()->set('search_api_use_tracking_batch', FALSE); $this->server = Server::create(array('id' => 'server', 'name' => 'Server & Name', 'status' => TRUE, 'backend' => 'search_api_db', 'backend_config' => array('min_chars' => 3, 'database' => 'default:default'))); $this->server->save(); $this->index = Index::create(array('id' => 'index', 'name' => 'Index name', 'status' => TRUE, 'datasource_settings' => array('entity:comment' => array('plugin_id' => 'entity:comment', 'settings' => array()), 'entity:node' => array('plugin_id' => 'entity:node', 'settings' => array())), 'server' => 'server', 'tracker_settings' => array('default' => array('plugin_id' => 'default', 'settings' => array())))); $this->index->setServer($this->server); $field_subject = new Field($this->index, 'subject'); $field_subject->setType('text'); $field_subject->setPropertyPath('subject'); $field_subject->setDatasourceId('entity:comment'); $field_subject->setLabel('Subject'); $field_title = new Field($this->index, 'title'); $field_title->setType('text'); $field_title->setPropertyPath('title'); $field_title->setDatasourceId('entity:node'); $field_title->setLabel('Title'); $this->index->addField($field_subject); $this->index->addField($field_title); if ($processor) { /** @var \Drupal\search_api\Processor\ProcessorPluginManager $plugin_manager */ $plugin_manager = \Drupal::service('plugin.manager.search_api.processor'); $this->processor = $plugin_manager->createInstance($processor, array('index' => $this->index)); $this->index->addProcessor($this->processor); } $this->index->save(); }
/** * Tests creating an action using the node_unpublish_by_keyword_action plugin. * * @see https://www.drupal.org/node/2578519 */ public function testUnpublishByKeywordAction() { Action::create(['id' => 'foo', 'label' => 'Foobaz', 'plugin' => 'node_unpublish_by_keyword_action'])->save(); }