class ParagraphsCollectionOverviewTest

Tests the Paragraphs Collection overview pages.

@group paragraphs_collection

Hierarchy

Expanded class hierarchy of ParagraphsCollectionOverviewTest

File

paragraphs_collection/tests/src/Functional/ParagraphsCollectionOverviewTest.php, line 13

Namespace

Drupal\Tests\paragraphs_collection\Functional
View source
class ParagraphsCollectionOverviewTest extends ParagraphsTestBase {

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

  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();
  }

  /**
   * Tests the overview pages of discoverable items.
   *
   * These are the layouts for the grid layout plugin and styles for the style
   * plugin.
   */
  public function testOverviewPages() {
    $this
      ->loginAsAdmin([
      'administer paragraphs types',
      'access site reports',
    ]);

    // Check the new link on the reports page.
    $this
      ->drupalGet('/admin/reports');
    $this
      ->assertSession()
      ->pageTextContains('Overviews of items discoverable by behavior plugins.');
    $this
      ->clickLink('Paragraphs Collection');

    // Check the grid layouts overview.
    $this
      ->assertSession()
      ->addressEquals('/admin/reports/paragraphs_collection/layouts');
    $this
      ->assertSession()
      ->titleEquals('Available grid layouts | Drupal');
    $this
      ->assertSession()
      ->pageTextContains('Grid layout label or ID');
    $this
      ->assertSession()
      ->pageTextContains('Details');
    $this
      ->assertSession()
      ->pageTextContains('Used in');

    // Check that a concrete grid layout is displayed.
    $this
      ->assertSession()
      ->pageTextContains('Three columns 1 - 1 - 2');
    $this
      ->assertSession()
      ->pageTextContains('Three columns layout of 1/4, 1/4 and 1/2 width.');
    $this
      ->assertSession()
      ->pageTextContains('paragraphs_collection_demo_1_1_2_column');
    $this
      ->assertSession()
      ->linkExists('Grid');
    $this
      ->assertSession()
      ->linkByHrefExists('/admin/structure/paragraphs_type/grid');

    // Check the tabs.
    $this
      ->assertSession()
      ->linkExists('Layouts');
    $this
      ->clickLink('Styles');

    // Check the styles layouts overview.
    $this
      ->assertSession()
      ->addressEquals('/admin/reports/paragraphs_collection/styles');
    $this
      ->assertSession()
      ->titleEquals('Available styles | Drupal');
    $this
      ->assertSession()
      ->pageTextContains('Group');
    $this
      ->assertSession()
      ->pageTextContains('Style label or ID');
    $this
      ->assertSession()
      ->pageTextContains('Details');
    $this
      ->assertSession()
      ->pageTextContains('Used in');

    // Check that a concrete style is displayed.
    $this
      ->assertSession()
      ->pageTextContains('Blue');
    $this
      ->assertSession()
      ->pageTextContains('paragraphs-blue');
    $this
      ->assertSession()
      ->pageTextContains('General Group');
    $this
      ->assertSession()
      ->linkExists('Container');
    $this
      ->assertSession()
      ->linkByHrefExists('/admin/structure/paragraphs_type/container');

    // Check the tabs.
    $this
      ->assertSession()
      ->linkExists('Layouts');
    $this
      ->assertSession()
      ->linkExists('Styles');

    // Disable the grid layout and style plugins for all paragraphs types.
    $paragraph_type_ids = \Drupal::entityQuery('paragraphs_type')
      ->execute();
    $paragraphs_types = ParagraphsType::loadMultiple($paragraph_type_ids);
    foreach ($paragraphs_types as $paragraphs_type) {

      /** @var \Drupal\paragraphs\ParagraphsTypeInterface $paragraphs_type */
      $paragraphs_type
        ->getBehaviorPlugin('grid_layout')
        ->setConfiguration([
        'enabled' => FALSE,
      ]);
      $paragraphs_type
        ->getBehaviorPlugin('style')
        ->setConfiguration([
        'enabled' => FALSE,
      ]);
      $paragraphs_type
        ->save();
    }

    // Check the grid layouts overview page displays grid layouts but no
    // paragraphs types.
    $this
      ->drupalGet('/admin/reports/paragraphs_collection/layouts');
    $this
      ->assertSession()
      ->pageTextContains('Three columns 1 - 1 - 2');
    $this
      ->assertSession()
      ->pageTextContains('Three columns layout of 1/4, 1/4 and 1/2 width.');
    $this
      ->assertSession()
      ->pageTextContains('paragraphs_collection_demo_1_1_2_column');
    $this
      ->assertSession()
      ->linkNotExists('Grid');
    $this
      ->assertSession()
      ->linkByHrefNotExists('/admin/structure/paragraphs_type/grid');

    // Check the styles overview page displays styles but no paragraphs types.
    $this
      ->drupalGet('/admin/reports/paragraphs_collection/styles');
    $this
      ->assertSession()
      ->pageTextContains('Blue');
    $this
      ->assertSession()
      ->pageTextContains('paragraphs-blue');
    $this
      ->assertSession()
      ->pageTextContains('General Group');
    $this
      ->assertSession()
      ->linkNotExists('Container');
    $this
      ->assertSession()
      ->linkByHrefNotExists('/admin/structure/paragraphs_type/container');

    // Assert saved styles are sorted alphabetically.
    $this
      ->drupalGet('/admin/reports/paragraphs_collection/styles');
    $this
      ->submitForm([
      'styles[underline][enabled]' => TRUE,
      'styles[advanced][enabled]' => TRUE,
    ], 'Save configuration');
    $this
      ->assertSession()
      ->pageTextContains('The configuration options have been saved.');
    $this
      ->assertEquals([
      'advanced',
      'underline',
    ], \Drupal::config('paragraphs_collection.settings')
      ->get('enabled_styles'));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ParagraphsCollectionOverviewTest::$modules protected static property Modules to be enabled. Overrides ParagraphsTestBase::$modules
ParagraphsCollectionOverviewTest::setUp protected function Overrides ParagraphsTestBase::setUp
ParagraphsCollectionOverviewTest::testOverviewPages public function Tests the overview pages of discoverable items.
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.
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::createEditorialWorkflow protected function Creates a workflow entity.
ParagraphsTestBaseTrait::setParagraphsWidgetSettings protected function Sets some of the settings of a paragraphs field widget.