class FieldValueTest in Twig Field Value 8
Same name in this branch
- 8 tests/src/Kernel/FieldValueTest.php \Drupal\Tests\twig_field_value\Kernel\FieldValueTest
- 8 tests/src/Unit/FieldValue/FieldValueTest.php \Drupal\Tests\twig_field_value\Unit\FieldValue\FieldValueTest
Same name and namespace in other branches
- 2.0.x tests/src/Unit/FieldValue/FieldValueTest.php \Drupal\Tests\twig_field_value\Unit\FieldValue\FieldValueTest
@coversDefaultClass \Drupal\twig_field_value\Twig\Extension\FieldValueExtension @group twig_field_value
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\twig_field_value\Unit\FieldValue\FieldValueTest
Expanded class hierarchy of FieldValueTest
File
- tests/
src/ Unit/ FieldValue/ FieldValueTest.php, line 12
Namespace
Drupal\Tests\twig_field_value\Unit\FieldValueView source
class FieldValueTest extends UnitTestCase {
/**
* The Twig extension under test.
*
* @var \Drupal\twig_field_value\Twig\Extension\FieldValueExtension
*/
protected $extension;
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->extension = new FieldValueExtension();
}
/**
* Asserts the twig field_label filter.
*
* @dataProvider providerTestFieldLabel
* @covers ::getFieldLabel
*
* @param $expected_result
* @param $render_array
*/
public function testFieldLabel($expected_result, $render_array) {
$result = $this->extension
->getFieldLabel($render_array);
$this
->assertSame($expected_result, $result);
}
/**
* Provides data and expected results for the test method.
*
* @return array
* Data and expected results.
*/
public function providerTestFieldLabel() {
return [
[
NULL,
[],
],
[
NULL,
[
'#title' => 'foo',
],
],
[
NULL,
[
'#theme' => 'item_list',
],
],
[
NULL,
[
'#theme' => 'field',
],
],
[
'My title',
[
'#theme' => 'field',
'#title' => 'My title',
],
],
];
}
/**
* Asserts the twig field_value filter.
*
* @dataProvider providerTestFieldValue
* @covers ::getFieldValue
*
* @param $expected_result
* @param $render_array
*/
public function testFieldValue($expected_result, $render_array) {
$result = $this->extension
->getFieldValue($render_array);
$this
->assertSame($expected_result, $result);
}
/**
* Provides data and expected results for the test method.
*
* @return array
* Data and expected results.
*/
public function providerTestFieldValue() {
return [
[
NULL,
NULL,
],
[
NULL,
[],
],
[
NULL,
[
'#items' => 'foo',
],
],
[
NULL,
[
'#theme' => 'item_list',
],
],
[
NULL,
[
'#theme' => 'field',
],
],
[
[
0 => [
'#markup' => 'this value',
],
],
[
'#theme' => 'field',
'#items' => [
0 => 'dummy',
],
0 => [
'#markup' => 'this value',
],
],
],
[
[
0 => [
'#markup' => 'zero',
],
2 => [
'#markup' => 'two',
],
3 => [
'#markup' => 'three',
],
],
[
'#theme' => 'field',
'#items' => [
0 => 'dummy',
1 => 'dummy',
2 => 'dummy',
3 => 'dummy',
],
0 => [
'#markup' => 'zero',
],
2 => [
'#markup' => 'two',
],
3 => [
'#markup' => 'three',
],
],
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FieldValueTest:: |
protected | property | The Twig extension under test. | |
FieldValueTest:: |
public | function | Provides data and expected results for the test method. | |
FieldValueTest:: |
public | function | Provides data and expected results for the test method. | |
FieldValueTest:: |
protected | function |
Overrides UnitTestCase:: |
|
FieldValueTest:: |
public | function | Asserts the twig field_label filter. | |
FieldValueTest:: |
public | function | Asserts the twig field_value filter. | |
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. |