View source
<?php
namespace Drupal\Tests\paragraphs_features\FunctionalJavascript;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\editor\Entity\Editor;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\filter\Entity\FilterFormat;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\Tests\paragraphs\Traits\ParagraphsCoreVersionUiTestTrait;
use Drupal\Tests\paragraphs\FunctionalJavascript\LoginAdminTrait;
use Drupal\Tests\paragraphs\FunctionalJavascript\ParagraphsTestBaseTrait;
abstract class ParagraphsFeaturesJavascriptTestBase extends WebDriverTestBase {
use LoginAdminTrait;
use ParagraphsTestBaseTrait;
use ParagraphsCoreVersionUiTestTrait;
use StringTranslationTrait;
protected $defaultTheme = 'stark';
protected static $modules = [
'block',
'field',
'field_ui',
'link',
'node',
'ckeditor',
'paragraphs',
'paragraphs_test',
'paragraphs_features',
'paragraphs_features_test',
'shortcut',
];
protected function setUp() {
parent::setUp();
if ($theme = getenv('THEME')) {
$this
->assertTrue(\Drupal::service('theme_installer')
->install([
$theme,
]));
$this->container
->get('config.factory')
->getEditable('system.theme')
->set('default', $theme)
->set('admin', $theme)
->save();
}
$this
->drupalPlaceBlock('system_breadcrumb_block');
$this
->drupalPlaceBlock('local_tasks_block');
$this
->drupalPlaceBlock('local_actions_block');
$this
->drupalPlaceBlock('page_title_block');
}
protected function createTestConfiguration($content_type, $num_of_test_paragraphs = 1) {
$this
->addParagraphedContentType($content_type);
$this
->loginAsAdmin([
"administer content types",
"administer node form display",
"edit any {$content_type} content",
"create {$content_type} content",
]);
for ($paragraph_type_index = 1; $paragraph_type_index <= $num_of_test_paragraphs; $paragraph_type_index++) {
$this
->addParagraphsType("test_{$paragraph_type_index}");
$this
->addFieldtoParagraphType("test_{$paragraph_type_index}", "text_{$paragraph_type_index}", 'text_long');
}
$this
->addParagraphsType('test_nested');
$this
->addParagraphsField('test_nested', 'field_paragraphs', 'paragraph');
$field_storage = FieldStorageConfig::loadByName('paragraph', 'field_paragraphs');
$field_storage
->set('cardinality', 4);
$field_storage
->save();
$component = [
'type' => 'paragraphs',
'region' => 'content',
'settings' => [
'edit_mode' => 'closed',
'add_mode' => 'modal',
'form_display_mode' => 'default',
],
];
EntityFormDisplay::load('paragraph.test_nested.default')
->setComponent('field_paragraphs', $component)
->save();
}
protected function createEditor() {
$filtered_html_format = FilterFormat::create([
'format' => 'filtered_html',
'name' => 'Filtered HTML',
'weight' => 0,
]);
$filtered_html_format
->save();
Editor::create([
'format' => 'filtered_html',
'editor' => 'ckeditor',
])
->save();
$this->admin_user
->addRole($this
->createRole([
'use text format filtered_html',
]));
$this->admin_user
->save();
}
protected function getCkEditorId($paragraph_index) {
return $this
->getSession()
->getPage()
->find('xpath', '//*[@data-drupal-selector="edit-field-paragraphs-' . $paragraph_index . '"]//textarea')
->getAttribute('id');
}
public function scrollElementInView($cssSelector) {
$this
->getSession()
->executeScript('
var element = document.querySelector(\'' . addcslashes($cssSelector, '\'') . '\');
element.scrollIntoView({block: "center"});
');
}
}