only in patch2: unchanged: --- a/core/modules/system/src/Tests/Entity/EntityAutocompleteTest.php +++ b/core/modules/system/src/Tests/Entity/EntityAutocompleteTest.php @@ -11,6 +11,7 @@ use Drupal\Component\Utility\Crypt; use Drupal\Component\Utility\Html; use Drupal\Component\Utility\Tags; +use Drupal\Core\Entity\Element\EntityAutocomplete; use Drupal\Core\Site\Settings; use Drupal\system\Controller\EntityAutocompleteController; use Symfony\Component\HttpFoundation\Request; @@ -98,6 +99,30 @@ function testEntityReferenceAutocompletion() { } /** + * Tests that entity IDs can be extracted from autocomplete strings. + */ + protected function testExtractEntityIdFromAutocompleteInput() { + $result = EntityAutocomplete::extractEntityIdFromAutocompleteInput('Name (42)'); + $this->assertEqual('42', $result); + $result = EntityAutocomplete::extractEntityIdFromAutocompleteInput('Name (entity_id)'); + $this->assertEqual('entity_id', $result); + $result = EntityAutocomplete::extractEntityIdFromAutocompleteInput('Name'); + $this->assertNull($result); + } + + /** + * Tests that entity labels can be extracted from autocomplete strings. + */ + protected function testExtractEntityLabelFromAutocompleteInput() { + $result = EntityAutocomplete::extractEntityLabelFromAutocompleteInput('Name (42)'); + $this->assertEqual('Name', $result); + $result = EntityAutocomplete::extractEntityLabelFromAutocompleteInput('Name (entity_id)'); + $this->assertEqual('Name', $result); + $result = EntityAutocomplete::extractEntityLabelFromAutocompleteInput('Name'); + $this->assertNull($result); + } + + /** * Tests that missing or invalid selection setting key are handled correctly. */ public function testSelectionSettingsHandling() {