class LengthIndicatorTest in Length Indicator 8
Same name in this branch
- 8 tests/src/FunctionalJavascript/LengthIndicatorTest.php \Drupal\Tests\length_indicator\FunctionalJavascript\LengthIndicatorTest
- 8 tests/src/Unit/LengthIndicatorTest.php \Drupal\Tests\length_indicator\Unit\LengthIndicatorTest
Tests the code in length_indicator.module.
@group length_indicator
Note we load code, so isolate the test.
@runInSeparateProcess @preserveGlobalState disabled
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\length_indicator\Unit\LengthIndicatorTest
Expanded class hierarchy of LengthIndicatorTest
File
- tests/
src/ Unit/ LengthIndicatorTest.php, line 18
Namespace
Drupal\Tests\length_indicator\UnitView source
class LengthIndicatorTest extends UnitTestCase {
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
include_once __DIR__ . '/../../../length_indicator.module';
}
/**
* Tests _length_indicator_get_width_and_pos().
*
* @dataProvider providerTestLengthIndicatorGetWidthAndPos
*/
public function testLengthIndicatorGetWidthAndPos($optimin, $optimax, $tolerance, array $expected) {
$service_length_indicator = new GetWidthPos();
$this
->assertEquals($expected, $service_length_indicator
->getWidthAndPosition($optimin, $optimax, $tolerance));
}
/**
* Data provider for testLengthIndicatorGetWidthAndPos().
*
* @return array
* An array with of arguments for testLengthIndicatorGetWidthAndPos().
*/
public function providerTestLengthIndicatorGetWidthAndPos() {
return [
[
10,
15,
5,
[
[
'width' => 20.0,
'pos' => 0,
'class' => 'length-indicator__indicator--bad',
],
[
'width' => 20.0,
'pos' => 5,
'class' => 'length-indicator__indicator--ok',
],
[
'width' => 20.0,
'pos' => 10,
'class' => 'length-indicator__indicator--good',
],
[
'width' => 20.0,
'pos' => 16,
'class' => 'length-indicator__indicator--ok',
],
[
'width' => 20.0,
'pos' => 21,
'class' => 'length-indicator__indicator--bad',
],
],
],
'zero_tolerance' => [
10,
15,
0,
[
[
'width' => 40.0,
'pos' => 0,
'class' => 'length-indicator__indicator--bad',
],
[
'width' => 0.0,
'pos' => 10,
'class' => 'length-indicator__indicator--ok',
],
[
'width' => 20.0,
'pos' => 10,
'class' => 'length-indicator__indicator--good',
],
[
'width' => 0.0,
'pos' => 16,
'class' => 'length-indicator__indicator--ok',
],
[
'width' => 40.0,
'pos' => 16,
'class' => 'length-indicator__indicator--bad',
],
],
],
[
100,
250,
75,
[
[
'width' => 7.142857142857142,
'pos' => 0,
'class' => 'length-indicator__indicator--bad',
],
[
'width' => 21.428571428571427,
'pos' => 25,
'class' => 'length-indicator__indicator--ok',
],
[
'width' => 42.85714285714286,
'pos' => 100,
'class' => 'length-indicator__indicator--good',
],
[
'width' => 21.42857142857143,
'pos' => 251,
'class' => 'length-indicator__indicator--ok',
],
[
'width' => 7.142857142857142,
'pos' => 326,
'class' => 'length-indicator__indicator--bad',
],
],
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LengthIndicatorTest:: |
public | function | Data provider for testLengthIndicatorGetWidthAndPos(). | |
LengthIndicatorTest:: |
public | function |
Overrides UnitTestCase:: |
|
LengthIndicatorTest:: |
public | function | Tests _length_indicator_get_width_and_pos(). | |
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. |