You are here

public function EntityconnectAddTest::testAddButton in Entity connect 8.2

Entityconnect add button test.

File

tests/src/Functional/EntityconnectAddTest.php, line 34

Class

EntityconnectAddTest
Tests the Entityconnect add entity function.

Namespace

Drupal\Tests\entityconnect\Functional

Code

public function testAddButton() {

  // Open the create test page.
  $this
    ->drupalGet('node/add/' . $this->testContentType
    ->id());
  $this
    ->assertSession()
    ->elementExists('xpath', '//div[contains(@class, \'entityconnect-add\')]/input');
  $this
    ->assertSession()
    ->elementNotExists('xpath', '//div[contains(@class, \'entityconnect-edit\')]/input');

  // Fill in the title.
  $base_page = $this
    ->getSession()
    ->getPage();
  $base_page
    ->fillField('title[0][value]', 'Base ' . $this->testContentType
    ->label());

  // Click the add button.
  $base_page
    ->findButton('New content')
    ->click();
  $this
    ->assertSession()
    ->responseContains('Create ' . $this->testContentType
    ->label());
  $this
    ->assertSession()
    ->fieldValueEquals('title[0][value]', '');

  // Test Cancel.
  $this
    ->drupalPostForm(NULL, [], 'Cancel');
  $this
    ->assertSession()
    ->fieldValueEquals('title[0][value]', 'Base ' . $this->testContentType
    ->label());

  // Test Create reference Node.
  $base_page = $this
    ->getSession()
    ->getPage();
  $base_page
    ->findButton('New content')
    ->click();
  $ref_page = $this
    ->getSession()
    ->getPage();
  $ref_page
    ->fillField('title[0][value]', 'Referenced ' . $this->testContentType
    ->label());
  $ref_page
    ->findButton('Save')
    ->click();
  $this
    ->assertSession()
    ->fieldValueEquals('title[0][value]', 'Base ' . $this->testContentType
    ->label());

  // Finish creating the base Node.
  $base_page = $this
    ->getSession()
    ->getPage();
  $base_page
    ->findButton('Save')
    ->click();

  // Base node should contain the referenced node.
  $this
    ->assertSession()
    ->pageTextContains('Base ' . $this->testContentType
    ->label());
  $this
    ->assertSession()
    ->pageTextContains('Referenced ' . $this->testContentType
    ->label());
}