You are here

public function InlineEntityFormTest::testEntityBrowserInsideInlineEntityForm in Entity Browser 8.2

Same name and namespace in other branches
  1. 8 tests/src/FunctionalJavascript/InlineEntityFormTest.php \Drupal\Tests\entity_browser\FunctionalJavascript\InlineEntityFormTest::testEntityBrowserInsideInlineEntityForm()

Check that selection state in entity browser Inline Entity Form.

File

tests/src/FunctionalJavascript/InlineEntityFormTest.php, line 61

Class

InlineEntityFormTest
Test for integration of entity browser and inline entity form.

Namespace

Drupal\Tests\entity_browser\FunctionalJavascript

Code

public function testEntityBrowserInsideInlineEntityForm() {
  $this
    ->createFile('test_file1');
  $this
    ->createFile('test_file2');
  $this
    ->createFile('test_file3');
  $this
    ->drupalGet('node/add/ief_content');
  $page = $this
    ->getSession()
    ->getPage();
  $page
    ->fillField('Title', 'Test IEF Title');
  $page
    ->pressButton('Add new Test File Media');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $page
    ->fillField('Name', 'Test Bundle Media');
  $page
    ->clickLink('Select entities');
  $this
    ->getSession()
    ->switchToIFrame('entity_browser_iframe_ief_entity_browser_file');
  $page
    ->checkField('entity_browser_select[file:1]');
  $page
    ->checkField('entity_browser_select[file:2]');
  $page
    ->pressButton('Select entities');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $page
    ->pressButton('Use selected');
  $this
    ->getSession()
    ->switchToIFrame();
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $page
    ->pressButton('Create Test File Media');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $page
    ->pressButton('Save');
  $this
    ->drupalGet('node/1/edit');
  $page = $this
    ->getSession()
    ->getPage();
  $page
    ->pressButton('Edit');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();

  // Test reorder of elements.
  $list_selector = '[data-drupal-selector="edit-ief-media-field-form-inline-entity-form-entities-0-form-ief-media-type-file-field-current"]';
  $item_selector = "{$list_selector} .item-container";
  $this
    ->sortableAfter("{$item_selector}:first-child", "{$item_selector}:last-child", $list_selector);
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $page
    ->pressButton('Update Test File Media');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $page
    ->pressButton('Edit');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();

  // Check that element on second position is test_file1 (file:1).
  $secondElement = $page
    ->find('xpath', '//div[@data-drupal-selector="edit-ief-media-field-form-inline-entity-form-entities-0-form-ief-media-type-file-field-current"]/div[2]');
  if (empty($secondElement)) {
    throw new \Exception('Element is not found.');
  }
  $this
    ->assertSame('file:1', $secondElement
    ->getAttribute('data-entity-id'));

  // Test remove of element.
  $this
    ->click('input[name*="ief_media_type_file_field_remove_1_1"]');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $page
    ->pressButton('Update Test File Media');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $page
    ->pressButton('Edit');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();

  // Check that remote button does not exist for already removed entity.
  $this
    ->assertSession()
    ->elementNotExists('css', '[name*="ief_media_type_file_field_remove_1_1"]');

  // Test add inside Entity Browser.
  $page
    ->clickLink('Select entities');
  $this
    ->getSession()
    ->switchToIFrame('entity_browser_iframe_ief_entity_browser_file');
  $page
    ->checkField('entity_browser_select[file:3]');
  $page
    ->pressButton('Select entities');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $page
    ->pressButton('Use selected');
  $this
    ->getSession()
    ->switchToIFrame();
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $page
    ->pressButton('Update Test File Media');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $page
    ->pressButton('Edit');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();

  // Check that element on second position is test_file3 (file:3).
  $secondElement = $page
    ->find('xpath', '//div[@data-drupal-selector="edit-ief-media-field-form-inline-entity-form-entities-0-form-ief-media-type-file-field-current"]/div[2]');
  if (empty($secondElement)) {
    throw new \Exception('Element is not found.');
  }
  $this
    ->assertSame('file:3', $secondElement
    ->getAttribute('data-entity-id'));

  // Test reorder inside Entity Browser.
  $page
    ->clickLink('Select entities');
  $this
    ->getSession()
    ->switchToIFrame('entity_browser_iframe_ief_entity_browser_file');
  $list_selector = '[data-drupal-selector="edit-selected"]';
  $item_selector = "{$list_selector} .item-container";
  $this
    ->sortableAfter("{$item_selector}:first-child", "{$item_selector}:last-child", $list_selector);
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $page
    ->pressButton('Use selected');
  $this
    ->getSession()
    ->switchToIFrame();
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $page
    ->pressButton('Update Test File Media');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $page
    ->pressButton('Edit');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();

  // Check that element on second position is test_file2 (file:2).
  $secondElement = $page
    ->find('xpath', '//div[@data-drupal-selector="edit-ief-media-field-form-inline-entity-form-entities-0-form-ief-media-type-file-field-current"]/div[2]');
  if (empty($secondElement)) {
    throw new \Exception('Element is not found.');
  }
  $this
    ->assertSame('file:2', $secondElement
    ->getAttribute('data-entity-id'));

  // Test remove inside entity browser.
  $page
    ->clickLink('Select entities');
  $this
    ->getSession()
    ->switchToIFrame('entity_browser_iframe_ief_entity_browser_file');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $page
    ->pressButton('remove_3_0');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $page
    ->pressButton('Use selected');
  $this
    ->getSession()
    ->switchToIFrame();
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $page
    ->pressButton('Update Test File Media');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $page
    ->pressButton('Edit');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();

  // Check that element on first position is test_file2 (file:2).
  $secondElement = $page
    ->find('xpath', '//div[@data-drupal-selector="edit-ief-media-field-form-inline-entity-form-entities-0-form-ief-media-type-file-field-current"]/div[1]');
  if (empty($secondElement)) {
    throw new \Exception('Element is not found.');
  }
  $this
    ->assertSame('file:2', $secondElement
    ->getAttribute('data-entity-id'));
}