public function EntityAutocompleteElementFormTest::testEntityAutocompleteAccess in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/system/src/Tests/Entity/Element/EntityAutocompleteElementFormTest.php \Drupal\system\Tests\Entity\Element\EntityAutocompleteElementFormTest::testEntityAutocompleteAccess()
Tests that access is properly checked by the EntityAutocomplete element.
File
- core/
modules/ system/ src/ Tests/ Entity/ Element/ EntityAutocompleteElementFormTest.php, line 294 - Contains \Drupal\system\Tests\Entity\Element\EntityAutocompleteElementFormTest.
Class
- EntityAutocompleteElementFormTest
- Tests the EntityAutocomplete Form API element.
Namespace
Drupal\system\Tests\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(array(), array()));
// 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);
}