class GranularityServiceTest in Duration Field 8.2
Same name and namespace in other branches
- 3.0.x tests/src/Unit/Service/GranularityServiceTest.php \Drupal\Tests\duration_field\Unit\Service\GranularityServiceTest
@coversDefaultClass \Drupal\duration_field\Service\GranularityService @group duration_field
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\duration_field\Unit\Service\GranularityServiceTest
Expanded class hierarchy of GranularityServiceTest
File
- tests/
src/ Unit/ Service/ GranularityServiceTest.php, line 11
Namespace
Drupal\Tests\duration_field\Unit\ServiceView source
class GranularityServiceTest extends UnitTestCase {
/**
* @covers ::convertGranularityArrayToGranularityString
* @dataProvider convertGranularityArrayToGranularityStringDataProvider
*/
public function testconvertGranularityArrayToGranularityString($input, $expectedResponse, $message) {
$service = new GranularityService();
$result = $service
->convertGranularityArrayToGranularityString($input);
$this
->assertSame($result, $expectedResponse, $message);
}
/**
* Data provider for testconvertGranularityArrayToGranularityString().
*/
public function convertGranularityArrayToGranularityStringDataProvider() {
return [
[
[
'y' => TRUE,
'm' => TRUE,
'd' => TRUE,
'h' => TRUE,
'i' => TRUE,
's' => TRUE,
],
'y:m:d:h:i:s',
'A full granularity array was converted to a granularity string',
],
[
[
'y' => TRUE,
'm' => FALSE,
'd' => TRUE,
'h' => FALSE,
'i' => TRUE,
's' => FALSE,
],
'y:d:i',
'A granularity array was correctly converted to the granularity string y:d:i',
],
[
[
'y' => FALSE,
'm' => FALSE,
'd' => FALSE,
'h' => FALSE,
'i' => FALSE,
's' => FALSE,
],
'',
'An empty granularity array was correctly converted to an empty granularity string',
],
];
}
/**
* @covers ::convertGranularityStringToGranularityArray
* @dataProvider convertGranularityStringToGranularityArrayDataProvider
*/
public function testconvertGranularityStringToGranularityArray($input, $expectedResponse, $message) {
$service = new GranularityService();
$result = $service
->convertGranularityStringToGranularityArray($input);
$this
->assertSame($result, $expectedResponse, $message);
}
/**
* Data provider for testconvertGranularityStringToGranularityArray().
*/
public function convertGranularityStringToGranularityArrayDataProvider() {
return [
[
'y:m:d:h:i:s',
[
'y' => TRUE,
'm' => TRUE,
'd' => TRUE,
'h' => TRUE,
'i' => TRUE,
's' => TRUE,
],
'A full granularity string was converted to a full granularity array',
],
[
'y:d:i',
[
'y' => TRUE,
'm' => FALSE,
'd' => TRUE,
'h' => FALSE,
'i' => TRUE,
's' => FALSE,
],
'A partial granularity string y:d:i was correctly converted to a granularity array',
],
[
'',
[
'y' => FALSE,
'm' => FALSE,
'd' => FALSE,
'h' => FALSE,
'i' => FALSE,
's' => FALSE,
],
'An empty granularity string was correctly converted to an empty granularity array',
],
];
}
/**
* @covers ::includeGranularityElement
* @dataProvider includeGranularityElementDataProvider
*/
public function testincludeGranularityElement($input, $expectedResponse, $message) {
$service = new GranularityService();
$result = $service
->includeGranularityElement($input['granularity_element'], $input['granularity_string']);
$this
->assertSame($result, $expectedResponse, $message);
}
/**
* Data provider for testincludeGranularityElement().
*/
public function includeGranularityElementDataProvider() {
return [
[
[
'granularity_element' => 'y',
'granularity_string' => 'y:m:d:h:i:s',
],
TRUE,
'y correctly returned TRUE when it is supposed to be included',
],
[
[
'granularity_element' => 'y',
'granularity_string' => 'm:d:h:i:s',
],
FALSE,
'y correctly returned FALSE when it is not supposed to be included',
],
[
[
'granularity_element' => 'm',
'granularity_string' => 'y:m:d:h:i:s',
],
TRUE,
'm correctly returned TRUE when it is supposed to be included',
],
[
[
'granularity_element' => 'm',
'granularity_string' => 'y:d:h:i:s',
],
FALSE,
'm correctly returned FALSE when it is not supposed to be included',
],
[
[
'granularity_element' => 'd',
'granularity_string' => 'y:m:d:h:i:s',
],
TRUE,
'd correctly returned TRUE when it is supposed to be included',
],
[
[
'granularity_element' => 'd',
'granularity_string' => 'y:m:h:i:s',
],
FALSE,
'y correctly returned FALSE when it is not supposed to be included',
],
[
[
'granularity_element' => 'h',
'granularity_string' => 'y:m:d:h:i:s',
],
TRUE,
'h correctly returned TRUE when it is supposed to be included',
],
[
[
'granularity_element' => 'h',
'granularity_string' => 'm:d:i:s',
],
FALSE,
'h correctly returned FALSE when it is not supposed to be included',
],
[
[
'granularity_element' => 'i',
'granularity_string' => 'y:m:d:h:i:s',
],
TRUE,
'i correctly returned TRUE when it is supposed to be included',
],
[
[
'granularity_element' => 'i',
'granularity_string' => 'm:d:h:s',
],
FALSE,
'y correctly returned FALSE when it is not supposed to be included',
],
[
[
'granularity_element' => 's',
'granularity_string' => 'y:m:d:h:i:s',
],
TRUE,
's correctly returned TRUE when it is supposed to be included',
],
[
[
'granularity_element' => 'y',
'granularity_string' => 'm:d:h:i',
],
FALSE,
'y correctly returned FALSE when it is not supposed to be included',
],
];
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
GranularityServiceTest:: |
public | function | Data provider for testconvertGranularityArrayToGranularityString(). | |
GranularityServiceTest:: |
public | function | Data provider for testconvertGranularityStringToGranularityArray(). | |
GranularityServiceTest:: |
public | function | Data provider for testincludeGranularityElement(). | |
GranularityServiceTest:: |
public | function | @covers ::convertGranularityArrayToGranularityString @dataProvider convertGranularityArrayToGranularityStringDataProvider | |
GranularityServiceTest:: |
public | function | @covers ::convertGranularityStringToGranularityArray @dataProvider convertGranularityStringToGranularityArrayDataProvider | |
GranularityServiceTest:: |
public | function | @covers ::includeGranularityElement @dataProvider includeGranularityElementDataProvider | |
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. | |
UnitTestCase:: |
protected | function | 340 |