class ParagraphsEntityReferenceWarningTest

Tests paragraphs customization for entity reference fields.

@group paragraphs

Hierarchy

Expanded class hierarchy of ParagraphsEntityReferenceWarningTest

File

paragraphs/tests/src/FunctionalJavascript/ParagraphsEntityReferenceWarningTest.php, line 14

Namespace

Drupal\Tests\paragraphs\FunctionalJavascript
View source
class ParagraphsEntityReferenceWarningTest extends WebDriverTestBase {
  use LoginAdminTrait;
  use ParagraphsTestBaseTrait;

  /**
   * Modules to enable.
   *
   * @var array
   */
  protected static $modules = [
    'node',
    'paragraphs',
    'field',
    'field_ui',
    'block',
    'link',
    'text',
    'content_translation',
  ];

  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';

  /**
   * Tests paragraphs customization for entity reference fields.
   */
  public function testEntityReferenceTargetTypeWarning() {

    // Create the content type.
    $node_type = NodeType::create([
      'type' => 'example',
      'name' => 'example',
    ]);
    $node_type
      ->save();
    $this
      ->loginAsAdmin();
    $this
      ->drupalGet('admin/structure/types/manage/example/fields/add-field');
    $page = $this
      ->getSession()
      ->getPage();
    if ($this
      ->coreVersion('10.2')) {
      $page
        ->find('css', "[name='new_storage_type'][value='reference']")
        ->getParent()
        ->click();
      $this
        ->assertSession()
        ->assertWaitOnAjaxRequest();
      $page
        ->fillField('label', 'unsupported field');
      $page
        ->find('css', "[name='group_field_options_wrapper'][value='entity_reference']")
        ->getParent()
        ->click();
      $this
        ->assertSession()
        ->assertWaitOnAjaxRequest();
      $page
        ->pressButton('Continue');
      $this
        ->assertSession()
        ->pageTextNotContains('Note: Regular paragraph fields should use the revision based reference fields, entity reference fields should only be used for cases when an existing paragraph is referenced from somewhere else.');
      $page
        ->selectFieldOption('field_storage[subform][settings][target_type]', 'paragraph');
      $this
        ->assertSession()
        ->pageTextContains('Note: Regular paragraph fields should use the revision based reference fields, entity reference fields should only be used for cases when an existing paragraph is referenced from somewhere else.');
    }
    else {
      $page
        ->selectFieldOption('new_storage_type', 'entity_reference');
      $this
        ->assertSession()
        ->assertWaitOnAjaxRequest();
      $page
        ->fillField('label', 'unsupported field');
      $this
        ->assertSession()
        ->waitForElement('css', 'button.link');
      sleep(1);
      $page
        ->pressButton('Save and continue');
      if ($this->htmlOutputEnabled && !$this
        ->isTestUsingGuzzleClient()) {
        $html_output = 'GET request to: ' . $this
          ->getUrl() . '<hr />Ending URL: ' . $this
          ->getSession()
          ->getCurrentUrl();
        $html_output .= '<hr />' . $this
          ->getSession()
          ->getPage()
          ->getContent();
        $html_output .= $this
          ->getHtmlOutputHeaders();
        $this
          ->htmlOutput($html_output);
      }
      $this
        ->assertSession()
        ->pageTextNotContains('Note: Regular paragraph fields should use the revision based reference fields, entity reference fields should only be used for cases when an existing paragraph is referenced from somewhere else.');
      $page
        ->selectFieldOption('settings[target_type]', 'paragraph');
      $this
        ->assertSession()
        ->pageTextContains('Note: Regular paragraph fields should use the revision based reference fields, entity reference fields should only be used for cases when an existing paragraph is referenced from somewhere else.');
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LoginAdminTrait::$admin_user protected property Drupal user object created by loginAsAdmin().
LoginAdminTrait::loginAsAdmin public function Creates an user with admin permissions and log in.
ParagraphsEntityReferenceWarningTest::$defaultTheme protected property
ParagraphsEntityReferenceWarningTest::$modules protected static property Modules to enable.
ParagraphsEntityReferenceWarningTest::testEntityReferenceTargetTypeWarning public function Tests paragraphs customization for entity reference fields.
ParagraphsTestBaseTrait::$workflow protected property The workflow entity.
ParagraphsTestBaseTrait::addFieldtoParagraphType protected function Adds a field to a given paragraph type.
ParagraphsTestBaseTrait::addParagraphedContentType protected function Adds a content type with a Paragraphs field.
ParagraphsTestBaseTrait::addParagraphsField protected function Adds a Paragraphs field to a given entity type.
ParagraphsTestBaseTrait::addParagraphsType protected function Adds a Paragraphs type.
ParagraphsTestBaseTrait::addParagraphsTypeIcon protected function Adds an icon to a paragraphs type.
ParagraphsTestBaseTrait::coreVersion protected function Checks the core version.
ParagraphsTestBaseTrait::createEditorialWorkflow protected function Creates a workflow entity.
ParagraphsTestBaseTrait::setParagraphsWidgetSettings protected function Sets some of the settings of a paragraphs field widget.