/**
  * 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.');
 }
 /**
  * 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'));
 }
 /**
  * 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 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.');
 }
 /**
  * Tests comment publish and unpublish actions.
  */
 function testCommentPublishUnpublishActions()
 {
     $this->drupalLogin($this->webUser);
     $comment_text = $this->randomMachineName();
     $subject = $this->randomMachineName();
     $comment = $this->postComment($this->node, $comment_text, $subject);
     // Unpublish a comment.
     $action = Action::load('comment_unpublish_action');
     $action->execute(array($comment));
     $this->assertTrue($comment->isPublished() === FALSE, 'Comment was unpublished');
     // Publish a comment.
     $action = Action::load('comment_publish_action');
     $action->execute(array($comment));
     $this->assertTrue($comment->isPublished() === TRUE, 'Comment was published');
 }