View source
<?php
namespace Drupal\Tests\paragraphs\Functional\WidgetStable;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\node\Entity\NodeType;
class ParagraphsConfigTest extends ParagraphsTestBase {
public static $modules = array(
'content_translation',
);
public function testFieldTranslationDisabled() {
$this
->loginAsAdmin([
'administer languages',
'administer content translation',
'create content translations',
'translate any entity',
]);
$this
->addParagraphedContentType('paragraphed_test');
$this
->addParagraphsType('paragraph_type_test');
$this
->addParagraphsType('text');
ConfigurableLanguage::create([
'id' => 'de',
])
->save();
$edit = [
'entity_types[node]' => TRUE,
'settings[node][paragraphed_test][translatable]' => TRUE,
'settings[node][paragraphed_test][fields][field_paragraphs]' => FALSE,
];
$this
->drupalGet('admin/config/regional/content-language');
$this
->submitForm($edit, 'Save configuration');
$this
->drupalGet('node/add/paragraphed_test');
$this
->submitForm([], 'field_paragraphs_paragraph_type_test_add_more');
$edit = [
'title[0][value]' => 'paragraphed_title',
];
$this
->submitForm($edit, 'Save');
$node = $this
->drupalGetNodeByTitle('paragraphed_title');
$this
->drupalGet('node/' . $node
->id() . '/translations');
$this
->clickLink('Add');
$this
->submitForm([], 'Save (this translation)');
$this
->assertSession()
->pageTextContains('paragraphed_test paragraphed_title has been updated.');
}
public function testContentTranslationForm() {
$this
->loginAsAdmin([
'administer languages',
'administer content translation',
'create content translations',
'translate any entity',
]);
$this
->drupalGet('admin/config/regional/content-language');
$this
->assertSession()
->pageTextContains('(* unsupported) Paragraphs fields do not support translation.');
$this
->addParagraphedContentType('paragraphed_test');
$this
->drupalGet('admin/config/regional/content-language');
$this
->assertSession()
->pageTextContains('(* unsupported) Paragraphs fields do not support translation.');
$this
->assertSession()
->responseNotContains('<div class="messages messages--error');
ConfigurableLanguage::create([
'id' => 'de',
])
->save();
$edit = [
'entity_types[node]' => TRUE,
'settings[node][paragraphed_test][translatable]' => TRUE,
'settings[node][paragraphed_test][fields][field_paragraphs]' => FALSE,
];
$this
->drupalGet('admin/config/regional/content-language');
$this
->submitForm($edit, 'Save configuration');
$this
->drupalGet('admin/config/regional/content-language');
$this
->assertSession()
->pageTextContains('(* unsupported) Paragraphs fields do not support translation.');
$this
->assertSession()
->responseNotContains('<div class="messages messages--error');
$this
->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.field_paragraphs');
$this
->assertSession()
->pageTextContains('Paragraphs fields do not support translation.');
$edit = [
'entity_types[node]' => TRUE,
'settings[node][paragraphed_test][translatable]' => TRUE,
'settings[node][paragraphed_test][fields][field_paragraphs]' => TRUE,
];
$this
->drupalGet('admin/config/regional/content-language');
$this
->submitForm($edit, 'Save configuration');
$this
->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.field_paragraphs');
$this
->assertSession()
->pageTextContains('Paragraphs fields do not support translation.');
$this
->assertSession()
->responseContains('<div class="messages messages--error');
$this
->drupalGet('admin/structure/types/manage/paragraphed_test/fields/add-field');
$edit = [
'new_storage_type' => 'field_ui:entity_reference:node',
'label' => 'new_no_field_paragraphs',
'field_name' => 'new_no_field_paragraphs',
];
$this
->submitForm($edit, 'Save and continue');
$this
->submitForm([], 'Save field settings');
$this
->assertSession()
->pageTextNotContains('Paragraphs fields do not support translation.');
$this
->assertSession()
->responseNotContains('<div class="messages messages--warning');
}
public function testAvoidUsingParagraphsWithWrongEntity() {
$node_type = NodeType::create([
'type' => 'article',
'name' => 'article',
]);
$node_type
->save();
$this
->loginAsAdmin([
'edit any article content',
]);
$this
->addParagraphsType('paragraphed_type');
$this
->fieldUIAddNewField('admin/structure/types/manage/article', 'node_reference', 'NodeReference', 'entity_reference_revisions', [
'cardinality' => 'number',
'cardinality_number' => 1,
'settings[target_type]' => 'node',
], [
'settings[handler_settings][target_bundles][article]' => 'article',
]);
$this
->drupalGet('admin/structure/types/manage/article/form-display');
$this
->assertSession()
->optionNotExists('edit-fields-field-node-reference-type', 'entity_reference_paragraphs');
$this
->assertSession()
->optionNotExists('edit-fields-field-node-reference-type', 'paragraphs');
}
public function testIncludedParagraphTypes() {
$this
->loginAsAdmin();
$this
->addParagraphedContentType('paragraphed_test', 'paragraphs');
$this
->addParagraphsType('paragraph_type_test');
$this
->addParagraphsType('text');
$this
->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.paragraphs');
$edit = [
'settings[handler_settings][negate]' => 0,
'settings[handler_settings][target_bundles_drag_drop][paragraph_type_test][enabled]' => 1,
];
$this
->submitForm($edit, 'Save settings');
$this
->assertSession()
->pageTextContains('Saved paragraphs configuration.');
$this
->drupalGet('node/add/paragraphed_test');
$this
->assertSession()
->pageTextContains('Add paragraph_type_test');
$this
->assertSession()
->pageTextNotContains('Add text');
$edit = [
'title[0][value]' => 'Testing included types',
];
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('paragraphed_test Testing included types has been created.');
$this
->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.paragraphs');
$edit = [
'settings[handler_settings][negate]' => 0,
'settings[handler_settings][target_bundles_drag_drop][text][enabled]' => 1,
'settings[handler_settings][target_bundles_drag_drop][paragraph_type_test][enabled]' => 1,
];
$this
->submitForm($edit, 'Save settings');
$this
->drupalGet('node/add/paragraphed_test');
$button_paragraphed_type_test = $this
->xpath('//input[@id=:id]', [
':id' => 'paragraphs-paragraph-type-test-add-more',
]);
$button_text = $this
->xpath('//input[@id=:id]', [
':id' => 'paragraphs-text-add-more',
]);
$this
->assertNotNull($button_paragraphed_type_test);
$this
->assertNotNull($button_text);
$edit = [
'title[0][value]' => 'Testing all excluded types',
];
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('paragraphed_test Testing all excluded types has been created.');
}
public function testExcludedParagraphTypes() {
$this
->loginAsAdmin();
$this
->addParagraphedContentType('paragraphed_test', 'paragraphs');
$this
->addParagraphsType('paragraph_type_test');
$this
->addParagraphsType('text');
$this
->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.paragraphs');
$edit = [
'settings[handler_settings][negate]' => 1,
'settings[handler_settings][target_bundles_drag_drop][text][enabled]' => 1,
];
$this
->submitForm($edit, 'Save settings');
$this
->assertSession()
->pageTextContains('Saved paragraphs configuration.');
$this
->drupalGet('node/add/paragraphed_test');
$this
->assertSession()
->pageTextContains('Add paragraph_type_test');
$this
->assertSession()
->pageTextNotContains('Add text');
$edit = [
'title[0][value]' => 'Testing excluded types',
];
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('paragraphed_test Testing excluded types has been created.');
$this
->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.paragraphs');
$edit = [
'settings[handler_settings][negate]' => 1,
'settings[handler_settings][target_bundles_drag_drop][text][enabled]' => 1,
'settings[handler_settings][target_bundles_drag_drop][paragraph_type_test][enabled]' => 1,
];
$this
->submitForm($edit, 'Save settings');
$this
->drupalGet('node/add/paragraphed_test');
$this
->assertSession()
->pageTextContains('You are not allowed to add any of the Paragraph types.');
$edit = [
'title[0][value]' => 'Testing all excluded types',
];
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('paragraphed_test Testing all excluded types has been created.');
}
}