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()

Tests get grouped definitions invalid.

File

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

Class

FieldTypePluginManagerTest
Tests Drupal\Core\Field\FieldTypePluginManager.

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.