function EntityAutocompleteElementFormTest::testEntityAutocompleteAccess
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/Entity/Element/EntityAutocompleteElementFormTest.php \Drupal\KernelTests\Core\Entity\Element\EntityAutocompleteElementFormTest::testEntityAutocompleteAccess()
- 10 core/tests/Drupal/KernelTests/Core/Entity/Element/EntityAutocompleteElementFormTest.php \Drupal\KernelTests\Core\Entity\Element\EntityAutocompleteElementFormTest::testEntityAutocompleteAccess()
- 11.x 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 324
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->assertEqual($form['single_access']['#value'], $expected);
$expected .= ', ' . $this->referencedEntities[1]
->label() . ' (' . $this->referencedEntities[1]
->id() . ')';
$this->assertEqual($form['tags_access']['#value'], $expected);
// 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 = t('- Restricted access -') . ' (' . $this->referencedEntities[0]
->id() . ')';
$this->assertEqual($form['single_access']['#value'], $expected);
$expected .= ', ' . t('- Restricted access -') . ' (' . $this->referencedEntities[1]
->id() . ')';
$this->assertEqual($form['tags_access']['#value'], $expected);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.