View source
<?php
namespace Drupal\Tests\paragraphs_collection_demo\Functional;
use Drupal\node\Entity\Node;
use Drupal\paragraphs\Entity\Paragraph;
use Drupal\Tests\paragraphs\Functional\WidgetStable\ParagraphsTestBase;
class ParagraphsCollectionDemoTest extends ParagraphsTestBase {
public static $modules = [
'paragraphs_collection_demo',
];
public function testConfiguration() {
$this
->loginAsAdmin([
'administer content types',
'access administration pages',
'access content overview',
]);
$this
->drupalGet('admin/structure/paragraphs_type/container');
$this
->assertSession()
->pageTextContains('Container');
$this
->assertFieldChecked('edit-behavior-plugins-style-enabled');
$this
->assertFieldChecked('edit-behavior-plugins-style-settings-groups-general-group');
$this
->assertNoFieldChecked('edit-behavior-plugins-style-settings-groups-slideshow-group');
$options = $this
->xpath('//input[contains(@id, :id)]', [
':id' => 'edit-behavior-plugins-style-settings-groups',
]);
$this
->assertCount(2, $options);
$this
->drupalGet('admin/structure/paragraphs_type/text');
$this
->assertFieldChecked('edit-behavior-plugins-language-enabled');
$this
->drupalGet('admin/content');
$this
->clickLink('Paragraphs Collection Demo Article!');
$this
->assertText('Paragraphs');
$this
->drupalGet('');
$this
->assertResponse(200);
$this
->assertLink('Paragraphs Collection Demo Article!');
$this
->assertSession()
->pageTextContains('This is content from the library. We can reuse it multiple times without duplicating it.');
}
public function testDemoStyles() {
$this
->loginAsAdmin([
'administer content types',
'access administration pages',
'access content overview',
'administer site configuration',
'create paragraphed_content_demo content',
'edit any paragraphed_content_demo content',
'delete any paragraphed_content_demo content',
]);
$text_paragraph = Paragraph::create([
'type' => 'text',
'paragraphs_text' => [
'value' => '<p>Introduces a new set of styles for the style plugin.</p>',
'format' => 'basic_html',
],
]);
$text_paragraph
->save();
$paragraph = Paragraph::create([
'title' => 'Styled paragraph',
'type' => 'container',
'paragraphs_container_paragraphs' => [
$text_paragraph,
],
]);
$node = Node::create([
'type' => 'paragraphed_content_demo',
'title' => 'Style plugin test',
'langcode' => 'en',
'uid' => '0',
'status' => 1,
'field_paragraphs_demo' => [
$paragraph,
],
]);
$node
->save();
$paragraph
->setBehaviorSettings('style', [
'styles' => [
'general_group' => 'paragraphs-green',
],
]);
$paragraph
->save();
$this
->drupalGet('node/' . $node
->id());
$this
->assertRaw('paragraphs-behavior-background');
$this
->assertRaw('paragraphs-behavior-style--paragraphs-green');
$this
->assertRaw('paragraph--type--container');
$this
->assertRaw('paragraph--view-mode--default');
$paragraph
->setBehaviorSettings('style', [
'styles' => [
'general_group' => 'paragraphs-blue',
],
]);
$paragraph
->save();
$this
->drupalGet('node/' . $node
->id());
$this
->assertRaw('paragraphs-behavior-background');
$this
->assertRaw('paragraphs-behavior-style--paragraphs-blue');
$this
->assertRaw('paragraph--type--container');
$this
->assertRaw('paragraph--view-mode--default');
}
public function testDemoNode() {
$this
->loginAsAdmin([
'edit any paragraphed_content_demo content',
'administer lockable paragraph',
'use text format basic_html',
]);
$this
->drupalGet('node/1/edit');
$this
->assertSession()
->pageTextContains('Edit Paragraphed Content Demo Paragraphs Collection Demo Article!');
$this
->drupalPostForm(NULL, [], 'field_paragraphs_demo_0_edit');
$this
->drupalPostForm(NULL, [], 'field_paragraphs_demo_0_subform_paragraphs_container_paragraphs_0_duplicate');
$this
->drupalPostForm(NULL, [], 'Save');
$this
->assertSession()
->pageTextContains('Paragraphed Content Demo Paragraphs Collection Demo Article! has been updated.');
}
public function testUsingExperimentalWidget() {
$this
->loginAsAdmin([
'edit any paragraphed_content_demo content',
]);
$this
->drupalGet('admin/structure/types/manage/paragraphed_content_demo/form-display');
$this
->assertOptionSelected('edit-fields-field-paragraphs-demo-type', 'paragraphs', 'Using experimental widget.');
}
public function testParagraphTypes() {
$this
->addParagraphedContentType('paragraphed_test');
$this
->loginAsAdmin([
'create paragraphed_test content',
'edit any paragraphed_test content',
'administer paragraphs library',
]);
$this
->drupalGet('/node/add/paragraphed_test');
$this
->drupalPostForm(NULL, [], 'field_paragraphs_image_add_more');
$this
->drupalPostForm(NULL, [], 'field_paragraphs_image_text_add_more');
$image = current($this
->getTestFiles('image'));
$file_system = \Drupal::service('file_system');
$edit = [
'title[0][value]' => 'Paragraph types example',
'files[field_paragraphs_0_subform_paragraphs_image_0]' => $file_system
->realpath($image->uri),
'field_paragraphs[1][subform][paragraphs_text][0][value]' => 'Text test with image',
'files[field_paragraphs_1_subform_paragraphs_image_0]' => $file_system
->realpath($image->uri),
];
$this
->drupalPostForm(NULL, $edit, 'Save');
$this
->assertSession()
->pageTextContains('Text test with image');
$this
->assertRaw($image->filename);
}
}