Skip to content
Snippets Groups Projects
Commit b3b4ab7e authored by Jonathan Smith's avatar Jonathan Smith
Browse files

Issue #3443183 by jonathan1055, alt36, sense-design: Call to non-existent...

Issue #3443183 by jonathan1055, alt36, sense-design: Call to non-existent token.entity_mapper service when Token is not installed
parent e9a6e5cc
No related branches found
No related tags found
1 merge request!135#3443183 Token entity mapper may not exist
Pipeline #159020 passed
......@@ -127,18 +127,20 @@ phpunit:
- |
printf "_MATRIX_VALUE = %s\n" $_MATRIX_VALUE &&
printf "_PHPUNIT_CONCURRENT = %s\n" $_PHPUNIT_CONCURRENT &&
printf "_PHPUNIT_TESTGROUPS = %s\n" $_PHPUNIT_TESTGROUPS &&
printf "_PHPUNIT_EXTRA = %s\n" $_PHPUNIT_EXTRA &&
printf "_PHPUNIT_TESTGROUPS = %s\n" "$_PHPUNIT_TESTGROUPS" &&
printf "_PHPUNIT_EXTRA = %s\n" "$_PHPUNIT_EXTRA" &&
printf "SYMFONY_DEPRECATIONS_HELPER = %s\n" $SYMFONY_DEPRECATIONS_HELPER
- |
if [[ "$_PHPUNIT_CONCURRENT" == "0" ]]; then
# Specify parameters that will be passed to PHPUNIT (needs --group)
export _PHPUNIT_EXTRA="$_PHPUNIT_EXTRA --group $_MATRIX_VALUE"
else
# Specify parameters that will be passed to RUN-TESTS.SH (without --group)
export _PHPUNIT_EXTRA="$_PHPUNIT_EXTRA $_MATRIX_VALUE"
# Ensure the value is 1 if it is not 0.
export _PHPUNIT_CONCURRENT=1
if [[ "$_MATRIX_VALUE" != "" ]]; then
if [[ "$_PHPUNIT_CONCURRENT" == "0" ]]; then
# Specify parameters that will be passed to PHPUNIT (needs --group)
export _PHPUNIT_EXTRA="$_PHPUNIT_EXTRA --group $_MATRIX_VALUE"
else
# Specify parameters that will be passed to RUN-TESTS.SH (without --group)
export _PHPUNIT_EXTRA="$_PHPUNIT_EXTRA $_MATRIX_VALUE"
# Ensure the value is 1 if it is not 0.
export _PHPUNIT_CONCURRENT=1
fi
fi
- echo "End of before_script _PHPUNIT_CONCURRENT=$_PHPUNIT_CONCURRENT _PHPUNIT_EXTRA=$_PHPUNIT_EXTRA"
......
......@@ -16,12 +16,16 @@ function _scheduler_token_types() {
return $token_types;
}
$plugin_types = \Drupal::service('scheduler.manager')->getPluginEntityTypes();
// This function should only get executed if the Token module is enabled,
// therefore we can assume the token.entity_mapper service exists without
// having to check for it.
foreach ($plugin_types as $type) {
$token_type = \Drupal::service('token.entity_mapper')->getTokenTypeForEntityType($type, TRUE);
$token_types[] = $token_type;
// Derive the token type id from the entity type id. Use second parameter TRUE
// to fall back to the input value if the mapping is not found. If the token
// module is not enabled then use the entity type id.
if (\Drupal::getContainer()->has('token.entity_mapper')) {
foreach ($plugin_types as $type) {
$token_types[] = \Drupal::service('token.entity_mapper')->getTokenTypeForEntityType($type, TRUE);
}
}
else {
$token_types = $plugin_types;
}
return $token_types;
}
......
......@@ -72,6 +72,26 @@ class SchedulerTokenReplaceTest extends SchedulerBrowserTestBase {
}
}
/**
* Test when token module is not installed.
*
* @see https://www.drupal.org/project/scheduler/issues/3443183
*
* @dataProvider dataSchedulerWithoutTokenModule()
*/
public function testSchedulerWithoutTokenModule($entityTypeId, $bundle) {
// This test is not run for commerce products because that module requires
// the token module, so it has to be uninstalled too.
$this->container->get('module_installer')->uninstall(['commerce_product']);
$this->container->get('module_installer')->uninstall(['token']);
$this->drupalLogin($this->schedulerUser);
// Check that the entity add page can be accessed successfully, so show that
// the token.entity_mapper service is avoided when not available.
$this->drupalGet($this->entityAddUrl($entityTypeId, $bundle));
$this->assertSession()->statusCodeEquals(200);
}
/**
* Provides test data for TokenReplacement test.
*
......@@ -86,4 +106,16 @@ class SchedulerTokenReplaceTest extends SchedulerBrowserTestBase {
return $data;
}
/**
* Provides test data for testing without the Token module.
*
* @return array
* Each array item has the values: [entity type id, bundle id].
*/
public function dataSchedulerWithoutTokenModule() {
$data = $this->dataStandardEntityTypes();
unset($data['#commerce_product']);
return $data;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment