class ParagraphsAnchorPluginTest

Tests the anchor plugin.

@group paragraphs_collection_demo

Hierarchy

Expanded class hierarchy of ParagraphsAnchorPluginTest

See also

\Drupal\paragraphs_collection_demo\Plugin\paragraphs\Behavior\ParagraphsAnchorPlugin

File

paragraphs_collection/modules/paragraphs_collection_demo/tests/src/Functional/ParagraphsAnchorPluginTest.php, line 13

Namespace

Drupal\Tests\paragraphs_collection_demo\Functional
View source
class ParagraphsAnchorPluginTest extends ParagraphsTestBase {

  /**
   * Modules to be enabled.
   *
   * @var array
   */
  protected static $modules = [
    'paragraphs_collection_demo',
  ];

  /**
   * Tests the anchor plugin functionality.
   */
  public function testAnchorPlugin() {
    $this
      ->loginAsAdmin([
      'edit behavior plugin settings',
    ]);
    $this
      ->drupalGet('admin/structure/paragraphs_type/add');
    $this
      ->assertSession()
      ->responseContains('Anchor');
    $this
      ->assertSession()
      ->responseContains('Allows to set ID attribute that can be used as jump position in URLs.');
    $paragraph_type = 'text_test';
    $this
      ->addParagraphsType($paragraph_type);
    $bundle_path = 'admin/structure/paragraphs_type/' . $paragraph_type;
    $this
      ->fieldUIAddExistingField('admin/structure/paragraphs_type/' . $paragraph_type, 'paragraphs_text');
    $this
      ->drupalGet($bundle_path);
    $edit = [
      'behavior_plugins[anchor][enabled]' => TRUE,
    ];
    $this
      ->submitForm($edit, t('Save'));
    $this
      ->addParagraphedContentType('paragraphed_test', 'text');
    $this
      ->setParagraphsWidgetMode('paragraphed_test', 'text', 'closed');
    $this
      ->loginAsAdmin([
      'create paragraphed_test content',
      'edit any paragraphed_test content',
      'edit behavior plugin settings',
    ]);
    $this
      ->drupalGet('node/add/paragraphed_test');
    $this
      ->submitForm([], 'text_text_test_add_more');
    $this
      ->assertSession()
      ->responseContains('Anchor');
    $this
      ->assertSession()
      ->responseContains('Sets an ID attribute prefixed with "scrollto-" in the Paragraph so that it can be used as a jump-to link.');
    $edit = [
      'title[0][value]' => t('Anchor'),
      'text[0][subform][paragraphs_text][0][value]' => t('Test Anchor'),
      'text[0][behavior_plugins][anchor][anchor]' => 'element-anchor',
    ];
    $this
      ->submitForm($edit, 'Save');
    $this
      ->assertSession()
      ->responseContains('id="scrollto-element-anchor"');

    // Test settings summary.
    $this
      ->clickLink('Edit');
    $this
      ->assertSession()
      ->responseContains('<span class="summary-content">Test Anchor</span></div><div class="paragraphs-plugin-wrapper"><span class="summary-plugin"><span class="summary-plugin-label">Anchor</span>scrollto-element-anchor');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ParagraphsAnchorPluginTest::$modules protected static property Modules to be enabled. Overrides ParagraphsTestBase::$modules
ParagraphsAnchorPluginTest::testAnchorPlugin public function Tests the anchor plugin functionality.
ParagraphsTestBase::$admin_permissions protected property List of permissions used by loginAsAdmin().
ParagraphsTestBase::$admin_user protected property Drupal user object created by loginAsAdmin(). 1
ParagraphsTestBase::$defaultTheme protected property 2
ParagraphsTestBase::loginAsAdmin function Creates an user with admin permissions and log in.
ParagraphsTestBase::removeDefaultParagraphType protected function Removes the default paragraph type. Overrides ParagraphsTestBase::removeDefaultParagraphType
ParagraphsTestBase::setAddMode protected function Sets the Paragraphs widget add mode. Overrides ParagraphsTestBase::setAddMode
ParagraphsTestBase::setAllowedParagraphsTypes protected function Sets the allowed Paragraphs types that can be added.
ParagraphsTestBase::setDefaultParagraphType protected function Sets the default paragraph type.
ParagraphsTestBase::setParagraphsTypeWeight protected function Sets the weight of a given Paragraphs type.
ParagraphsTestBase::setParagraphsWidgetMode protected function Sets the Paragraphs widget display mode.
ParagraphsTestBase::setUp protected function 19
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.