diff --git a/core/tests/Drupal/Tests/Core/Field/BaseFieldDefinitionTestBase.php b/core/tests/Drupal/Tests/Core/Field/BaseFieldDefinitionTestBase.php new file mode 100644 index 0000000..a69f98e --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Field/BaseFieldDefinitionTestBase.php @@ -0,0 +1,79 @@ +getModuleAndPath(); + + $namespaces = new \ArrayObject(); + $namespaces["Drupal\\$module_name"] = $module_dir . '/src'; + + $module_handler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface'); + $module_handler->expects($this->once()) + ->method('moduleExists') + ->with($module_name) + ->will($this->returnValue(TRUE)); + $plugin_manager = new FieldTypePluginManager( + $namespaces, + $this->getMock('Drupal\Core\Cache\CacheBackendInterface'), + $module_handler + ); + + $container = new ContainerBuilder(); + $container->set('plugin.manager.field.field_type', $plugin_manager); + // The 'string_translation' service is used by the @Translation annotation. + $container->set('string_translation', $this->getStringTranslationStub()); + \Drupal::setContainer($container); + + $this->definition = BaseFieldDefinition::create($this->getPluginId()); + } + + /** + * Returns the plugin ID of the tested field type. + * + * @return string + * The plugin ID. + */ + abstract protected function getPluginId(); + + /** + * Returns the module name and the module directory for the plugin. + * + * drupal_get_path() cannot be used here, because it is not available in + * Drupal PHPUnit tests. + * + * @return array + * A one-dimensional array containing the following strings: + * - The module name. + * - The module directory, e.g. DRUPAL_CORE . 'core/modules/path'. + */ + abstract protected function getModuleAndPath(); + +} diff --git a/core/tests/Drupal/Tests/Core/Field/FieldDefinitionTestBase.php b/core/tests/Drupal/Tests/Core/Field/FieldDefinitionTestBase.php deleted file mode 100644 index a69f98e..0000000 --- a/core/tests/Drupal/Tests/Core/Field/FieldDefinitionTestBase.php +++ /dev/null @@ -1,79 +0,0 @@ -getModuleAndPath(); - - $namespaces = new \ArrayObject(); - $namespaces["Drupal\\$module_name"] = $module_dir . '/src'; - - $module_handler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface'); - $module_handler->expects($this->once()) - ->method('moduleExists') - ->with($module_name) - ->will($this->returnValue(TRUE)); - $plugin_manager = new FieldTypePluginManager( - $namespaces, - $this->getMock('Drupal\Core\Cache\CacheBackendInterface'), - $module_handler - ); - - $container = new ContainerBuilder(); - $container->set('plugin.manager.field.field_type', $plugin_manager); - // The 'string_translation' service is used by the @Translation annotation. - $container->set('string_translation', $this->getStringTranslationStub()); - \Drupal::setContainer($container); - - $this->definition = BaseFieldDefinition::create($this->getPluginId()); - } - - /** - * Returns the plugin ID of the tested field type. - * - * @return string - * The plugin ID. - */ - abstract protected function getPluginId(); - - /** - * Returns the module name and the module directory for the plugin. - * - * drupal_get_path() cannot be used here, because it is not available in - * Drupal PHPUnit tests. - * - * @return array - * A one-dimensional array containing the following strings: - * - The module name. - * - The module directory, e.g. DRUPAL_CORE . 'core/modules/path'. - */ - abstract protected function getModuleAndPath(); - -}