class ParagraphsSummaryFormatterTest

Same name in this branch
  1. 8.x-1.x paragraphs/tests/src/Functional/WidgetStable/ParagraphsSummaryFormatterTest.php \Drupal\Tests\paragraphs\Functional\WidgetStable\ParagraphsSummaryFormatterTest
  2. 8.x-1.x paragraphs/tests/src/Functional/WidgetLegacy/ParagraphsSummaryFormatterTest.php \Drupal\Tests\paragraphs\Functional\WidgetLegacy\ParagraphsSummaryFormatterTest

Tests the paragraphs summary formatter.

@group paragraphs

Hierarchy

  • class \Drupal\Tests\paragraphs\Functional\WidgetLegacy\ParagraphsTestBase extends \Drupal\Tests\BrowserTestBase uses \Drupal\Tests\field_ui\Traits\FieldUiTestTrait

Expanded class hierarchy of ParagraphsSummaryFormatterTest

File

paragraphs/tests/src/Functional/WidgetLegacy/ParagraphsSummaryFormatterTest.php, line 10

Namespace

Drupal\Tests\paragraphs\Functional\WidgetLegacy
View source
class ParagraphsSummaryFormatterTest extends ParagraphsTestBase {

  /**
   * Modules to enable.
   *
   * @var array
   */
  protected static $modules = [
    'image',
  ];

  /**
   * Tests the paragraphs summary formatter.
   */
  public function testParagraphsSummaryFormatter() {
    $this
      ->addParagraphedContentType('paragraphed_test', 'field_paragraphs', 'entity_reference_paragraphs');
    $this
      ->loginAsAdmin([
      'create paragraphed_test content',
      'edit any paragraphed_test content',
      'administer node display',
    ]);

    // Add a Paragraph type.
    $paragraph_type = 'text_paragraph';
    $this
      ->addParagraphsType($paragraph_type);
    $title_paragraphs_type = 'title';
    $this
      ->addParagraphsType($title_paragraphs_type);
    $this
      ->addParagraphsType('text');
    static::fieldUIAddNewField('admin/structure/paragraphs_type/' . $paragraph_type, 'text', 'Text', 'text_long', [], []);
    static::fieldUIAddNewField('admin/structure/paragraphs_type/' . $title_paragraphs_type, 'title', 'Title', 'string', [], []);

    // Add a user Paragraph Type
    $paragraph_type = 'user_paragraph';
    $this
      ->addParagraphsType($paragraph_type);
    static::fieldUIAddNewField('admin/structure/paragraphs_type/' . $paragraph_type, 'user', 'User', 'entity_reference', [
      'settings[target_type]' => 'user',
    ], []);

    // Set display format to paragraphs summary.
    $this
      ->drupalGet('admin/structure/types/manage/paragraphed_test/display');
    $edit = [
      'fields[field_paragraphs][type]' => 'paragraph_summary',
    ];
    $this
      ->submitForm($edit, 'Save');

    // Add a paragraph.
    $this
      ->drupalGet('node/add/paragraphed_test');
    $this
      ->submitForm([], 'field_paragraphs_text_paragraph_add_more');
    $this
      ->submitForm([], 'field_paragraphs_title_add_more');

    // Create a node with a text.
    $edit = [
      'title[0][value]' => 'Test article',
      'field_paragraphs[0][subform][field_text][0][value]' => 'text_summary',
      'field_paragraphs[1][subform][field_title][0][value]' => 'Title example',
    ];
    $this
      ->submitForm($edit, 'Save');
    $this
      ->clickLink('Edit');
    $this
      ->submitForm([], 'Add user_paragraph');
    $edit = [
      'field_paragraphs[2][subform][field_user][0][target_id]' => $this->admin_user
        ->label() . ' (' . $this->admin_user
        ->id() . ')',
    ];
    $this
      ->submitForm($edit, 'Save');

    // Assert the summary is correctly generated.
    $this
      ->assertSession()
      ->pageTextContains($this->admin_user
      ->label());
    $this
      ->assertSession()
      ->pageTextContains('Title example');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ParagraphsSummaryFormatterTest::$modules protected static property Modules to enable. Overrides ParagraphsTestBase::$modules
ParagraphsSummaryFormatterTest::testParagraphsSummaryFormatter public function Tests the paragraphs summary formatter.
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. 1
ParagraphsTestBase::setAddMode protected function Sets the Paragraphs widget add mode. 1
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