ElementWebTest.php in Inline Entity Form 8
File
tests/src/FunctionalJavascript/ElementWebTest.php
View source
<?php
namespace Drupal\Tests\inline_entity_form\FunctionalJavascript;
class ElementWebTest extends InlineEntityFormTestBase {
protected static $modules = [
'inline_entity_form_test',
];
protected function setUp() : void {
parent::setUp();
$this->user = $this
->createUser([
'create ief_simple_single content',
'edit any ief_test_custom content',
'view own unpublished content',
'administer nodes',
]);
$this
->drupalLogin($this->user);
$this->fieldStorageConfigStorage = $this->container
->get('entity_type.manager')
->getStorage('field_storage_config');
}
public function testCustomForm() {
$title_field_xpath = $this
->getXpathForNthInputByLabelText('Title', 1);
$positive_int_field_xpath = $this
->getXpathForNthInputByLabelText('Positive int', 1);
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
foreach ([
'default',
'inline',
] as $form_mode_possibility) {
$title = $this
->randomMachineName();
$this
->drupalGet("ief-test/{$form_mode_possibility}");
$assert_session
->pageTextContains('Title');
$assert_session
->pageTextContains('Positive int');
$this
->checkFormDisplayFields("node.ief_test_custom.{$form_mode_possibility}", 'inline_entity_form');
$page
->pressButton('Save');
$assert_session
->pageTextNotContains("Created Content {$title}");
$this
->assertNoNodeByTitle($title);
$assert_session
->elementExists('xpath', $title_field_xpath)
->setValue($title);
$assert_session
->elementExists('xpath', $positive_int_field_xpath)
->setValue(-1);
$page
->pressButton('Save');
$assert_session
->pageTextNotContains("Created Content {$title}");
$this
->assertNoNodeByTitle($title);
$assert_session
->elementExists('xpath', $positive_int_field_xpath)
->setValue(11);
$page
->pressButton('Save');
$assert_session
->pageTextContains("Created Content {$title}");
$this
->assertNodeByTitle($title, 'ief_test_custom');
$node = $this
->getNodeByTitle($title);
$this
->drupalGet("ief-test/{$form_mode_possibility}/{$node->id()}");
$assert_session
->elementExists('xpath', $title_field_xpath);
$this
->checkFormDisplayFields("node.ief_test_custom.{$form_mode_possibility}", 'inline_entity_form');
$this
->assertSame('11', $assert_session
->elementExists('xpath', $positive_int_field_xpath)
->getValue());
$assert_session
->elementExists('xpath', $title_field_xpath)
->setValue($title . ' - updated');
$page
->pressButton('Update');
$this
->assertNodeByTitle($title . ' - updated', 'ief_test_custom');
}
}
}