diff --git a/core/modules/filter/lib/Drupal/filter/Tests/DefaultConfig.php b/core/modules/filter/lib/Drupal/filter/Tests/DefaultConfig.php new file mode 100644 index 0000000..23e9ee7 --- /dev/null +++ b/core/modules/filter/lib/Drupal/filter/Tests/DefaultConfig.php @@ -0,0 +1,71 @@ +test = $test; + } + + function createFormat($config) { + $format = (object) $config; + filter_format_save($format); + $this->formats[$format->format] = $format; + return $format; + } + + function grantFormatAccess($rid, $format) { + $permission = filter_permission_name($format); + user_role_grant_permissions($rid, array($permission)); + } + + function givenFilteredHtmlFormat() { + $filtered_html_format = array( + 'format' => 'filtered_html', + 'name' => 'Filtered HTML', + 'weight' => 0, + 'filters' => array( + // URL filter. + 'filter_url' => array( + 'weight' => 0, + 'status' => 1, + ), + // HTML filter. + 'filter_html' => array( + 'weight' => 1, + 'status' => 1, + ), + // Line break filter. + 'filter_autop' => array( + 'weight' => 2, + 'status' => 1, + ), + // HTML corrector filter. + 'filter_htmlcorrector' => array( + 'weight' => 10, + 'status' => 1, + ), + ), + ); + return $this->createFormat($filtered_html_format); + } + + function whenFilteredHtmlFormatAnonymousAccess() { + if (empty($this->formats['filtered_html'])) { + $this->givenFilteredHtmlFormat(); + } + debug("CHECK"); + $this->grantFormatAccess(DRUPAL_ANONYMOUS_RID, $this->formats['filtered_html']); + } +} + diff --git a/core/modules/node/node.test b/core/modules/node/node.test index 655bc0b..ffd3abe 100644 --- a/core/modules/node/node.test +++ b/core/modules/node/node.test @@ -567,6 +567,13 @@ class PageViewTestCase extends NodeWebTestCase { ); } + function setUp() { + parent::setUp(); + $this->config + ->givenFilteredHtmlFormat() + ->whenFilteredHtmlFormatAnonymousAccess(); + } + /** * Creates a node and then an anonymous and unpermissioned user attempt to edit the node. */ diff --git a/core/modules/simpletest/drupal_web_test_case.php b/core/modules/simpletest/drupal_web_test_case.php index 540dc0e..49d2f7e 100644 --- a/core/modules/simpletest/drupal_web_test_case.php +++ b/core/modules/simpletest/drupal_web_test_case.php @@ -759,6 +759,28 @@ class DrupalUnitTestCase extends DrupalTestCase { } } +class DrupalTestingConfigContainer { + protected $services = array(); + + function register($module, $instance) { + $this->services[$module] = $instance; + } + + function __call($name, $args) { + $found = FALSE; + foreach ($this->services as $instance) { + if (method_exists($instance, $name)) { + $found = TRUE; + call_user_func_array(array($instance, $name), $args); + } + } + if (!$found) { + throw new InvalidArgumentException('Call to undefined configuration method: ' . $name); + } + return $this; + } +} + /** * Test case for typical Drupal tests. */ @@ -1026,6 +1048,55 @@ class DrupalWebTestCase extends DrupalTestCase { } /** + * Creates default testing configuration for the specified modules, if available. + * + * @param array $modules + * A list of module names, for which corresponding default testing + * configuration is installed from the ./config_test sub-directory and + * additional configuration may be performed via hook_testing_install(). + * Note that configuration may depend on other and dependencies are not + * automatically resolved; pass dependent module names first; e.g., + * array('node', 'rdf'). + * + * @todo Add support for default configuration "versions". Later. + */ + protected function drupalCreateConfig(array $modules) { + $this->config = new DrupalTestingConfigContainer($this); + + $configured_modules = array(); + foreach ($modules as $module) { + // @todo Import testing configuration from ./config_test, if any. + // Though, speaking of dependencies in phpDoc above, default config of + // one module may depend on default config of another module and thus + // would need conditional logic; perhaps this doesn't make sense after all. + + // Perform additional testing configuration actions via + // hook_testing_install(), if defined. + // @todo Consider usage of module_implements() for sorted implementations + // here; but still requires to load .install files first (which may be + // loaded during setUp(), but not necessarily after). + module_load_install($module); + $function = $module . '_testing_install'; + if (function_exists($function)) { + $function(); + $configured_modules[] = $module; + } + $class = "Drupal\\$module\\Tests\\DefaultConfig"; + if (class_exists($class)) { + $this->config->register($module, new $class($this)); + } + } + + if (!empty($configured_modules)) { + // Ensure that all configuration changes are taken over in the parent site + // and child site. + $this->resetAll(); + + $this->pass(t('Created test configuration for %modules.', array('%modules' => implode(', ', $configured_modules)))); + } + } + + /** * Get a list files that can be used in tests. * * @param $type @@ -1408,6 +1479,9 @@ class DrupalWebTestCase extends DrupalTestCase { if (isset($modules[0]) && is_array($modules[0])) { $modules = $modules[0]; } + // Installation profile module dependencies are installed already, but might + // have been additionally specified in $modules; exclude them. + $modules = array_diff($modules, $profile_details['dependencies']); if ($modules) { $success = module_enable($modules, TRUE); $this->assertTrue($success, t('Enabled modules: %modules', array('%modules' => implode(', ', $modules)))); @@ -1445,6 +1519,18 @@ class DrupalWebTestCase extends DrupalTestCase { // Use the test mail class instead of the default mail handler class. variable_set('mail_system', array('default-system' => 'Drupal\Core\Mail\VariableLog')); + // Setup default testing configuration for all installed modules. + // Testing configuration is only installed for tests using the Testing + // installation profile. All other installation profiles may pre-configure + // modules already, and injecting any additional configuration would break + // functional/behavior tests on custom sites. + // @todo Must provide a way to specify modules to exclude (which will be + // manually configured in the test). $this->skipConfigurations? + // @todo Order by module dependencies. + if ($this->profile === 'testing') { + $this->drupalCreateConfig(array_merge($profile_details['dependencies'], $modules)); + } + drupal_set_time_limit($this->timeLimit); $this->setup = TRUE; } diff --git a/core/modules/user/user.test b/core/modules/user/user.test index c911088..fd811f8 100644 --- a/core/modules/user/user.test +++ b/core/modules/user/user.test @@ -1873,33 +1873,14 @@ class UserSignatureTestCase extends DrupalWebTestCase { // Prefetch and create text formats. $this->plain_text_format = filter_format_load('plain_text'); - - $filtered_html_format = array( - 'format' => 'filtered_html', - 'name' => 'Filtered HTML', - ); - $this->filtered_html_format = (object) $filtered_html_format; - filter_format_save($this->filtered_html_format); - - $full_html_format = array( - 'format' => 'full_html', - 'name' => 'Full HTML', - ); - $this->full_html_format = (object) $full_html_format; - filter_format_save($this->full_html_format); - - user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array(filter_permission_name($this->filtered_html_format))); - $this->checkPermissions(array(), TRUE); + $this->filtered_html_format = filter_format_load('filtered_html'); + $this->full_html_format = filter_format_load('full_html'); // Create regular and administrative users. $this->web_user = $this->drupalCreateUser(array('post comments')); $admin_permissions = array('administer comments'); - foreach (filter_formats() as $format) { - if ($permission = filter_permission_name($format)) { - $admin_permissions[] = $permission; - } - } + $admin_permissions[] = filter_permission_name($this->full_html_format); $this->admin_user = $this->drupalCreateUser($admin_permissions); }