View source
<?php
namespace Drupal\Tests\require_on_publish\FunctionalJavascript;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
class ConfigPageTest extends WebDriverTestBase {
protected $defaultTheme = 'stable';
protected static $modules = [
'node',
'field_ui',
'require_on_publish',
'taxonomy',
];
protected $account;
public function setUp() : void {
parent::setUp();
$type = $this->container
->get('entity_type.manager')
->getStorage('node_type')
->create([
'type' => 'article',
'name' => 'Article',
]);
$type
->save();
$this->container
->get('router.builder')
->rebuild();
FieldStorageConfig::create([
'entity_type' => 'node',
'field_name' => 'field_tags',
'type' => 'entity_reference',
'settings' => [
'target_type' => 'taxonomy_term',
],
])
->save();
FieldConfig::create([
'field_name' => 'field_tags',
'entity_type' => 'node',
'bundle' => 'article',
])
->save();
$this->account = $this
->drupalCreateUser([
'administer node fields',
]);
}
protected function logIn() {
$this
->drupalLogin($this->account);
$this
->drupalGet('admin/structure/types/manage/article/fields/node.article.field_tags');
}
public function testRequireOnPublishExists() {
$this
->logIn();
$this
->assertSession()
->fieldExists('require_on_publish');
}
public function testRequireOnPublishToggles() {
$this
->logIn();
$this
->getSession()
->getPage()
->fillField('require_on_publish', 1);
$required = $this
->getSession()
->getPage()
->findField('required')
->getValue();
$this
->assertEquals(0, $required);
$this
->getSession()
->getPage()
->fillField('required', 1);
$required = $this
->getSession()
->getPage()
->findField('require_on_publish')
->getValue();
$this
->assertEquals(0, $required);
}
public function testRequireOnPublishEnable() {
$this
->logIn();
$this
->getSession()
->getPage()
->fillField('require_on_publish', 1);
$this
->getSession()
->getPage()
->pressButton('Save settings');
$required = $this
->getSession()
->getPage()
->findField('require_on_publish')
->getValue();
$this
->assertEquals(1, $required);
}
public function testRequireOnPublishDisable() {
$this
->logIn();
$this
->getSession()
->getPage()
->fillField('require_on_publish', 0);
$this
->getSession()
->getPage()
->pressButton('Save settings');
$required = $this
->getSession()
->getPage()
->findField('require_on_publish')
->getValue();
$this
->assertEquals(0, $required);
}
public function testWarningToggle() {
$this
->logIn();
$this
->getSession()
->getPage()
->fillField('require_on_publish', 1);
$this
->assertSession()
->fieldExists('warn_on_empty');
}
public function testWarningToggleEnable() {
$this
->logIn();
$this
->getSession()
->getPage()
->fillField('require_on_publish', 1);
$this
->getSession()
->getPage()
->fillField('warn_on_empty', 1);
$this
->getSession()
->getPage()
->pressButton('Save settings');
$warning = $this
->getSession()
->getPage()
->findField('warn_on_empty')
->getValue();
$this
->assertEquals($warning, 1);
}
public function testWarningToggleDisable() {
$this
->logIn();
$this
->getSession()
->getPage()
->fillField('require_on_publish', 1);
$this
->getSession()
->getPage()
->fillField('warn_on_empty', 0);
$this
->getSession()
->getPage()
->pressButton('Save settings');
$warning = $this
->getSession()
->getPage()
->findField('warn_on_empty')
->getValue();
$this
->assertEquals($warning, 0);
}
}