public function EntityBrowserTest::testSelectedEvent in Entity Browser 8
Same name and namespace in other branches
- 8.2 tests/src/Kernel/Extension/EntityBrowserTest.php \Drupal\Tests\entity_browser\Kernel\Extension\EntityBrowserTest::testSelectedEvent()
Test selected event dispatch.
File
- tests/
src/ Kernel/ Extension/ EntityBrowserTest.php, line 333
Class
- EntityBrowserTest
- Tests the entity_browser config entity.
Namespace
Drupal\Tests\entity_browser\Kernel\ExtensionCode
public function testSelectedEvent() {
$this
->installConfig([
'entity_browser_test',
]);
/** @var \Drupal\entity_browser\EntityBrowserInterface $entity */
$entity = $this->controller
->load('dummy_widget');
/** @var \Drupal\entity_browser\EntityBrowserFormInterface $form_object */
$form_object = $entity
->getFormObject();
$form_object
->setEntityBrowser($entity);
$form_state = new FormState();
$entity
->getWidgets()
->get($entity
->getFirstWidget())->entity = $entity;
$this->container
->get('form_builder')
->buildForm($form_object, $form_state);
$this
->assertEquals(0, count($form_state
->get([
'entity_browser',
'selected_entities',
])), 'Correct number of entities was propagated.');
$this->container
->get('form_builder')
->submitForm($form_object, $form_state);
// Event should be dispatched from widget and added to list of selected
// entities.
$selected_entities = $form_state
->get([
'entity_browser',
'selected_entities',
]);
$this
->assertEquals($selected_entities, [
$entity,
], 'Expected selected entities detected.');
}