public function ParagraphsUiTest::testSummary in Paragraphs 8
Test paragraphs summary with markup text.
File
- tests/
src/ Functional/ ParagraphsUiTest.php, line 51
Class
- ParagraphsUiTest
- Tests the Paragraphs user interface.
Namespace
Drupal\Tests\paragraphs\FunctionalCode
public function testSummary() {
$this
->addParagraphedContentType('paragraphed_test', 'paragraphs');
$this
->addParagraphsType('text');
$this
->addFieldtoParagraphType('text', 'field_text_demo', 'text');
$this
->loginAsAdmin([
'edit any paragraphed_test content',
]);
$settings = [
'edit_mode' => 'closed',
'closed_mode' => 'summary',
];
$this
->setParagraphsWidgetSettings('paragraphed_test', 'paragraphs', $settings, 'paragraphs');
// Create a node and add a paragraph.
$this
->drupalGet('node/add/paragraphed_test');
$this
->getSession()
->getPage()
->findButton('paragraphs_text_add_more')
->press();
$edit = [
'title[0][value]' => 'Llama test',
'paragraphs[0][subform][field_text_demo][0][value]' => '<iframe src="https://www.llamatest.neck"></iframe>',
];
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('paragraphed_test Llama test has been created.');
// Assert that the summary contains the html text.
$node = $this
->getNodeByTitle('Llama test');
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->assertSession()
->pageTextContains('<iframe src="https://www.llamatest.neck');
$this
->assertSession()
->responseContains('class="paragraphs-description paragraphs-collapsed-description"><div class="paragraphs-content-wrapper"><span class="summary-content"><iframe src=');
// Assert that the summary keeps showing html even with longer html.
$this
->getSession()
->getPage()
->pressButton('paragraphs_0_edit');
$edit = [
'paragraphs[0][subform][field_text_demo][0][value]' => '<iframe src="https://www.llamatest.neck" class="this-is-a-pretty-long-class-that-needs-to-be-really-long-for-testing-purposes-so-we-have-a-better-summary-test-and-it-has-exactly-144-characters"></iframe>',
];
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('paragraphed_test Llama test has been updated.');
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->assertSession()
->pageTextContains('<iframe src="https://www.llamatest.neck" class="this-is-a-pretty-long-class-that-needs-to-be-really-long-for-testing-purposes-so-we-');
$this
->assertSession()
->responseContains('class="paragraphs-description paragraphs-collapsed-description"><div class="paragraphs-content-wrapper"><span class="summary-content"><iframe src=');
// Asset that the summary does not display markup even when we have long
// html.
$this
->getSession()
->getPage()
->pressButton('paragraphs_0_edit');
$edit = [
'paragraphs[0][subform][field_text_demo][0][value]' => '<iframe src="https://www.llamatest.neck" class="this-is-a-pretty-long-class-that-needs-to-be-really-long-for-testing-purposes-so-we-have-a-better-summary-test-and-it-has-exactly-144-characters"></iframe><h1>This is a title</h1>',
];
$this
->submitForm($edit, 'Save');
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->assertSession()
->responseContains('class="paragraphs-description paragraphs-collapsed-description"><div class="paragraphs-content-wrapper"><span class="summary-content">This is a title');
}