public function EntityAutocompleteElementFormTest::testEntityAutocompleteAccess in Drupal 10
Same name and namespace in other branches
- 8 core/tests/Drupal/KernelTests/Core/Entity/Element/EntityAutocompleteElementFormTest.php \Drupal\KernelTests\Core\Entity\Element\EntityAutocompleteElementFormTest::testEntityAutocompleteAccess()
- 9 core/tests/Drupal/KernelTests/Core/Entity/Element/EntityAutocompleteElementFormTest.php \Drupal\KernelTests\Core\Entity\Element\EntityAutocompleteElementFormTest::testEntityAutocompleteAccess()
Tests that access is properly checked by the EntityAutocomplete element.
File
- core/
tests/ Drupal/ KernelTests/ Core/ Entity/ Element/ EntityAutocompleteElementFormTest.php, line 335
Class
- EntityAutocompleteElementFormTest
- Tests the EntityAutocomplete Form API element.
Namespace
Drupal\KernelTests\Core\Entity\ElementCode
public function testEntityAutocompleteAccess() {
$form_builder = $this->container
->get('form_builder');
$form = $form_builder
->getForm($this);
// Check that the current user has proper access to view entity labels.
$expected = $this->referencedEntities[0]
->label() . ' (' . $this->referencedEntities[0]
->id() . ')';
$this
->assertEquals($expected, $form['single_access']['#value']);
$expected .= ', ' . $this->referencedEntities[1]
->label() . ' (' . $this->referencedEntities[1]
->id() . ')';
$this
->assertEquals($expected, $form['tags_access']['#value']);
// Set up a non-admin user that is *not* allowed to view test entities.
\Drupal::currentUser()
->setAccount($this
->createUser([], []));
// Rebuild the form.
$form = $form_builder
->getForm($this);
$expected = '- Restricted access - (' . $this->referencedEntities[0]
->id() . ')';
$this
->assertEquals($expected, $form['single_access']['#value']);
$expected .= ', - Restricted access - (' . $this->referencedEntities[1]
->id() . ')';
$this
->assertEquals($expected, $form['tags_access']['#value']);
}