View source
<?php
namespace Drupal\Tests\paragraphs_library\FunctionalJavascript;
use Behat\Mink\Element\Element;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\paragraphs\Entity\ParagraphsType;
use Drupal\Tests\field_ui\Traits\FieldUiTestTrait;
use Drupal\Tests\paragraphs\FunctionalJavascript\ParagraphsTestBaseTrait;
use Drupal\Tests\paragraphs\Traits\ParagraphsLastEntityQueryTrait;
class ParagraphsContentModerationTest extends WebDriverTestBase {
use ParagraphsTestBaseTrait, FieldUiTestTrait, ParagraphsLastEntityQueryTrait;
protected $adminUser;
protected $visitorUser;
protected $editorUser;
protected static $modules = [
'node',
'entity_browser',
'paragraphs_library',
'block',
'field_ui',
'content_moderation',
];
protected $defaultTheme = 'classy';
public function setUp() : void {
parent::setUp();
$this
->addParagraphedContentType('paragraphed_moderated_test', 'field_paragraphs');
$this
->addParagraphsType('text');
$this
->addFieldtoParagraphType('text', 'field_text', 'text');
$this
->createEditorialWorkflow('paragraphed_moderated_test');
$type_plugin = $this->workflow
->getTypePlugin();
$type_plugin
->addEntityTypeAndBundle('paragraphs_library_item', 'paragraphs_library_item');
$this->workflow
->save();
$this->adminUser = $this
->drupalCreateUser([
'access administration pages',
'view any unpublished content',
'view all revisions',
'revert all revisions',
'view latest version',
'view any unpublished content',
'use ' . $this->workflow
->id() . ' transition create_new_draft',
'use ' . $this->workflow
->id() . ' transition publish',
'use ' . $this->workflow
->id() . ' transition archived_published',
'use ' . $this->workflow
->id() . ' transition archived_draft',
'use ' . $this->workflow
->id() . ' transition archive',
'administer nodes',
'bypass node access',
'administer paragraphs library',
'access paragraphs_library_items entity browser pages',
'administer workflows',
]);
$this->editorUser = $this
->drupalCreateUser([
'access content',
'view all revisions',
'view any unpublished content',
'view latest version',
'use ' . $this->workflow
->id() . ' transition create_new_draft',
'use ' . $this->workflow
->id() . ' transition publish',
'use ' . $this->workflow
->id() . ' transition archived_published',
'use ' . $this->workflow
->id() . ' transition archived_draft',
'use ' . $this->workflow
->id() . ' transition archive',
'access paragraphs_library_items entity browser pages',
'create paragraph library item',
'create paragraphed_moderated_test content',
'edit any paragraphed_moderated_test content',
'access administration pages',
'administer paragraphs library',
]);
$this->visitorUser = $this
->drupalCreateUser([
'access content',
'view all revisions',
]);
$this
->drupalPlaceBlock('system_breadcrumb_block');
$this
->drupalPlaceBlock('local_tasks_block');
$this
->drupalPlaceBlock('local_actions_block');
$this
->drupalPlaceBlock('page_title_block');
$this
->drupalLogin($this->adminUser);
}
public function testModeratedParagraphedContent() {
$session = $this
->getSession();
$page = $session
->getPage();
$assert_session = $this
->assertSession();
$this
->drupalGet('/admin/content/paragraphs/add/default');
$page
->fillField('label[0][value]', 'Library item 1');
$dropbutton_paragraphs = $assert_session
->elementExists('css', '#edit-paragraphs-add-more .dropbutton-arrow');
$dropbutton_paragraphs
->click();
$add_text_paragraph = $assert_session
->elementExists('css', '#paragraphs-text-add-more');
$add_text_paragraph
->press();
$textfield = $assert_session
->waitForElement('css', 'input[name="paragraphs[0][subform][field_text][0][value]"]');
$this
->assertNotNull($textfield);
$page
->fillField('paragraphs[0][subform][field_text][0][value]', 'Library item text 1');
$assert_session
->optionExists('moderation_state[0][state]', 'draft');
$moderation_select = $assert_session
->elementExists('css', 'select[name="moderation_state[0][state]"]');
$this
->assertEquals('draft', $moderation_select
->getValue());
$page
->pressButton('Save');
$assert_session
->pageTextContains('Paragraph Library item 1 has been created.');
$library_item = $this
->getLastEntityOfType('paragraphs_library_item', TRUE);
$this
->assertEquals('draft', $library_item->moderation_state->value);
$library_item_id = $library_item
->id();
$this
->drupalGet("/admin/content/paragraphs/{$library_item_id}");
$assert_session
->elementExists('css', '#content-moderation-entity-moderation-form');
$this
->drupalGet('/node/add/paragraphed_moderated_test');
$page
->fillField('title[0][value]', 'Host page 1');
$add_from_library_button = $assert_session
->elementExists('css', 'input[name="field_paragraphs_from_library_add_more"]');
$add_from_library_button
->press();
$button = $assert_session
->waitForButton('Select reusable paragraph');
$this
->assertNotNull($button);
$button
->press();
$modal = $assert_session
->waitForElement('css', '.ui-dialog');
$this
->assertNotNull($modal);
$session
->switchToIFrame('entity_browser_iframe_paragraphs_library_items');
$assert_session
->assertWaitOnAjaxRequest();
$assert_session
->pageTextContains('Library item 1');
$first_row_checkbox = $assert_session
->elementExists('css', '.view-content tbody tr:nth-child(1) input');
$first_row_checkbox
->click();
$page
->pressButton('Select reusable paragraph');
$session
->wait(1000);
$session
->switchToIFrame();
$assert_session
->assertWaitOnAjaxRequest();
$assert_session
->elementExists('css', '#edit-field-paragraphs-wrapper .rendered-entity');
$assert_session
->elementNotExists('css', '#edit-field-paragraphs-wrapper .rendered-entity #content-moderation-entity-moderation-form');
$page
->selectFieldOption('moderation_state[0][state]', 'draft');
$page
->pressButton('Save');
$assert_session
->pageTextContains('paragraphed_moderated_test Host page 1 has been created.');
$host_node = $this
->getLastEntityOfType('node', TRUE);
$host_node_id = $host_node
->id();
$this
->assertFalse($host_node
->access('view', $this->visitorUser));
$this
->drupalGet("/node/{$host_node_id}/edit");
$page
->fillField('title[0][value]', 'Host page 1 (rev 2)');
$dropbutton_paragraphs = $assert_session
->elementExists('css', '#edit-field-paragraphs-wrapper .dropbutton-wrapper .dropbutton-arrow');
$dropbutton_paragraphs
->click();
$add_text_paragraph = $assert_session
->elementExists('css', 'input[name="field_paragraphs_text_add_more"]');
$add_text_paragraph
->press();
$textfield = $assert_session
->waitForElement('css', 'input[name="field_paragraphs[1][subform][field_text][0][value]"]');
$this
->assertNotNull($textfield);
$page
->fillField('field_paragraphs[1][subform][field_text][0][value]', 'Direct paragraph text 2');
$page
->selectFieldOption('moderation_state[0][state]', 'published');
$page
->clickLink('Revision information');
$page
->find('css', 'a[href="#edit-revision-information"]')
->click();
$page
->fillField('revision_log[0][value]', 'Node revision #2 - This is a special version!');
$page
->pressButton('Save');
$assert_session
->pageTextContains('paragraphed_moderated_test Host page 1 (rev 2) has been updated.');
$assert_session
->pageTextContains('Direct paragraph text 2');
$assert_session
->pageTextContains('Library item text 1');
$this
->drupalLogin($this->visitorUser);
$this
->drupalGet("/node/{$host_node_id}");
$assert_session
->pageTextContains('Direct paragraph text 2');
$assert_session
->pageTextNotContains('Library item text 1');
$this
->drupalLogin($this->adminUser);
$this
->drupalGet("/node/{$host_node_id}/edit");
$page
->fillField('title[0][value]', 'Host page 1 (rev 3)');
$page
->fillField('field_paragraphs[1][subform][field_text][0][value]', 'Direct paragraph text 2 modified');
$dropbutton_paragraphs = $assert_session
->elementExists('css', '#edit-field-paragraphs-wrapper .dropbutton-wrapper .dropbutton-arrow');
$dropbutton_paragraphs
->click();
$add_text_paragraph = $assert_session
->elementExists('css', 'input[name="field_paragraphs_text_add_more"]');
$add_text_paragraph
->press();
$textfield = $assert_session
->waitForElement('css', 'input[name="field_paragraphs[2][subform][field_text][0][value]"]');
$this
->assertNotNull($textfield);
$page
->fillField('field_paragraphs[2][subform][field_text][0][value]', 'Direct paragraph text 3');
$page
->selectFieldOption('moderation_state[0][state]', 'published');
$page
->find('css', 'a[href="#edit-revision-information"]')
->click();
$page
->fillField('revision_log[0][value]', 'Node revision #3');
$page
->pressButton('Save');
$assert_session
->pageTextContains('paragraphed_moderated_test Host page 1 (rev 3) has been updated.');
$assert_session
->pageTextContains('Direct paragraph text 3');
$assert_session
->pageTextContains('Direct paragraph text 2 modified');
$assert_session
->pageTextContains('Library item text 1');
$this
->drupalLogin($this->visitorUser);
$this
->drupalGet("/node/{$host_node_id}");
$assert_session
->pageTextContains('Direct paragraph text 3');
$assert_session
->pageTextContains('Direct paragraph text 2 modified');
$assert_session
->pageTextNotContains('Library item text 1');
$this
->drupalLogin($this->adminUser);
$this
->drupalGet("/admin/content/paragraphs/{$library_item_id}/edit");
$page
->fillField('label[0][value]', 'Library item 1 (rev 2)');
$page
->selectFieldOption('moderation_state[0][state]', 'published');
$page
->pressButton('Save');
$this
->drupalLogin($this->visitorUser);
$this
->drupalGet("/node/{$host_node_id}");
$assert_session
->pageTextContains('Direct paragraph text 3');
$assert_session
->pageTextContains('Direct paragraph text 2 modified');
$assert_session
->pageTextContains('Library item text 1');
$this
->drupalLogin($this->adminUser);
$this
->drupalGet("/node/{$host_node_id}/edit");
$page
->fillField('title[0][value]', 'Host page 1 (rev 4)');
$page
->fillField('field_paragraphs[1][subform][field_text][0][value]', 'Direct paragraph text 2 modified again');
$row = $assert_session
->elementExists('css', '#field-paragraphs-add-more-wrapper tr.draggable:nth-of-type(3)');
$dropdown = $assert_session
->elementExists('css', '.paragraphs-dropdown', $row);
$dropdown
->click();
$paragraph3_remove_button = $assert_session
->elementExists('css', 'input[name="field_paragraphs_2_remove"]');
$paragraph3_remove_button
->press();
$assert_session
->assertWaitOnAjaxRequest();
$page
->selectFieldOption('moderation_state[0][state]', 'draft');
$page
->find('css', 'a[href="#edit-revision-information"]')
->click();
$page
->fillField('revision_log[0][value]', 'Node revision #4');
$page
->pressButton('Save');
$this
->assertNotEmpty(strpos($session
->getCurrentUrl(), "/node/{$host_node_id}/latest") !== FALSE);
$assert_session
->pageTextContains('paragraphed_moderated_test Host page 1 (rev 4) has been updated.');
$assert_session
->pageTextNotContains('Direct paragraph text 3');
$assert_session
->pageTextContains('Direct paragraph text 2 modified again');
$assert_session
->pageTextContains('Library item text 1');
$this
->drupalGet("/node/{$host_node_id}");
$assert_session
->pageTextContains('Direct paragraph text 3');
$assert_session
->pageTextContains('Direct paragraph text 2 modified');
$assert_session
->pageTextContains('Library item text 1');
$this
->drupalLogin($this->visitorUser);
$this
->drupalGet("/node/{$host_node_id}");
$assert_session
->pageTextContains('Direct paragraph text 3');
$assert_session
->pageTextContains('Direct paragraph text 2 modified');
$assert_session
->pageTextContains('Library item text 1');
$this
->drupalLogin($this->adminUser);
$this
->drupalGet("/node/{$host_node_id}/latest");
$page
->selectFieldOption('new_state', 'published');
$content_moderation_apply_button = $assert_session
->elementExists('css', '#content-moderation-entity-moderation-form input[value="Apply"]');
$content_moderation_apply_button
->press();
$assert_session
->pageTextContains('The moderation state has been updated.');
$this
->drupalLogin($this->visitorUser);
$this
->drupalGet("/node/{$host_node_id}");
$assert_session
->pageTextNotContains('Direct paragraph text 3');
$assert_session
->pageTextContains('Direct paragraph text 2 modified again');
$assert_session
->pageTextContains('Library item text 1');
$this
->drupalLogin($this->adminUser);
$this
->drupalGet("/node/{$host_node_id}/revisions");
$table = $assert_session
->elementExists('css', 'table');
$target_row = $this
->getTableRowWithText($table, '- This is a special version!');
$target_row
->clickLink('Revert');
$assert_session
->pageTextContains('Are you sure you want to revert to the revision from');
$page
->pressButton('Revert');
$assert_session
->pageTextContains(' has been reverted to the revision from ');
$this
->drupalLogin($this->visitorUser);
$this
->drupalGet("/node/{$host_node_id}");
$title_element = $assert_session
->elementExists('css', 'h1.page-title');
$this
->assertEquals('Host page 1 (rev 2)', $title_element
->getText());
$assert_session
->pageTextNotContains('Direct paragraph text 3');
$assert_session
->pageTextContains('Direct paragraph text 2');
$assert_session
->pageTextNotContains('Direct paragraph text 2 modified');
$assert_session
->pageTextContains('Library item text 1');
$this
->drupalLogin($this->adminUser);
$this
->drupalGet("/admin/content/paragraphs/{$library_item_id}/edit");
$page
->fillField('label[0][value]', 'Library item 1 (rev 3)');
$page
->fillField('paragraphs[0][subform][field_text][0][value]', 'Library item text - Unapproved version');
$page
->selectFieldOption('moderation_state[0][state]', 'draft');
$page
->pressButton('Save');
$this
->drupalLogin($this->visitorUser);
$this
->drupalGet("/node/{$host_node_id}");
$assert_session
->pageTextContains('Library item text 1');
$assert_session
->pageTextNotContains('Library item text - Unapproved version');
$this
->drupalLogin($this->adminUser);
$this
->drupalGet("/admin/content/paragraphs/{$library_item_id}/edit");
$page
->fillField('label[0][value]', 'Library item 1 (rev 4)');
$page
->fillField('paragraphs[0][subform][field_text][0][value]', 'Library item text - Approved version');
$page
->selectFieldOption('moderation_state[0][state]', 'published');
$page
->pressButton('Save');
$this
->drupalLogin($this->visitorUser);
$this
->drupalGet("/node/{$host_node_id}");
$assert_session
->pageTextNotContains('Library item text 1');
$assert_session
->pageTextContains('Library item text - Approved version');
$this
->drupalLogin($this->editorUser);
$this
->drupalGet("/admin/content/paragraphs/{$library_item_id}/edit");
$page
->fillField('label[0][value]', 'Library item 1 (rev 5)');
$page
->fillField('paragraphs[0][subform][field_text][0][value]', 'Library item text - Draft created by editor');
$page
->selectFieldOption('moderation_state[0][state]', 'draft');
$page
->pressButton('Save');
$assert_session
->pageTextContains('Paragraph Library item 1 (rev 5) has been updated.');
$assert_session
->pageTextNotContains('Library item text - Approved version');
$assert_session
->pageTextContains('Library item text - Draft created by editor');
$this
->drupalLogin($this->visitorUser);
$this
->drupalGet("/node/{$host_node_id}");
$assert_session
->pageTextContains('Library item text - Approved version');
$assert_session
->pageTextNotContains('Library item text - Draft created by editor');
$this
->drupalLogin($this->editorUser);
$this
->drupalGet("/node/{$host_node_id}/edit");
$page
->fillField('title[0][value]', 'Host page 1 (rev 6)');
$page
->selectFieldOption('moderation_state[0][state]', 'published');
$page
->find('css', 'a[href="#edit-revision-information"]')
->click();
$page
->fillField('revision_log[0][value]', 'Node revision #6');
$page
->pressButton('Save');
$assert_session
->pageTextContains('paragraphed_moderated_test Host page 1 (rev 6) has been updated.');
$this
->drupalGet("/node/{$host_node_id}");
$assert_session
->pageTextContains('Library item text - Approved version');
$assert_session
->pageTextNotContains('Library item text - Draft created by editor');
drupal_flush_all_caches();
$this
->drupalGet("/admin/content/paragraphs/{$library_item_id}/edit");
$assert_session
->fieldValueEquals('paragraphs[0][subform][field_text][0][value]', 'Library item text - Draft created by editor');
$page
->fillField('label[0][value]', 'Library item 1 (rev 6)');
$page
->selectFieldOption('moderation_state[0][state]', 'published');
$page
->pressButton('Save');
$assert_session
->pageTextContains('Paragraph Library item 1 (rev 6) has been updated.');
$assert_session
->pageTextNotContains('Library item text - Approved version');
$assert_session
->pageTextContains('Library item text - Draft created by editor');
$this
->drupalGet("/node/{$host_node_id}");
$assert_session
->pageTextNotContains('Library item text - Approved version');
$assert_session
->pageTextContains('Library item text - Draft created by editor');
$this
->drupalLogin($this->visitorUser);
$this
->drupalGet("/node/{$host_node_id}");
$assert_session
->pageTextNotContains('Library item text - Approved version');
$assert_session
->pageTextContains('Library item text - Draft created by editor');
$nodes = \Drupal::entityTypeManager()
->getStorage('node')
->getQuery()
->allRevisions()
->condition($host_node
->getEntityType()
->getKey('id'), $host_node
->id())
->execute();
$this
->assertEquals(7, count($nodes));
$library_items = \Drupal::entityTypeManager()
->getStorage('paragraphs_library_item')
->getQuery()
->allRevisions()
->condition($library_item
->getEntityType()
->getKey('id'), $library_item
->id())
->execute();
$this
->assertEquals(6, count($library_items));
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('admin/config/workflow/workflows/manage/' . $this->workflow
->id());
$assert_session
->pageTextNotContains('Paragraph types');
$assert_session
->pageTextContains('Content types');
$assert_session
->elementNotExists('css', 'a[href$="' . $this->workflow
->id() . '/type/paragraph"]');
$assert_session
->elementExists('css', 'a[href$="' . $this->workflow
->id() . '/type/node"]');
$paragraph_type = ParagraphsType::load('text');
$paragraph_type
->setThirdPartySetting('paragraphs_library', 'allow_library_conversion', TRUE);
$paragraph_type
->save();
$this
->drupalGet('/node/add/paragraphed_moderated_test');
$page
->fillField('title[0][value]', 'Host page 1');
$dropbutton_paragraphs = $assert_session
->elementExists('css', '#field-paragraphs-add-more-wrapper .dropbutton-arrow');
$dropbutton_paragraphs
->click();
$add_text_paragraph = $assert_session
->elementExists('css', '#field-paragraphs-text-add-more');
$add_text_paragraph
->press();
$textfield = $assert_session
->waitForElement('css', 'input[name="field_paragraphs[0][subform][field_text][0][value]"]');
$this
->assertNotNull($textfield);
$page
->fillField('field_paragraphs[0][subform][field_text][0][value]', 'Promoted library item');
$first_row = $assert_session
->elementExists('css', '#field-paragraphs-add-more-wrapper tr.draggable:nth-of-type(1)');
$dropdown = $assert_session
->elementExists('css', '.paragraphs-dropdown', $first_row);
$dropdown
->click();
$add_above_button = $assert_session
->elementExists('css', 'input[name="field_paragraphs_0_promote_to_library"]', $first_row);
$add_above_button
->click();
$library_item = $this
->getLastEntityOfType('paragraphs_library_item', TRUE);
$this
->assertEquals('published', $library_item->moderation_state->value);
ParagraphsType::load('text')
->setThirdPartySetting('paragraphs_library', 'allow_library_conversion', TRUE)
->save();
$this
->drupalGet('node/add');
$title = $assert_session
->fieldExists('Title');
$title
->setValue('Paragraph test');
$element = $page
->find('xpath', '//*[contains(@class, "dropbutton-toggle")]');
$element
->click();
$button = $page
->findButton('Add text');
$button
->press();
$assert_session
->waitForElementVisible('css', '.ui-dialog');
$page
->fillField('field_paragraphs[0][subform][field_text][0][value]', 'This is a reusable text UPDATED.');
$first_row = $assert_session
->elementExists('css', '#field-paragraphs-add-more-wrapper tr.draggable:nth-of-type(1)');
$dropdown = $assert_session
->elementExists('css', '.paragraphs-dropdown', $first_row);
$dropdown
->click();
$page
->pressButton('Promote to library');
$assert_session
->assertWaitOnAjaxRequest();
$status_icon = $page
->find('css', '.paragraph-formatter.paragraphs-icon-view');
$this
->assertNull($status_icon);
$edit_button = $page
->find('css', 'input[name^="field_reusable_paragraph_edit_button"]');
$edit_button
->press();
$assert_session
->waitForElementVisible('css', '.ui-dialog');
$assert_session
->elementExists('css', '.ui-dialog')
->selectFieldOption('moderation_state[0][state]', 'archived');
$page
->find('css', '.ui-dialog-buttonset button:contains("Save")')
->press();
$assert_session
->assertWaitOnAjaxRequest();
$status_icon = $page
->find('css', '.paragraphs-icon-view');
$this
->assertTrue($status_icon
->isVisible());
}
public function testModeratedContentNestedParagraphs() {
$session = $this
->getSession();
$page = $session
->getPage();
$assert_session = $this
->assertSession();
$this
->addParagraphsType('rich_paragraph');
$this
->addFieldtoParagraphType('rich_paragraph', 'field_intermediate_text', 'text');
$this
->addFieldtoParagraphType('rich_paragraph', 'field_nested_paragraphs', 'entity_reference', [
'target_type' => 'paragraphs_library_item',
]);
$display = \Drupal::service('entity_display.repository')
->getViewDisplay('paragraph', 'rich_paragraph');
$display
->setComponent('field_nested_paragraphs', [
'type' => 'entity_reference_entity_view',
])
->save();
$this
->drupalGet('/admin/content/paragraphs/add/default');
$page
->fillField('label[0][value]', 'Child library item');
$dropbutton_paragraphs = $assert_session
->elementExists('css', '#edit-paragraphs-add-more .dropbutton-arrow');
$dropbutton_paragraphs
->click();
$add_text_paragraph = $assert_session
->elementExists('css', '#paragraphs-text-add-more');
$add_text_paragraph
->press();
$textfield = $assert_session
->waitForElement('css', 'input[name="paragraphs[0][subform][field_text][0][value]"]');
$this
->assertNotNull($textfield);
$page
->fillField('paragraphs[0][subform][field_text][0][value]', 'This is the low-level text.');
$page
->selectFieldOption('moderation_state[0][state]', 'published');
$page
->find('css', 'a[href="#edit-revision-information"]')
->click();
$page
->fillField('revision_log[0][value]', 'Child initial revision.');
$page
->pressButton('Save');
$assert_session
->pageTextContains('Paragraph Child library item has been created.');
$child_library_item_id = $this
->getLastEntityOfType('paragraphs_library_item');
$this
->drupalGet('/admin/content/paragraphs/add/default');
$page
->fillField('label[0][value]', 'Rich library item');
$dropbutton_paragraphs = $assert_session
->elementExists('css', '#edit-paragraphs-add-more .dropbutton-arrow');
$dropbutton_paragraphs
->click();
$add_rich_paragraph = $assert_session
->elementExists('css', '#paragraphs-rich-paragraph-add-more');
$add_rich_paragraph
->press();
$textfield = $assert_session
->waitForElement('css', 'input[name="paragraphs[0][subform][field_intermediate_text][0][value]"]');
$this
->assertNotNull($textfield);
$page
->fillField('paragraphs[0][subform][field_intermediate_text][0][value]', 'First level text - draft');
$paragraphs_field = $assert_session
->waitForElement('css', 'input[name="paragraphs[0][subform][field_nested_paragraphs][0][target_id]"]');
$this
->assertNotNull($paragraphs_field);
$page
->fillField('paragraphs[0][subform][field_nested_paragraphs][0][target_id]', "Child library item ({$child_library_item_id})");
$page
->selectFieldOption('moderation_state[0][state]', 'draft');
$page
->find('css', 'a[href="#edit-revision-information"]')
->click();
$page
->fillField('revision_log[0][value]', 'Rich item initial revision.');
$page
->pressButton('Save');
$assert_session
->pageTextContains('Paragraph Rich library item has been created.');
$rich_library_item_id = $this
->getLastEntityOfType('paragraphs_library_item');
$this
->drupalGet('/node/add/paragraphed_moderated_test');
$page
->fillField('title[0][value]', 'Host page 2');
$add_from_library_button = $assert_session
->elementExists('css', 'input[name="field_paragraphs_from_library_add_more"]');
$add_from_library_button
->press();
$button = $assert_session
->waitForButton('Select reusable paragraph');
$this
->assertNotNull($button);
$button
->press();
$modal = $assert_session
->waitForElement('css', '.ui-dialog');
$this
->assertNotNull($modal);
$session
->switchToIFrame('entity_browser_iframe_paragraphs_library_items');
$assert_session
->assertWaitOnAjaxRequest();
$assert_session
->pageTextContains('Child library item');
$assert_session
->pageTextContains('Rich library item');
$table = $assert_session
->elementExists('css', 'table.views-table');
$rich_item_row = $this
->getTableRowWithText($table, 'Rich library item');
$rich_item_checkbox = $assert_session
->elementExists('css', 'input[type="radio"]', $rich_item_row);
$rich_item_checkbox
->click();
$page
->pressButton('Select reusable paragraph');
$session
->wait(1000);
$session
->switchToIFrame();
$assert_session
->assertWaitOnAjaxRequest();
$page
->selectFieldOption('moderation_state[0][state]', 'published');
$page
->find('css', 'a[href="#edit-revision-information"]')
->click();
$page
->fillField('revision_log[0][value]', 'Node initial revision');
$page
->pressButton('Save');
$host_node_id = $this
->getLastEntityOfType('node');
$this
->drupalLogin($this->visitorUser);
$this
->drupalGet("/node/{$host_node_id}");
$assert_session
->pageTextNotContains('This is the low-level text.');
$assert_session
->pageTextNotContains('First level text - draft');
$this
->drupalLogin($this->adminUser);
$this
->drupalGet("/admin/content/paragraphs/{$rich_library_item_id}/edit");
$page
->fillField('paragraphs[0][subform][field_intermediate_text][0][value]', 'First level text - published');
$page
->selectFieldOption('moderation_state[0][state]', 'published');
$page
->find('css', 'a[href="#edit-revision-information"]')
->click();
$page
->fillField('revision_log[0][value]', 'Rich item first published revision.');
$page
->pressButton('Save');
$assert_session
->pageTextContains('Paragraph Rich library item has been updated.');
$this
->drupalLogin($this->visitorUser);
$this
->drupalGet("/node/{$host_node_id}");
$assert_session
->pageTextContains('This is the low-level text.');
$assert_session
->pageTextContains('First level text - published');
$this
->drupalLogin($this->adminUser);
$this
->drupalGet("/admin/content/paragraphs/{$child_library_item_id}/edit");
$page
->fillField('paragraphs[0][subform][field_text][0][value]', 'The low-level text has been modified (pending approval).');
$page
->selectFieldOption('moderation_state[0][state]', 'draft');
$page
->find('css', 'a[href="#edit-revision-information"]')
->click();
$page
->fillField('revision_log[0][value]', 'Child item unapproved changes.');
$page
->pressButton('Save');
$assert_session
->pageTextContains('Paragraph Child library item has been updated.');
$this
->drupalLogin($this->visitorUser);
$this
->drupalGet("/node/{$host_node_id}");
$assert_session
->pageTextContains('This is the low-level text.');
$assert_session
->pageTextContains('First level text - published');
$assert_session
->pageTextNotContains('The low-level text has been modified (pending approval).');
$this
->drupalLogin($this->adminUser);
$this
->drupalGet("/admin/content/paragraphs/{$child_library_item_id}/edit");
$page
->fillField('paragraphs[0][subform][field_text][0][value]', 'The low-level text has been modified (approved!).');
$page
->selectFieldOption('moderation_state[0][state]', 'published');
$page
->find('css', 'a[href="#edit-revision-information"]')
->click();
$page
->fillField('revision_log[0][value]', 'Child item approved changes.');
$page
->pressButton('Save');
$assert_session
->pageTextContains('Paragraph Child library item has been updated.');
$this
->drupalLogin($this->visitorUser);
$this
->drupalGet("/node/{$host_node_id}");
$assert_session
->pageTextContains('The low-level text has been modified (approved!).');
$assert_session
->pageTextContains('First level text - published');
$assert_session
->pageTextNotContains('This is the low-level text.');
$this
->drupalLogin($this->adminUser);
$this
->drupalGet("/admin/content/paragraphs/{$child_library_item_id}/revisions");
$table = $assert_session
->elementExists('css', 'table');
$target_row = $this
->getTableRowWithText($table, 'Child initial revision');
$target_row
->clickLink('Revert');
$assert_session
->pageTextContains('Are you sure you want to revert');
$page
->pressButton('Revert');
$assert_session
->pageTextContains(' has been reverted to the revision from ');
$this
->drupalLogin($this->visitorUser);
$this
->drupalGet("/node/{$host_node_id}");
$assert_session
->pageTextContains('This is the low-level text.');
$assert_session
->pageTextContains('First level text - published');
}
protected function getTableRowWithText(Element $table, $search) {
$rows = $table
->findAll('css', 'tr');
if (empty($rows)) {
throw new \Exception(sprintf('No rows found on the received table element.'));
}
foreach ($rows as $row) {
if (strpos($row
->getText(), $search) !== FALSE) {
return $row;
}
}
throw new \Exception(sprintf('Failed to find a row containing "%s" on the received table.', $search));
}
}