EntityconnectAddTest.php in Entity connect 8.2
File
tests/src/Functional/EntityconnectAddTest.php
View source
<?php
namespace Drupal\Tests\entityconnect\Functional;
use Drupal\Core\StringTranslation\StringTranslationTrait;
class EntityconnectAddTest extends EntityconnectTestBase {
use StringTranslationTrait;
protected function setUp() {
parent::setUp();
$this->ecUser
->addRole('ec_add');
$this->ecUser
->save();
$this
->setEcButtons(TRUE, FALSE);
$this
->drupalLogin($this->ecUser);
}
public function testAddButton() {
$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');
$base_page = $this
->getSession()
->getPage();
$base_page
->fillField('title[0][value]', 'Base ' . $this->testContentType
->label());
$base_page
->findButton('New content')
->click();
$this
->assertSession()
->responseContains('Create ' . $this->testContentType
->label());
$this
->assertSession()
->fieldValueEquals('title[0][value]', '');
$this
->drupalPostForm(NULL, [], 'Cancel');
$this
->assertSession()
->fieldValueEquals('title[0][value]', 'Base ' . $this->testContentType
->label());
$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());
$base_page = $this
->getSession()
->getPage();
$base_page
->findButton('Save')
->click();
$this
->assertSession()
->pageTextContains('Base ' . $this->testContentType
->label());
$this
->assertSession()
->pageTextContains('Referenced ' . $this->testContentType
->label());
}
public function testAddWithMultipleTypes() {
$extra_type = $this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
$this
->updateEntityReferenceFieldTargets([
$extra_type
->id(),
]);
$this
->drupalGet('node/add/' . $this->testContentType
->id());
$base_page = $this
->getSession()
->getPage();
$base_page
->findButton('New content')
->click();
$this
->assertSession()
->responseContains('Create ' . $this->testContentType
->label());
$this
->drupalCreateRole([
"create {$extra_type->id()} content",
], "ec_add_{$extra_type->id()}");
$this->ecUser
->addRole("ec_add_{$extra_type->id()}");
$this->ecUser
->save();
$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());
$sel_page = $this
->getSession()
->getPage();
$sel_page
->clickLink($extra_type
->label());
$this
->assertSession()
->pageTextContains('Create ' . $extra_type
->label());
}
}