/**
  * Tests install profile config changes.
  */
 function testInstallProfileConfigOverwrite()
 {
     $config_name = 'system.cron';
     // The expected configuration from the system module.
     $expected_original_data = array('threshold' => array('autorun' => 0, 'requirements_warning' => 172800, 'requirements_error' => 1209600));
     // The expected active configuration altered by the install profile.
     $expected_profile_data = array('threshold' => array('autorun' => 0, 'requirements_warning' => 259200, 'requirements_error' => 1209600));
     // Verify that the original data matches. We have to read the module config
     // file directly, because the install profile default system.cron.yml
     // configuration file was used to create the active configuration.
     $config_dir = drupal_get_path('module', 'system') . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY;
     $this->assertTrue(is_dir($config_dir));
     $source_storage = new FileStorage($config_dir);
     $data = $source_storage->read($config_name);
     $this->assertIdentical($data, $expected_original_data);
     // Verify that active configuration matches the expected data, which was
     // created from the testing install profile's system.cron.yml file.
     $config = $this->config($config_name);
     $this->assertIdentical($config->get(), $expected_profile_data);
     // Ensure that the configuration entity has the expected dependencies and
     // overrides.
     $action = Action::load('user_block_user_action');
     $this->assertEqual($action->label(), 'Overridden block the selected user(s)');
     $action = Action::load('user_cancel_user_action');
     $this->assertEqual($action->label(), 'Cancel the selected user account(s)', 'Default configuration that is not overridden is not affected.');
     // Ensure that optional configuration can be overridden.
     $tour = Tour::load('language');
     $this->assertEqual(count($tour->getTips()), 1, 'Optional configuration can be overridden. The language tour only has one tip');
     $tour = Tour::load('language-add');
     $this->assertEqual(count($tour->getTips()), 3, 'Optional configuration that is not overridden is not affected.');
     // Ensure that optional configuration from a profile is created if
     // dependencies are met.
     $this->assertEqual(Tour::load('testing_config_overrides')->label(), 'Config override test');
     // Ensure that optional configuration from a profile is not created if
     // dependencies are not met. Cannot use the entity system since the entity
     // type does not exist.
     $optional_dir = drupal_get_path('module', 'testing_config_overrides') . '/' . InstallStorage::CONFIG_OPTIONAL_DIRECTORY;
     $optional_storage = new FileStorage($optional_dir);
     foreach (['config_test.dynamic.dotted.default', 'config_test.dynamic.override', 'config_test.dynamic.override_unmet'] as $id) {
         $this->assertTrue(\Drupal::config($id)->isNew(), "The config_test entity {$id} contained in the profile's optional directory does not exist.");
         // Make that we don't get false positives from the assertion above.
         $this->assertTrue($optional_storage->exists($id), "The config_test entity {$id} does exist in the profile's optional directory.");
     }
     // Install the config_test module and ensure that the override from the
     // install profile is not used. Optional configuration can not override
     // configuration in a modules config/install directory.
     $this->container->get('module_installer')->install(['config_test']);
     $this->rebuildContainer();
     $config_test_storage = \Drupal::entityManager()->getStorage('config_test');
     $this->assertEqual($config_test_storage->load('dotted.default')->label(), 'Default', 'The config_test entity is not overridden by the profile optional configuration.');
     // Test that override of optional configuration does work.
     $this->assertEqual($config_test_storage->load('override')->label(), 'Override', 'The optional config_test entity is overridden by the profile optional configuration.');
     // Test that override of optional configuration which introduces an unmet
     // dependency does not get created.
     $this->assertNull($config_test_storage->load('override_unmet'), 'The optional config_test entity with unmet dependencies is not created.');
     // Installing dblog creates the optional configuration.
     $this->container->get('module_installer')->install(['dblog']);
     $this->rebuildContainer();
     $this->assertEqual($config_test_storage->load('override_unmet')->label(), 'Override', 'The optional config_test entity is overridden by the profile optional configuration and is installed when its dependencies are met.');
 }
 /**
  * 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());
 }
 /**
  * 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.
  */
 protected function assertEntity($id, $label, $type, $configuration)
 {
     $action = Action::load($id);
     $this->assertTrue($action instanceof Action);
     /** @var \Drupal\system\Entity\Action $action */
     $this->assertIdentical($id, $action->id());
     $this->assertIdentical($label, $action->label());
     $this->assertIdentical($type, $action->getType());
     $this->assertIdentical($configuration, $action->get('configuration'));
 }
Example #4
0
 /**
  * Tests configuration of advanced actions through administration interface.
  */
 function testActionConfiguration()
 {
     // Create a user with permission to view the actions administration pages.
     $user = $this->drupalCreateUser(array('administer actions'));
     $this->drupalLogin($user);
     // Make a POST request to admin/config/system/actions.
     $edit = array();
     $edit['action'] = Crypt::hashBase64('action_goto_action');
     $this->drupalPostForm('admin/config/system/actions', $edit, t('Create'));
     $this->assertResponse(200);
     // Make a POST request to the individual action configuration page.
     $edit = array();
     $action_label = $this->randomMachineName();
     $edit['label'] = $action_label;
     $edit['id'] = strtolower($action_label);
     $edit['url'] = 'admin';
     $this->drupalPostForm('admin/config/system/actions/add/' . Crypt::hashBase64('action_goto_action'), $edit, t('Save'));
     $this->assertResponse(200);
     // Make sure that the new complex action was saved properly.
     $this->assertText(t('The action has been successfully saved.'), "Make sure we get a confirmation that we've successfully saved the complex action.");
     $this->assertText($action_label, "Make sure the action label appears on the configuration page after we've saved the complex action.");
     // Make another POST request to the action edit page.
     $this->clickLink(t('Configure'));
     preg_match('|admin/config/system/actions/configure/(.+)|', $this->getUrl(), $matches);
     $aid = $matches[1];
     $edit = array();
     $new_action_label = $this->randomMachineName();
     $edit['label'] = $new_action_label;
     $edit['url'] = 'admin';
     $this->drupalPostForm(NULL, $edit, t('Save'));
     $this->assertResponse(200);
     // Make sure that the action updated properly.
     $this->assertText(t('The action has been successfully saved.'), "Make sure we get a confirmation that we've successfully updated the complex action.");
     $this->assertNoText($action_label, "Make sure the old action label does NOT appear on the configuration page after we've updated the complex action.");
     $this->assertText($new_action_label, "Make sure the action label appears on the configuration page after we've updated the complex action.");
     $this->clickLink(t('Configure'));
     $element = $this->xpath('//input[@type="text" and @value="admin"]');
     $this->assertTrue(!empty($element), 'Make sure the URL appears when re-editing the action.');
     // Make sure that deletions work properly.
     $this->drupalGet('admin/config/system/actions');
     $this->clickLink(t('Delete'));
     $this->assertResponse(200);
     $edit = array();
     $this->drupalPostForm("admin/config/system/actions/configure/{$aid}/delete", $edit, t('Delete'));
     $this->assertResponse(200);
     // Make sure that the action was actually deleted.
     $this->assertRaw(t('The action %action has been deleted.', array('%action' => $new_action_label)), 'Make sure that we get a delete confirmation message.');
     $this->drupalGet('admin/config/system/actions');
     $this->assertResponse(200);
     $this->assertNoText($new_action_label, "Make sure the action label does not appear on the overview page after we've deleted the action.");
     $action = Action::load($aid);
     $this->assertFalse($action, 'Make sure the action is gone after being deleted.');
 }
 /**
  * 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);
 }
Example #6
0
 /**
  * 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.');
 }
 /**
  * Tests configuration of the node_assign_owner_action action.
  */
 public function testAssignOwnerNodeActionConfiguration()
 {
     // 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'] = Crypt::hashBase64('node_assign_owner_action');
     $this->drupalPostForm('admin/config/system/actions', $edit, t('Create'));
     $this->assertResponse(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->drupalPostForm('admin/config/system/actions/add/' . Crypt::hashBase64('node_assign_owner_action'), $edit, t('Save'));
     $this->assertResponse(200);
     // Make sure that the new action was saved properly.
     $this->assertText(t('The action has been successfully saved.'), 'The node_assign_owner_action action has been successfully saved.');
     $this->assertText($action_label, 'The label of the node_assign_owner_action action appears on the actions administration page after saving.');
     // Make another POST request to the action edit page.
     $this->clickLink(t('Configure'));
     preg_match('|admin/config/system/actions/configure/(.+)|', $this->getUrl(), $matches);
     $aid = $matches[1];
     $edit = [];
     $new_action_label = $this->randomMachineName();
     $edit['label'] = $new_action_label;
     $edit['owner_uid'] = $user->id();
     $this->drupalPostForm(NULL, $edit, t('Save'));
     $this->assertResponse(200);
     // Make sure that the action updated properly.
     $this->assertText(t('The action has been successfully saved.'), 'The node_assign_owner_action action has been successfully updated.');
     $this->assertNoText($action_label, 'The old label for the node_assign_owner_action action does not appear on the actions administration page after updating.');
     $this->assertText($new_action_label, 'The new label for the node_assign_owner_action action appears on the actions administration page after updating.');
     // Make sure that deletions work properly.
     $this->drupalGet('admin/config/system/actions');
     $this->clickLink(t('Delete'));
     $this->assertResponse(200);
     $edit = [];
     $this->drupalPostForm("admin/config/system/actions/configure/{$aid}/delete", $edit, t('Delete'));
     $this->assertResponse(200);
     // Make sure that the action was actually deleted.
     $this->assertRaw(t('The action %action has been deleted.', ['%action' => $new_action_label]), 'The delete confirmation message appears after deleting the node_assign_owner_action action.');
     $this->drupalGet('admin/config/system/actions');
     $this->assertResponse(200);
     $this->assertNoText($new_action_label, 'The label for the node_assign_owner_action action does not appear on the actions administration page after deleting.');
     $action = Action::load($aid);
     $this->assertFalse($action, 'The node_assign_owner_action action is not available after being deleted.');
 }
 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();
 }