Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test for proper validation of autocomplete fields #114

Merged
merged 2 commits into from
Apr 16, 2018
Merged

Conversation

agentrickard
Copy link
Owner

Ensure that users cannot save terms that are not in their sections.


// Try to force an invalid selection.
$this->submitForm([$field => $super_staff_term->label() . ' (' . $super_staff_term->id() . ')', 'title[0][value]' => 'Foo'], 'Save');
$web_assert->pageTextContains('The referenced entity (taxonomy_term: 2) does not exist.');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct me if I'm wrong, but the "The referenced entity (taxonomy_term: 2) does not exist" is coming from core, right? If so, can we somehow override it? I think the message that the entity does not exist can be confusing -- especially if someone has copy and pasted the field from another user that does have permission to use the entity.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure offhand how we would override that string

Copy link
Owner Author

@agentrickard agentrickard Apr 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is coming from core. In Drupal 7, we would reset the messages in drupal_set_message(). Here, in Drupal 8, that's OO code.

Get current messages:

https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Messenger%21MessengerInterface.php/function/MessengerInterface%3A%3AmessagesByType/8.5.x

Inside that class you can read and then empty the messages array.

Then use:

https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Messenger%21MessengerInterface.php/function/MessengerInterface%3A%3AaddMessage/8.5.x

To add the messages we wish to keep and our rewritten message.

I think this can wait for a follow-up.

@agentrickard
Copy link
Owner Author

The test fails are a Travis issue -- see sonnym/travis-ci-drupal-module-example#12

@agentrickard agentrickard merged commit cfc91cc into 8.x-1.x Apr 16, 2018
@agentrickard agentrickard deleted the validate branch April 16, 2018 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants