You are here

public function QuickNodeCloneExcludeParagraphFieldsTest::testNodeCloneExcludeParagraphFields in Quick Node Clone 8

Test node clone excluding fields.

File

tests/src/Functional/QuickNodeCloneExcludeParagraphFieldsTest.php, line 72

Class

QuickNodeCloneExcludeParagraphFieldsTest
Tests node cloning excluding paragraph fields.

Namespace

Drupal\Tests\quick_node_clone\Functional

Code

public function testNodeCloneExcludeParagraphFields() {
  $this
    ->loginAsAdmin([
    'create paragraphed_test content',
    'edit any paragraphed_test content',
    'Administer Quick Node Clone Settings',
    'clone paragraphed_test content',
  ]);

  // Test the form.
  $this
    ->drupalGet('admin/config/quick-node-clone-paragraph');
  $this
    ->assertSession()
    ->fieldValueEquals('text_paragraph[field_text2]', 'field_text2');

  // Create a node and add two Paragraphs.
  $this
    ->drupalGet('node/add/paragraphed_test');
  $title_value = $this->randomGenerator
    ->word(10);
  $text1 = $this->randomGenerator
    ->word(10);
  $text2 = $this->randomGenerator
    ->word(10);
  $edit = [
    'title[0][value]' => $title_value,
    'field_paragraphs[0][subform][field_text1][0][value]' => $text1,
    'field_paragraphs[0][subform][field_text2][0][value]' => $text2,
  ];
  $this
    ->submitForm([], 'field_paragraphs_text_paragraph_add_more');
  $this
    ->submitForm($edit, 'Save');
  $node = $this
    ->drupalGetNodeByTitle($title_value);
  $this
    ->drupalGet('node/' . $node
    ->id() . '/edit');
  $this
    ->assertSession()
    ->fieldValueEquals('field_paragraphs[0][subform][field_text1][0][value]', $text1);
  $this
    ->assertSession()
    ->fieldValueEquals('field_paragraphs[0][subform][field_text2][0][value]', $text2);
  $this
    ->submitForm([], 'Save');
  $this
    ->assertSession()
    ->pageTextContains($text1);
  $this
    ->assertSession()
    ->pageTextContains($text2);

  // Clone node.
  $this
    ->clickLink('Clone');
  $this
    ->drupalGet('clone/' . $node
    ->id() . '/quick_clone');
  $this
    ->assertSession()
    ->fieldValueEquals('field_paragraphs[0][subform][field_text1][0][value]', $text1);
  $this
    ->assertSession()
    ->fieldValueEquals('field_paragraphs[0][subform][field_text2][0][value]', '');
  $this
    ->drupalGet('clone/' . $node
    ->id() . '/quick_clone');
  $this
    ->submitForm([], 'Save');
  $this
    ->assertSession()
    ->responseContains('Clone of ' . $title_value);

  // Make sure text_2 paragraph was cloned.
  $this
    ->assertSession()
    ->pageTextContains($text1);

  // Make sure text_2 paragraph was not cloned.
  $this
    ->assertSession()
    ->pageTextNotContains($text2);
}