class FreelinkingPrepopulateTest in Freelinking 8.3
Same name in this branch
- 8.3 modules/freelinking_prepopulate/tests/src/Functional/FreelinkingPrepopulateTest.php \Drupal\Tests\freelinking_prepopulate\Functional\FreelinkingPrepopulateTest
- 8.3 modules/freelinking_prepopulate/tests/src/Unit/Plugin/freelinking/FreelinkingPrepopulateTest.php \Drupal\Tests\freelinking_prepopulate\Unit\Plugin\freelinking\FreelinkingPrepopulateTest
Same name and namespace in other branches
- 4.0.x modules/freelinking_prepopulate/tests/src/Unit/Plugin/freelinking/FreelinkingPrepopulateTest.php \Drupal\Tests\freelinking_prepopulate\Unit\Plugin\freelinking\FreelinkingPrepopulateTest
Tests FreelinkingPrepopulate freelinking plugin.
@group freelinking_prepopulate
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\freelinking_prepopulate\Unit\Plugin\freelinking\FreelinkingPrepopulateTest
Expanded class hierarchy of FreelinkingPrepopulateTest
File
- modules/
freelinking_prepopulate/ tests/ src/ Unit/ Plugin/ freelinking/ FreelinkingPrepopulateTest.php, line 14
Namespace
Drupal\Tests\freelinking_prepopulate\Unit\Plugin\freelinkingView source
class FreelinkingPrepopulateTest extends UnitTestCase {
/**
* {@inheritdoc}
*/
protected function setUp() {
// Mocks returning content types.
$nodeTypeProphet = $this
->prophesize('\\Drupal\\Core\\Entity\\EntityInterface');
$nodeTypeProphet
->id()
->willReturn('page');
$nodeTypeStorageProphet = $this
->prophesize('\\Drupal\\Core\\Config\\Entity\\ConfigEntityStorageInterface');
$nodeTypeStorageProphet
->loadMultiple()
->willReturn([
'page' => $nodeTypeProphet
->reveal(),
]);
// Mocks the entity type manager.
$entityTypeManagerProphet = $this
->prophesize('\\Drupal\\Core\\Entity\\EntityTypeManagerInterface');
$entityTypeManagerProphet
->getStorage('node_type')
->willReturn($nodeTypeStorageProphet
->reveal());
$entityTypeManager = $entityTypeManagerProphet
->reveal();
// Mocks the entity field manager.
$entityFieldManagerProphet = $this
->prophesize('\\Drupal\\Core\\Entity\\EntityFieldManagerInterface');
$entityFieldManagerProphet
->getFieldDefinitions('node', 'page');
// Mocks the module handler interface.
$moduleHandlerProphet = $this
->prophesize('\\Drupal\\Core\\Extension\\ModuleHandlerInterface');
$container = new ContainerBuilder();
$container
->set('entity_type.manager', $entityTypeManager);
$container
->set('entity_field.manager', $entityFieldManagerProphet
->reveal());
$container
->set('module_handler', $moduleHandlerProphet
->reveal());
\Drupal::setContainer($container);
}
/**
* Asserts that the configuration is returned based on initial state.
*
* @param array $configuration
* The initial plugin configuration.
* @param array $expected
* The expected return value.
*
* @dataProvider configurationProvider
*/
public function testGetConfiguration(array $configuration, array $expected) {
$definition = [
'id' => 'freelinking_prepopulate',
'title' => 'Prepopulate',
'settings' => [
'default_node_type' => 'page',
'advanced' => [
'title' => '0',
],
'failover' => 'search',
],
];
$plugin = FreelinkingPrepopulate::create(\Drupal::getContainer(), $configuration, 'freelinking_prepopulate', $definition);
$this
->assertEquals($expected, $plugin
->getConfiguration());
}
/**
* Gets test arguments for testGetConfiguration.
*
* @return array
* An array of test arguments.
*/
public function configurationProvider() {
return [
'empty configuration provided' => [
[],
[
'settings' => [
'default_node_type' => 'page',
'advanced' => [
'title' => FALSE,
],
'failover' => 'search',
],
],
],
'empty settings provided' => [
[
'settings' => [],
],
[
'settings' => [
'default_node_type' => 'page',
'advanced' => [
'title' => FALSE,
],
'failover' => 'search',
],
],
],
'failover setting provided' => [
[
'settings' => [
'failover' => 'error',
],
],
[
'settings' => [
'default_node_type' => 'page',
'advanced' => [
'title' => FALSE,
],
'failover' => 'error',
],
],
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FreelinkingPrepopulateTest:: |
public | function | Gets test arguments for testGetConfiguration. | |
FreelinkingPrepopulateTest:: |
protected | function |
Overrides UnitTestCase:: |
|
FreelinkingPrepopulateTest:: |
public | function | Asserts that the configuration is returned based on initial state. | |
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. |