public function EntityconnectAddTest::testAddWithMultipleTypes in Entity connect 8.2
Entityconnect add with multiple types test.
File
- tests/
src/ Functional/ EntityconnectAddTest.php, line 72
Class
- EntityconnectAddTest
- Tests the Entityconnect add entity function.
Namespace
Drupal\Tests\entityconnect\FunctionalCode
public function testAddWithMultipleTypes() {
// Create another content type.
$extra_type = $this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
// Add it to the entity reference field as a target.
$this
->updateEntityReferenceFieldTargets([
$extra_type
->id(),
]);
// Test select page not shown if user only has access to one target type.
$this
->drupalGet('node/add/' . $this->testContentType
->id());
$base_page = $this
->getSession()
->getPage();
$base_page
->findButton('New content')
->click();
// No select page, just go right to create ec test page.
$this
->assertSession()
->responseContains('Create ' . $this->testContentType
->label());
// Grant ec user permission to create the extra type.
$this
->drupalCreateRole([
"create {$extra_type->id()} content",
], "ec_add_{$extra_type->id()}");
$this->ecUser
->addRole("ec_add_{$extra_type->id()}");
$this->ecUser
->save();
// Now test the page to select node type.
$this
->drupalGet('node/add/' . $this->testContentType
->id());
$base_page = $this
->getSession()
->getPage();
$base_page
->findButton('New content')
->click();
$this
->assertSession()
->pageTextContains('Choose type to create and add');
$this
->assertSession()
->linkExists($this->testContentType
->label());
$this
->assertSession()
->linkExists($extra_type
->label());
// Test Extra type selection.
$sel_page = $this
->getSession()
->getPage();
$sel_page
->clickLink($extra_type
->label());
$this
->assertSession()
->pageTextContains('Create ' . $extra_type
->label());
}