class FieldUITest
Same name in this branch
- 9 core/modules/field/tests/src/Functional/Views/FieldUITest.php \Drupal\Tests\field\Functional\Views\FieldUITest
- 9 core/modules/field_ui/tests/src/Unit/FieldUiTest.php \Drupal\Tests\field_ui\Unit\FieldUiTest
Same name and namespace in other branches
- 11.x core/modules/field/tests/src/Functional/Views/FieldUITest.php \Drupal\Tests\field\Functional\Views\FieldUITest
- 11.x core/modules/field_ui/tests/src/Unit/FieldUiTest.php \Drupal\Tests\field_ui\Unit\FieldUiTest
- 11.x core/modules/views_ui/tests/src/Functional/FieldUITest.php \Drupal\Tests\views_ui\Functional\FieldUITest
Tests the UI of field handlers.
@group views_ui
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\Tests\views\Functional\ViewTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait implements \Drupal\Tests\BrowserTestBase
- class \Drupal\Tests\views_ui\Functional\UITestBase implements \Drupal\Tests\views\Functional\ViewTestBase
- class \Drupal\Tests\views_ui\Functional\FieldUITest implements \Drupal\Tests\views_ui\Functional\UITestBase
- class \Drupal\Tests\views_ui\Functional\UITestBase implements \Drupal\Tests\views\Functional\ViewTestBase
- class \Drupal\Tests\views\Functional\ViewTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait implements \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of FieldUITest
See also
\Drupal\views\Plugin\views\field\FieldPluginBase
File
-
core/
modules/ views_ui/ tests/ src/ Functional/ FieldUITest.php, line 14
Namespace
Drupal\Tests\views_ui\FunctionalView source
class FieldUITest extends UITestBase {
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = [
'test_view',
];
/**
* Tests the UI of field handlers.
*/
public function testFieldUI() {
// Ensure the field is not marked as hidden on the first run.
$this->drupalGet('admin/structure/views/view/test_view/edit');
$this->assertSession()
->pageTextContains('Views test: Name');
$this->assertSession()
->pageTextNotContains('Views test: Name [hidden]');
// Hides the field and check whether the hidden label is appended.
$edit_handler_url = 'admin/structure/views/nojs/handler/test_view/default/field/name';
$this->drupalGet($edit_handler_url);
$this->submitForm([
'options[exclude]' => TRUE,
], 'Apply');
$this->assertSession()
->pageTextContains('Views test: Name [hidden]');
// Ensure that the expected tokens appear in the UI.
$edit_handler_url = 'admin/structure/views/nojs/handler/test_view/default/field/age';
$this->drupalGet($edit_handler_url);
$xpath = '//details[@id="edit-options-alter-help"]/ul/li';
$this->assertSession()
->elementTextEquals('xpath', $xpath, '{{ age }} == Age');
$edit_handler_url = 'admin/structure/views/nojs/handler/test_view/default/field/id';
$this->drupalGet($edit_handler_url);
$this->assertSession()
->elementTextEquals('xpath', "{$xpath}[1]", '{{ age }} == Age');
$this->assertSession()
->elementTextEquals('xpath', "{$xpath}[2]", '{{ id }} == ID');
$edit_handler_url = 'admin/structure/views/nojs/handler/test_view/default/field/name';
$this->drupalGet($edit_handler_url);
$this->assertSession()
->elementTextEquals('xpath', "{$xpath}[1]", '{{ age }} == Age');
$this->assertSession()
->elementTextEquals('xpath', "{$xpath}[2]", '{{ id }} == ID');
$this->assertSession()
->elementTextEquals('xpath', "{$xpath}[3]", '{{ name }} == Name');
$this->assertSession()
->elementNotExists('xpath', '//details[@id="edit-options-more"]');
// Ensure that dialog titles are not escaped.
$edit_groupby_url = 'admin/structure/views/nojs/handler/test_view/default/field/name';
$this->assertSession()
->linkByHrefNotExists($edit_groupby_url, 0, 'No aggregation link found.');
// Enable aggregation on the view.
$edit = [
'group_by' => TRUE,
];
$this->drupalGet('/admin/structure/views/nojs/display/test_view/default/group_by');
$this->submitForm($edit, 'Apply');
$this->assertSession()
->linkByHrefExists($edit_groupby_url, 0, 'Aggregation link found.');
$edit_handler_url = '/admin/structure/views/ajax/handler-group/test_view/default/field/name';
$this->drupalGet($edit_handler_url);
$data = Json::decode($this->getSession()
->getPage()
->getContent());
$this->assertEquals('Configure aggregation settings for field Views test: Name', $data[3]['dialogOptions']['title']);
}
/**
* Tests the field labels.
*/
public function testFieldLabel() {
// Create a view with unformatted style and make sure the fields have no
// labels by default.
$view = [];
$view['label'] = $this->randomMachineName(16);
$view['id'] = strtolower($this->randomMachineName(16));
$view['description'] = $this->randomMachineName(16);
$view['show[wizard_key]'] = 'node';
$view['page[create]'] = TRUE;
$view['page[style][style_plugin]'] = 'default';
$view['page[title]'] = $this->randomMachineName(16);
$view['page[path]'] = $view['id'];
$this->drupalGet('admin/structure/views/add');
$this->submitForm($view, 'Save and edit');
$view = Views::getView($view['id']);
$view->initHandlers();
$this->assertEquals('', $view->field['title']->options['label'], 'The field label for normal styles are empty.');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.