public function CardinalityTest::testInlineEntityForm in Entity Browser 8
Same name and namespace in other branches
- 8.2 tests/src/FunctionalJavascript/CardinalityTest.php \Drupal\Tests\entity_browser\FunctionalJavascript\CardinalityTest::testInlineEntityForm()
Tests cardinality functionality using Inline Entity Form.
File
- tests/
src/ FunctionalJavascript/ CardinalityTest.php, line 283
Class
- CardinalityTest
- Tests the Cardinality handling.
Namespace
Drupal\Tests\entity_browser\FunctionalJavascriptCode
public function testInlineEntityForm() {
/** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $form_display */
$form_display = $this->container
->get('entity_type.manager')
->getStorage('entity_form_display')
->load('node.ief_content.default');
$field_nodes = $form_display
->getComponent('field_nodes');
$field_nodes['third_party_settings']['entity_browser_entity_form']['entity_browser_id'] = 'cardinality';
$form_display
->setComponent('field_nodes', $field_nodes);
$form_display
->save();
// Set auto open to TRUE on the entity browser.
$entity_browser = $this->container
->get('entity_type.manager')
->getStorage('entity_browser')
->load('cardinality');
$display_configuration = $entity_browser
->get('display_configuration');
$display_configuration['auto_open'] = TRUE;
$entity_browser
->set('display_configuration', $display_configuration);
$entity_browser
->save();
$vizzini = $this
->createNode([
'type' => 'shark',
'title' => 'Vizzini',
]);
$inigo = $this
->createNode([
'type' => 'jet',
'title' => 'Inigo',
]);
$miracle_max = $this
->createNode([
'type' => 'article',
'title' => 'Miracle Max',
]);
$this
->drupalGet('node/add/ief_content');
$page = $this
->getSession()
->getPage();
$page
->pressButton('Add existing node');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->getSession()
->switchToIFrame('entity_browser_iframe_cardinality');
// Without use_field_cardinality set, there should be checkboxes, the default.
$this
->assertCheckBoxExistsByValue('node:' . $vizzini
->id());
$this
->assertCheckBoxExistsByValue('node:' . $inigo
->id());
$this
->assertCheckBoxNotExistsByValue('node:' . $miracle_max
->id());
$view = $this
->config('views.view.bundle_filter_exposed');
$field = $view
->get('display.default.display_options.fields.entity_browser_select', TRUE);
$field['use_field_cardinality'] = TRUE;
$view
->set('display.default.display_options.fields.entity_browser_select', $field);
$view
->save();
FieldStorageConfig::load('node.field_nodes')
->setCardinality(1)
->save();
$this
->drupalGet('node/add/ief_content');
$page = $this
->getSession()
->getPage();
$page
->pressButton('Add existing node');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->getSession()
->switchToIFrame('entity_browser_iframe_cardinality');
// With use_field_cardinality set to true, and cardinality set to 1,
// there should be radios.
$this
->assertRadioExistsByValue('node:' . $vizzini
->id());
$this
->assertRadioExistsByValue('node:' . $inigo
->id());
$this
->assertRadioNotExistsByValue('node:' . $miracle_max
->id());
// Test that cardinality setting persists when using exposed filters form.
// When applying the exposed filters, the radios should persist.
$this
->assertSession()
->selectExists('Type')
->selectOption('jet');
$this
->assertSession()
->buttonExists('Apply')
->press();
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->assertRadioNotExistsByValue('node:' . $vizzini
->id());
$this
->assertRadioExistsByValue('node:' . $inigo
->id());
$this
->assertRadioNotExistsByValue('node:' . $miracle_max
->id());
$this
->assertSession()
->selectExists('Type')
->selectOption('shark');
$this
->assertSession()
->buttonExists('Apply')
->press();
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->assertRadioExistsByValue('node:' . $vizzini
->id());
$this
->assertRadioNotExistsByValue('node:' . $inigo
->id());
$this
->assertRadioNotExistsByValue('node:' . $miracle_max
->id());
}