Completed
Push — 8.x-1.x ( c6ae39...2ee901 )
by Janez
03:25
created

InlineEntityIntegrationTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 54
rs 10
wmc 1
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B testInlineEntityIntegration() 0 35 1
1
<?php
2
3
namespace Drupal\entity_browser_entity_form\Tests;
4
5
use Drupal\simpletest\WebTestBase;
6
7
/**
8
 * Tests integration with Inline entity form.
9
 *
10
 * @group entity_browser_entity_form
11
 */
12
class InlineEntityIntegrationTest extends WebTestBase {
13
14
  /**
15
   * Modules to enable.
16
   *
17
   * @var array
18
   */
19
  public static $modules = [
20
    'entity_browser_entity_form',
21
    'node',
22
    'field_ui',
23
    'entity_browser_entity_form_test',
24
  ];
25
26
  /**
27
   * Tests integration with Inline entity form.
28
   */
29
  public function testInlineEntityIntegration() {
30
    $account = $this->drupalCreateUser([
31
      'administer node form display',
32
      'administer node display',
33
      'create article content',
34
    ]);
35
    $this->drupalLogin($account);
36
    $this->drupalGet('admin/structure/types/manage/article/form-display');
37
    $edit = [
38
      'fields[field_content_reference][type]' => 'inline_entity_form_complex',
39
    ];
40
    $this->drupalPostForm(NULL, $edit, t('Save'));
41
    $this->drupalPostAjaxForm(NULL, [], 'field_content_reference_settings_edit');
42
    $this->assertRaw('fields[field_content_reference][settings_edit_form][third_party_settings][entity_browser_entity_form][entity_browser_id]', 'Field to select entity browser is available.');
43
    $edit = [
44
      'fields[field_content_reference][settings_edit_form][third_party_settings][entity_browser_entity_form][entity_browser_id]' => 'entity_browser_entity_form_test',
45
      'fields[field_content_reference][settings_edit_form][settings][allow_existing]' => TRUE,
46
    ];
47
    $this->drupalPostAjaxForm(NULL, $edit, 'field_content_reference_plugin_settings_update');
48
    $this->drupalPostForm(NULL, [], t('Save'));
49
    $this->assertText('Entity browser: Entity browser entity form test', 'Settings summary is working correctly.');
50
51
    $this->drupalGet('node/add');
52
    $elements = $this->xpath('//input[@type="submit" and @value="Add existing node"]');
53
    $button_name = $elements[0]->attributes()['name'];
54
    $this->drupalPostAjaxForm(NULL, [], $button_name);
55
    $this->assertLink('Select entities', 0, 'Entity browser is available.');
56
57
    $browsers = $this->container->get('entity_type.manager')->getStorage('entity_browser')->loadMultiple();
58
    $browser = current($browsers);
59
    $this->container->get('entity_type.manager')->getStorage('entity_browser')->delete([$browser]);
60
    $this->drupalGet('admin/structure/types/manage/article/form-display');
61
    $this->drupalPostAjaxForm(NULL, [], 'field_content_reference_settings_edit');
62
    $this->assertText(t('There are no entity browsers available. You can create one here'), 'Massage displays when no entity browser is available.');
63
  }
64
65
}
66