<?php
namespace Drupal\Tests\paragraphs\Functional\WidgetStable;
class ParagraphsTypesTest extends ParagraphsTestBase {
public function testRemoveTypesWithContent() {
$this
->addParagraphedContentType('paragraphed_test', 'paragraphs');
$this
->loginAsAdmin([
'edit any paragraphed_test content',
]);
$this
->addParagraphsType('paragraph_type_test');
$this
->addParagraphsType('text');
$this
->drupalGet('admin/structure/paragraphs_type');
$this
->clickLink('Delete');
$this
->assertSession()
->pageTextContains('This action cannot be undone.');
$this
->clickLink('Cancel');
$this
->drupalGet('node/add/paragraphed_test');
$this
->submitForm([], 'paragraphs_paragraph_type_test_add_more');
$edit = [
'title[0][value]' => 'test_node',
];
$table_rows = $this
->xpath('//table[contains(@class, :class)]/tbody/tr', [
':class' => 'field-multiple-table',
]);
$this
->assertEquals(1, count($table_rows));
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('paragraphed_test test_node has been created.');
$this
->drupalGet('admin/structure/paragraphs_type');
$this
->clickLink('Delete');
$this
->assertSession()
->pageTextContains('paragraph_type_test Paragraphs type is used by 1 piece of content on your site. You can not remove this paragraph_type_test Paragraphs type until you have removed all from the content.');
$this
->submitForm([], 'Delete existing Paragraph');
$this
->assertSession()
->pageTextContains('Entity is successfully deleted.');
$node = $this
->drupalGetNodeByTitle('test_node');
$this
->drupalGet('node/' . $node
->id() . '/edit');
$table_rows = $this
->xpath('//table[contains(@class, :class)]/tbody/tr', [
':class' => 'field-multiple-table',
]);
$this
->assertEquals(0, count($table_rows));
$this
->submitForm($edit, 'Save');
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->submitForm([], 'paragraphs_paragraph_type_test_add_more');
$this
->submitForm([], 'paragraphs_text_add_more');
$table_rows = $this
->xpath('//table[contains(@class, :class)]/tbody/tr', [
':class' => 'field-multiple-table',
]);
$this
->assertEquals(2, count($table_rows));
$this
->submitForm([], 'Save');
$this
->drupalGet('admin/structure/paragraphs_type');
$this
->clickLink('Delete');
$this
->assertSession()
->pageTextContains('paragraph_type_test Paragraphs type is used by 1 piece of content on your site. You can not remove this paragraph_type_test Paragraphs type until you have removed all from the content.');
$this
->submitForm([], 'Delete existing Paragraph');
$this
->assertSession()
->pageTextContains('Entity is successfully deleted.');
$this
->submitForm([], 'Delete');
$node = $this
->drupalGetNodeByTitle('test_node');
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->assertSession()
->pageTextNotContains('paragraph_type_test');
$table_rows = $this
->xpath('//table[contains(@class, :class)]/tbody/tr', [
':class' => 'field-multiple-table',
]);
$this
->assertEquals(1, count($table_rows));
}
public function testCreateParagraphType() {
$this
->loginAsAdmin();
$this
->drupalGet('/admin/structure/paragraphs_type/add');
$edit = [
'label' => 'Test',
'id' => 'test_name_with_more_than_32_characters',
];
$this
->submitForm($edit, 'Save and manage fields');
$this
->assertSession()
->pageTextContains('Machine-readable name cannot be longer than 32 characters but is currently 38 characters long.');
$edit['id'] = 'new_test_id';
$this
->submitForm($edit, 'Save and manage fields');
$this
->assertSession()
->pageTextContains('Saved the Test Paragraphs type.');
}
}