You are here

public function WebformNodeEntityReferenceTest::testEntityReference in Webform 8.5

Same name and namespace in other branches
  1. 6.x modules/webform_node/tests/src/Functional/WebformNodeEntityReferenceTest.php \Drupal\Tests\webform_node\Functional\WebformNodeEntityReferenceTest::testEntityReference()

Tests webform node entity references.

File

modules/webform_node/tests/src/Functional/WebformNodeEntityReferenceTest.php, line 31

Class

WebformNodeEntityReferenceTest
Tests for webform node entity references.

Namespace

Drupal\Tests\webform_node\Functional

Code

public function testEntityReference() {
  $user_data = \Drupal::service('user.data');
  $this
    ->drupalLogin($this->rootUser);

  // Check that both webform A & B are being displayed.
  $this
    ->drupalGet('/node/1');
  $this
    ->assertRaw('webform_test_multiple_a');
  $this
    ->assertRaw('textfield_a');
  $this
    ->assertRaw('webform_test_multiple_b');
  $this
    ->assertRaw('textfield_a');

  /**************************************************************************/

  // Check test form B (B is the default because its weight is -1).
  $this
    ->drupalGet('/node/1/webform/test');
  $this
    ->assertNoRaw('textfield_a');
  $this
    ->assertRaw('textfield_b');

  // Check result webform B.
  $this
    ->drupalGet('/node/1/webform/results/submissions');
  $this
    ->assertNoRaw('textfield_a');
  $this
    ->assertRaw('textfield_b');

  // Check export webform B.
  $this
    ->drupalGet('/node/1/webform/results/download');
  $this
    ->assertNoRaw('textfield_a');
  $this
    ->assertRaw('textfield_b');

  // Check user data is NULL.
  $this
    ->assertNull($user_data
    ->get('webform_node', $this->rootUser
    ->id(), 1));

  /**************************************************************************/

  // Select webform A.
  $this
    ->drupalGet('/node/1/webform/test');
  $this
    ->clickLink('Test: Webform Node Multiple A');

  // Check user data is set to webform A.
  $this
    ->assertEqual([
    'target_id' => 'webform_node_test_multiple_a',
  ], $user_data
    ->get('webform_node', $this->rootUser
    ->id(), 1));

  // Check test webform A.
  $this
    ->drupalGet('/node/1/webform/test');
  $this
    ->assertRaw('textfield_a');
  $this
    ->assertNoRaw('textfield_b');

  // Check result webform A.
  $this
    ->drupalGet('/node/1/webform/results/submissions');
  $this
    ->assertRaw('textfield_a');
  $this
    ->assertNoRaw('textfield_b');

  // Check export webform A.
  $this
    ->drupalGet('/node/1/webform/results/download');
  $this
    ->assertRaw('textfield_a');
  $this
    ->assertNoRaw('textfield_b');

  /**************************************************************************/

  // Select webform A.
  $this
    ->drupalGet('/node/1/webform/test');
  $this
    ->clickLink('Test: Webform Node Multiple A');

  // Check user data is set to webform A.
  $this
    ->assertEqual([
    'target_id' => 'webform_node_test_multiple_a',
  ], $user_data
    ->get('webform_node', $this->rootUser
    ->id(), 1));

  // Check test webform A.
  $this
    ->drupalGet('/node/1/webform/test');
  $this
    ->assertRaw('textfield_a');
  $this
    ->assertNoRaw('textfield_b');

  // Check result webform A.
  $this
    ->drupalGet('/node/1/webform/results/submissions');
  $this
    ->assertRaw('textfield_a');
  $this
    ->assertNoRaw('textfield_b');

  // Check export webform A.
  $this
    ->drupalGet('/node/1/webform/results/download');
  $this
    ->assertRaw('textfield_a');
  $this
    ->assertNoRaw('textfield_b');

  /**************************************************************************/

  // Delete the node.
  Node::load(1)
    ->delete();

  // Check user data is NULL (aka deleted).
  $this
    ->assertNull($user_data
    ->get('webform_node', $this->rootUser
    ->id(), 1));
}