public function EntityBrowserTest::testDefaultWidget in Entity Browser 8.2
Same name and namespace in other branches
- 8 tests/src/Kernel/Extension/EntityBrowserTest.php \Drupal\Tests\entity_browser\Kernel\Extension\EntityBrowserTest::testDefaultWidget()
Tests default widget selector.
File
- tests/
src/ Kernel/ Extension/ EntityBrowserTest.php, line 306
Class
- EntityBrowserTest
- Tests the entity_browser config entity.
Namespace
Drupal\Tests\entity_browser\Kernel\ExtensionCode
public function testDefaultWidget() {
$this
->installConfig([
'entity_browser_test',
]);
/** @var \Drupal\entity_browser\EntityBrowserInterface $entity */
$entity = $this->controller
->load('test');
/** @var \Drupal\entity_browser\EntityBrowserFormInterface $form_object */
$form_object = $entity
->getFormObject();
$form_object
->setEntityBrowser($entity);
$form_state = new FormState();
$form = [];
$form = $form_object
->buildForm($form, $form_state);
$this
->assertEquals($form['widget']['#markup'], 'Number one', 'First widget is active.');
// Change weight and expect second widget to become first.
$entity
->getWidget($entity
->getFirstWidget())
->setWeight(3);
$form_state
->set('entity_browser_current_widget', NULL);
$entity
->getWidgets()
->sort();
$form = [];
$form = $form_object
->buildForm($form, $form_state);
$this
->assertEquals($form['widget']['#markup'], 'Number two', 'Second widget is active after changing widgets.');
}