class BaseFieldDefinitionTestBase

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Field/BaseFieldDefinitionTestBase.php \Drupal\Tests\Core\Field\BaseFieldDefinitionTestBase
  2. 8.9.x core/tests/Drupal/Tests/Core/Field/BaseFieldDefinitionTestBase.php \Drupal\Tests\Core\Field\BaseFieldDefinitionTestBase
  3. 11.x core/tests/Drupal/Tests/Core/Field/BaseFieldDefinitionTestBase.php \Drupal\Tests\Core\Field\BaseFieldDefinitionTestBase

Provides setup method for testing base field definitions.

Hierarchy

Expanded class hierarchy of BaseFieldDefinitionTestBase

1 file declares its use of BaseFieldDefinitionTestBase
PathFieldDefinitionTest.php in core/modules/path/tests/src/Unit/Field/PathFieldDefinitionTest.php

File

core/tests/Drupal/Tests/Core/Field/BaseFieldDefinitionTestBase.php, line 17

Namespace

Drupal\Tests\Core\Field
View source
abstract class BaseFieldDefinitionTestBase extends UnitTestCase {
    
    /**
     * The field definition used in this test.
     *
     * @var \Drupal\Core\Field\BaseFieldDefinition
     */
    protected $definition;
    
    /**
     * {@inheritdoc}
     */
    protected function setUp() : void {
        parent::setUp();
        // getModuleAndPath() returns an array of the module name and directory.
        [
            $module_name,
            $module_dir,
        ] = $this->getModuleAndPath();
        $namespaces = new \ArrayObject();
        $namespaces["Drupal\\{$module_name}"] = $module_dir . '/src';
        $module_handler = $this->createMock('Drupal\\Core\\Extension\\ModuleHandlerInterface');
        $module_handler->expects($this->once())
            ->method('moduleExists')
            ->with($module_name)
            ->willReturn(TRUE);
        $typed_data_manager = $this->createMock(TypedDataManagerInterface::class);
        $field_type_category_manager = $this->createMock(FieldTypeCategoryManagerInterface::class);
        $plugin_manager = new FieldTypePluginManager($namespaces, $this->createMock('Drupal\\Core\\Cache\\CacheBackendInterface'), $module_handler, $typed_data_manager, $field_type_category_manager);
        $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.
     */
    protected abstract function getPluginId();
    
    /**
     * Returns the module name and the module directory for the plugin.
     *
     * @return array
     *   A one-dimensional array containing the following strings:
     *   - The module name.
     *   - The module directory, e.g. DRUPAL_CORE . 'core/modules/path'.
     */
    protected abstract function getModuleAndPath();

}

Members

Title Sort descending Deprecated Modifiers Object type Summary Overriden Title Overrides
BaseFieldDefinitionTestBase::$definition protected property The field definition used in this test.
BaseFieldDefinitionTestBase::getModuleAndPath abstract protected function Returns the module name and the module directory for the plugin. 1
BaseFieldDefinitionTestBase::getPluginId abstract protected function Returns the plugin ID of the tested field type. 1
BaseFieldDefinitionTestBase::setUp protected function Overrides UnitTestCase::setUp
PhpUnitWarnings::$deprecationWarnings private static property Deprecation warnings from PHPUnit to raise with @trigger_error().
PhpUnitWarnings::addWarning public function Converts PHPUnit deprecation warnings to E_USER_DEPRECATED.
RandomGeneratorTrait::getRandomGenerator protected function Gets the random generator for the utility methods.
RandomGeneratorTrait::randomMachineName protected function Generates a unique random string containing letters and numbers.
RandomGeneratorTrait::randomObject public function Generates a random PHP object.
RandomGeneratorTrait::randomString public function Generates a pseudo-random string of ASCII characters of codes 32 to 126.
RandomGeneratorTrait::randomStringValidate Deprecated public function Callback for random string validation.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::setUpBeforeClass public static function
UnitTestCase::__get public function

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.