abstract class BaseFieldDefinitionTestBase in Drupal 8
Same name and namespace in other branches
- 9 core/tests/Drupal/Tests/Core/Field/BaseFieldDefinitionTestBase.php \Drupal\Tests\Core\Field\BaseFieldDefinitionTestBase
- 10 core/tests/Drupal/Tests/Core/Field/BaseFieldDefinitionTestBase.php \Drupal\Tests\Core\Field\BaseFieldDefinitionTestBase
Provides setup method for testing base field definitions.
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\Core\Field\BaseFieldDefinitionTestBase
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 14
Namespace
Drupal\Tests\Core\FieldView source
abstract class BaseFieldDefinitionTestBase extends UnitTestCase {
/**
* The field definition used in this test.
*
* @var \Drupal\Core\Field\BaseFieldDefinition
*/
protected $definition;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// getModuleAndPath() returns an array of the module name and directory.
list($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)
->will($this
->returnValue(TRUE));
$typed_data_manager = $this
->createMock(TypedDataManagerInterface::class);
$plugin_manager = new FieldTypePluginManager($namespaces, $this
->createMock('Drupal\\Core\\Cache\\CacheBackendInterface'), $module_handler, $typed_data_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.
*
* Function 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'.
*/
protected abstract function getModuleAndPath();
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BaseFieldDefinitionTestBase:: |
protected | property | The field definition used in this test. | |
BaseFieldDefinitionTestBase:: |
abstract protected | function | Returns the module name and the module directory for the plugin. | 1 |
BaseFieldDefinitionTestBase:: |
abstract protected | function | Returns the plugin ID of the tested field type. | 1 |
BaseFieldDefinitionTestBase:: |
protected | function |
Overrides UnitTestCase:: |
|
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |