class ProviderManagerTest in Video Embed Field 8
Same name and namespace in other branches
- 8.2 tests/src/Unit/ProviderManagerTest.php \Drupal\Tests\video_embed_field\Unit\ProviderManagerTest
Tests the provider manager is working.
@group video_embed_field
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\video_embed_field\Unit\ProviderManagerTest
Expanded class hierarchy of ProviderManagerTest
File
- tests/
src/ Unit/ ProviderManagerTest.php, line 12
Namespace
Drupal\Tests\video_embed_field\UnitView source
class ProviderManagerTest extends UnitTestCase {
/**
* Mock providers to use for the test.
*
* @var array
*/
protected $mockProviders = [
'provider_a' => [
'id' => 'provider_a',
'title' => 'Provider A',
],
'provider_b' => [
'id' => 'provider_b',
'title' => 'Provider B',
],
'provider_c' => [
'id' => 'provider_c',
'title' => 'Provider C',
],
];
/**
* Test URL parsing works as expected.
*/
public function testOptionsList() {
$options = $this
->getManagerMock()
->getProvidersOptionList();
$this
->assertEquals($options, [
'provider_a' => 'Provider A',
'provider_b' => 'Provider B',
'provider_c' => 'Provider C',
]);
}
/**
* Test filtering the definition list from user input via checkboxes.
*
* @dataProvider optionsWithExpectedProviders
*/
public function testDefinitionListFromOptionsList($user_input, $expected_providers) {
$this
->assertEquals($expected_providers, $this
->getManagerMock()
->loadDefinitionsFromOptionList($user_input));
}
/**
* A data provider for user input with expected filtered providers.
*
* @return array
* An array of test cases.
*/
public function optionsWithExpectedProviders() {
return [
'Empty input: all providers' => [
[],
$this->mockProviders,
],
'Empty checkbox input: all providers' => [
[
'provider_a' => '0',
'provider_b' => '0',
'provider_c' => '0',
],
$this->mockProviders,
],
'Some providers' => [
[
'provider_a' => '0',
'provider_b' => 'provider_b',
'provider_c' => 'provider_c',
],
[
'provider_b' => $this->mockProviders['provider_b'],
'provider_c' => $this->mockProviders['provider_c'],
],
],
'One provider' => [
[
'provider_a' => 'provider_a',
'provider_b' => '0',
'provider_c' => '0',
],
[
'provider_a' => $this->mockProviders['provider_a'],
],
],
];
}
/**
* Get a mock provider manager.
*/
protected function getManagerMock() {
$definitions = $this->mockProviders;
$manager = $this
->getMockBuilder('Drupal\\video_embed_field\\ProviderManager')
->disableOriginalConstructor()
->setMethods([
'getDefinitions',
'getDefinition',
'createInstance',
])
->getMock();
$manager
->method('getDefinitions')
->willReturn($definitions);
$manager
->method('getDefinition')
->willReturnCallback(function ($value) use ($definitions) {
return $definitions[$value];
});
$manager
->method('createInstance')
->willReturnCallback(function ($name) {
return (object) [
'id' => $name,
];
});
return $manager;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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. | |
ProviderManagerTest:: |
protected | property | Mock providers to use for the test. | |
ProviderManagerTest:: |
protected | function | Get a mock provider manager. | |
ProviderManagerTest:: |
public | function | A data provider for user input with expected filtered providers. | |
ProviderManagerTest:: |
public | function | Test filtering the definition list from user input via checkboxes. | |
ProviderManagerTest:: |
public | function | Test URL parsing works as expected. | |
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. | |
UnitTestCase:: |
protected | function | 340 |