function FieldTypePluginManagerTest::testGetGroupedDefinitionsInvalid

Same name and namespace in other branches
  1. 10 core/tests/Drupal/Tests/Core/Field/FieldTypePluginManagerTest.php \Drupal\Tests\Core\Field\FieldTypePluginManagerTest::testGetGroupedDefinitionsInvalid()

@covers ::getGroupedDefinitions

File

core/tests/Drupal/Tests/Core/Field/FieldTypePluginManagerTest.php, line 135

Class

FieldTypePluginManagerTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Field%21FieldTypePluginManager.php/class/FieldTypePluginManager/11.x" title="Plugin manager for &#039;field type&#039; plugins." class="local">\Drupal\Core\Field\FieldTypePluginManager</a> @group Field

Namespace

Drupal\Tests\Core\Field

Code

public function testGetGroupedDefinitionsInvalid() : void {
    $this->discovery
        ->getDefinitions()
        ->willReturn([
        'string' => [
            'category' => 'text',
            'label' => 'Text (plain)',
            'id' => 'string',
        ],
    ]);
    $this->fieldTypeCategoryManager
        ->getDefinitions()
        ->willReturn([
        'general' => [
            'label' => 'General',
            'id' => 'general',
        ],
    ]);
    $zend_assertions_default = ini_get('zend.assertions');
    // Test behavior when assertions are not enabled.
    ini_set('zend.assertions', 0);
    $grouped_definitions = $this->fieldTypeManager
        ->getGroupedDefinitions();
    $this->assertEquals([
        'General',
    ], array_keys($grouped_definitions));
    // Test behavior when assertions are enabled.
    ini_set('zend.assertions', 1);
    $this->expectException(\AssertionError::class);
    try {
        $this->fieldTypeManager
            ->getGroupedDefinitions();
    } catch (\Exception $e) {
        // Reset the original assert values.
        ini_set('zend.assertions', $zend_assertions_default);
        throw $e;
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.