View source
<?php
namespace Drupal\Tests\paragraphs\Functional;
use Drupal\Tests\paragraphs\Functional\WidgetStable\ParagraphsTestBase;
class ParagraphsUiTest extends ParagraphsTestBase {
public static $modules = [
'node',
'paragraphs',
'field',
'field_ui',
'block',
];
public function testParagraphTypeClass() {
$this
->loginAsAdmin();
$this
->addParagraphedContentType('paragraphed_test', 'paragraphs');
$this
->addParagraphsType('test_paragraph');
$this
->addParagraphsType('text');
$this
->drupalGet('node/add/paragraphed_test');
$this
->getSession()
->getPage()
->findButton('paragraphs_test_paragraph_add_more')
->press();
$this
->assertSession()
->responseContains('paragraph-type--test-paragraph');
$this
->getSession()
->getPage()
->findButton('paragraphs_text_add_more')
->press();
$this
->assertSession()
->responseContains('paragraph-type--text');
$this
->getSession()
->getPage()
->findButton('paragraphs_0_remove')
->press();
$this
->assertSession()
->responseContains('paragraph-type--text');
}
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');
$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.');
$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=');
$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=');
$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');
}
public function testDefaultWidget() {
$this
->loginAsAdmin();
$this
->drupalGet('admin/structure/types/add');
$this
->submitForm([
'name' => 'Test',
'type' => 'test',
], 'Save and manage fields');
$this
->clickLink('Add field');
$this
->submitForm([
'new_storage_type' => 'field_ui:entity_reference_revisions:paragraph',
'label' => 'Paragraph',
'field_name' => 'paragraph',
], 'Save and continue');
$this
->submitForm([], 'Save field settings');
$this
->drupalGet('admin/structure/types/manage/test/form-display');
$this
->assertSession()
->fieldValueEquals('fields[field_paragraph][type]', 'paragraphs');
}
}