public function FieldUiTest::testConfiguringFilter in Field Formatter Filter 2.0.x
Same name and namespace in other branches
- 8 tests/src/Functional/FieldUiTest.php \Drupal\Tests\field_formatter_filter\Kernel\FieldUiTest::testConfiguringFilter()
Test enabling the filter formatter. Check before, during and after.
File
- tests/
src/ Functional/ FieldUiTest.php, line 56
Class
- FieldUiTest
- Tests applying the filter formatter to a node.
Namespace
Drupal\Tests\field_formatter_filter\KernelCode
public function testConfiguringFilter() {
$entity_type = 'node';
$bundle = 'fff_article';
$view_mode = 'default';
$this
->createContentType([
'type' => $bundle,
]);
$node = $this
->createTestNode($bundle);
// Verify that rendering the page initially shows unwanted text.
// We use the browser page fetch to look at the page.
$this
->drupalGet('node/' . $node
->id());
$this
->assertSession()
->pageTextContains('the real content of the body text');
$this
->assertSession()
->responseContains('<li>troublesome lists</li>');
// Now enable the module.
$this->container
->get('module_installer')
->install([
'field_formatter_filter',
], TRUE);
// Log in as a content manager.
$permissions = [
'access administration pages',
'administer site configuration',
"access content",
"create {$bundle} content",
];
$account = $this
->createUser($permissions, 'manager', TRUE);
$this
->drupalLogin($account);
// Open, edit and re-save the field UI, then
// Re-check that all is well, issue #2868519 implies leaving it unconfigured
// may damage normal display.
$this
->drupalGet("/admin/structure/types/manage/{$bundle}/display");
// To edit the field formatter settings, can do it by submitting the
// fields 'cog' button. This is js/no-js safe.
$edit = [];
// Take care of these button identifiers. Unsure how volatile they are.
$this
->submitForm($edit, 'body_settings_edit');
// At this point we should be seeing the field UI edit form with our
// widget options displayed open.
$this
->assertSession()
->pageTextContains(t('Additional Text Filter/Format'));
// And the default current value of it should be '<none>'
// The SELECT actually has that as '0' - which is part of our problem.
# $this->assertSession()->fieldValueEquals(t('Additional Text Filter/Format'), '0');
// Save without deliberately making any change.
$this
->submitForm($edit, 'body_plugin_settings_update');
// OMG, I forgot this annoying extra step even when automating!
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains(t('Your settings have been saved.'));
// After that field UI update, we ensure the the node display
// has not been corrupted as reported in #2868519.
$this
->drupalGet('node/' . $node
->id());
$this
->assertSession()
->pageTextContains('the real content of the body text');
$this
->assertSession()
->responseContains('<li>troublesome lists</li>');
// Proceed with the proper configurations.
// Return to the field UI, choose our option, and check results again.
$this
->drupalGet("/admin/structure/types/manage/{$bundle}/display");
$this
->submitForm($edit, 'body_settings_edit');
// Retrieving the element is the way to set it. Its ID is ridiculous.
$select = $this
->assertSession()
->selectExists(t('Additional Text Filter/Format'));
// fields[body][settings_edit_form][third_party_settings][field_formatter_filter][format]
$select
->selectOption('teaser_safe_text');
$this
->submitForm($edit, 'body_plugin_settings_update');
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains(t('Your settings have been saved.'));
// Now go and see the results.
$this
->drupalGet('node/' . $node
->id());
$this
->assertSession()
->pageTextContains('the real content of the body text');
// Markup should be stripped now!
$this
->assertSession()
->responseNotContains('<li>troublesome lists</li>');
}