public function ParagraphsLibraryItemTest::testLibraryItemUsageTab in Paragraphs 8
Test that usage tab are presented for library item.
File
- modules/
paragraphs_library/ tests/ src/ Functional/ ParagraphsLibraryItemTest.php, line 239
Class
- ParagraphsLibraryItemTest
- Tests the functionality of the Paragraphs Library.
Namespace
Drupal\Tests\paragraphs_library\FunctionalCode
public function testLibraryItemUsageTab() {
$admin = $this
->drupalCreateUser([
'create paragraphed_test content',
'edit any paragraphed_test content',
'administer paragraphs library',
'delete all revisions',
'revert all revisions',
'administer content types',
'administer node fields',
'administer paragraphs types',
'administer node form display',
'administer paragraph fields',
'administer paragraph form display',
'access entity usage statistics',
]);
$this
->drupalLogin($admin);
$this
->addParagraphsType('test_content');
$this
->addParagraphsType('nested_paragraph');
$this
->fieldUIAddNewField('admin/structure/paragraphs_type/test_content', 'paragraphs_text', 'Test content', 'text_long', [], []);
// Add nested paragraph field.
$this
->fieldUIAddNewField('admin/structure/paragraphs_type/nested_paragraph', 'err_field', 'Nested', 'field_ui:entity_reference_revisions:paragraph', [
'settings[target_type]' => 'paragraph',
'cardinality' => '-1',
], []);
// Add nested paragraph directly in library.
$this
->drupalGet('admin/content/paragraphs/add/default');
$page = $this
->getSession()
->getPage();
$assert_session = $this
->assertSession();
$page
->pressButton('Add nested_paragraph');
$page
->find('css', '.paragraphs-subform')
->pressButton('Add test_content');
$edit = [
'label[0][value]' => 'Test usage nested paragraph',
'paragraphs[0][subform][field_err_field][0][subform][field_paragraphs_text][0][value]' => 'Example text for revision in nested paragraph.',
];
$this
->submitForm($edit, 'Save');
$assert_session
->pageTextContains('Paragraph Test usage nested paragraph has been created.');
// Create content with referenced paragraph.
$this
->drupalGet('node/add/paragraphed_test');
$page
->pressButton('Add From library');
$edit = [
'title[0][value]' => 'Test content',
'field_paragraphs[0][subform][field_reusable_paragraph][0][target_id]' => 'Test usage nested paragraph',
];
$this
->submitForm($edit, 'Save');
$node = $this
->drupalGetNodeByTitle('Test content');
// Check Usage tab.
$this
->drupalGet('admin/content/paragraphs');
$this
->clickLink('Test usage nested paragraph');
$this
->clickLink('Usage');
$assert_session
->pageTextContains('Entity usage information for Test usage nested paragraph');
$assert_session
->elementContains('css', 'table tbody tr td:nth-child(1)', 'Test content > field_paragraphs');
$assert_session
->elementContains('css', 'table tbody tr td:nth-child(2)', 'Paragraph');
$assert_session
->elementContains('css', 'table tbody tr td:nth-child(3)', 'English');
$assert_session
->elementContains('css', 'table tbody tr td:nth-child(4)', 'Reusable paragraph');
$assert_session
->elementContains('css', 'table tbody tr td:nth-child(5)', 'Published');
// Assert breadcrumb.
$assert_session
->elementContains('css', '.breadcrumb ol li:nth-child(1)', 'Home');
$assert_session
->elementContains('css', '.breadcrumb ol li:nth-child(2)', 'Paragraphs library');
$assert_session
->elementContains('css', '.breadcrumb ol li:nth-child(3)', 'Test usage nested paragraph');
// Unlink library item and check usage tab.
$node = $this
->drupalGetNodeByTitle('Test content');
$this
->drupalGet($node
->toUrl('edit-form'));
$this
->submitForm([], 'Unlink from library');
$this
->submitForm([
'revision' => TRUE,
], 'Save');
// Check Usage tab.
$this
->drupalGet('admin/content/paragraphs');
$this
->clickLink('Test usage nested paragraph');
$this
->clickLink('Usage');
$assert_session
->pageTextContains('Entity usage information for Test usage nested paragraph');
// Assert there is a row here indicating that the host node references the
// paragraph in a non-default revision.
$assert_session
->elementContains('css', 'table tbody tr td:nth-child(1)', 'Test content > field_paragraphs (previous revision)');
$assert_session
->elementContains('css', 'table tbody tr td:nth-child(2)', 'Paragraph');
$assert_session
->elementContains('css', 'table tbody tr td:nth-child(3)', 'English');
$assert_session
->elementContains('css', 'table tbody tr td:nth-child(4)', 'Reusable paragraph');
$assert_session
->elementContains('css', 'table tbody tr td:nth-child(5)', 'Published');
}