FieldTest.php in Drupal 9
File
core/modules/views/tests/src/FunctionalJavascript/Plugin/views/Handler/FieldTest.php
View source
<?php
namespace Drupal\Tests\views\FunctionalJavascript\Plugin\views\Handler;
use Drupal\Tests\SchemaCheckTestTrait;
use Drupal\field\Entity\FieldConfig;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\node\Entity\NodeType;
use Drupal\views\Tests\ViewTestData;
class FieldTest extends WebDriverTestBase {
use SchemaCheckTestTrait;
protected static $modules = [
'node',
'views',
'views_ui',
'views_test_config',
];
protected $defaultTheme = 'stark';
public static $testViews = [
'test_field_body',
];
protected $account;
protected function setUp() : void {
parent::setUp();
ViewTestData::createTestViews(static::class, [
'views_test_config',
]);
\Drupal::configFactory()
->getEditable('views.settings')
->set('ui.always_live_preview', FALSE)
->save();
$this->account = $this
->drupalCreateUser([
'administer views',
]);
$this
->drupalLogin($this->account);
NodeType::create([
'type' => 'page',
])
->save();
FieldConfig::create([
'entity_type' => 'node',
'field_name' => 'body',
'bundle' => 'page',
])
->save();
}
public function testFormatterChanging() {
$web_assert = $this
->assertSession();
$url = '/admin/structure/views/view/test_field_body';
$this
->drupalGet($url);
$page = $this
->getSession()
->getPage();
$page
->clickLink('Body field');
$web_assert
->assertWaitOnAjaxRequest();
$page
->fillField('options[type]', 'text_trimmed');
$web_assert
->assertWaitOnAjaxRequest();
$page
->fillField('options[settings][trim_length]', '700');
$apply_button = $page
->find('css', '.views-ui-dialog button.button--primary');
$this
->assertTrue(!empty($apply_button));
$apply_button
->press();
$web_assert
->assertWaitOnAjaxRequest();
$save_button = $page
->find('css', '#edit-actions-submit');
$save_button
->press();
$this
->drupalGet($url);
$page
->clickLink('Body field');
$web_assert
->assertWaitOnAjaxRequest();
$page
->fillField('options[type]', 'text_default');
$web_assert
->assertWaitOnAjaxRequest();
$apply_button = $page
->find('css', '.views-ui-dialog button.button--primary');
$apply_button
->press();
$web_assert
->assertWaitOnAjaxRequest();
$save_button = $page
->find('css', '#edit-actions-submit');
$save_button
->press();
$this
->assertConfigSchemaByName('views.view.test_field_body');
}
}