Problem/Motivation

The template looks like this as of this writing:

  register:
    plugin: static_map
    source: user_register
    default_value: visitors_admin_approval
    map:
      2: visitors_admin_approval
      1: user_register
      0: admin_only

But the constants used in the admin form are

        USER_REGISTER_ADMINISTRATORS_ONLY => $this->t('Administrators only'),
        USER_REGISTER_VISITORS => $this->t('Visitors'),
        USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL => $this->t('Visitors, but administrator approval is required'),

Which map to:

const USER_REGISTER_ADMINISTRATORS_ONLY = 'admin_only';
const USER_REGISTER_VISITORS = 'visitors';
const USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL = 'visitors_admin_approval';

'user_register' is only in the map and 'visitors' is only in the constants so I assume that's the value that needs to be replaced.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

neclimdul created an issue. See original summary.

quietone’s picture

Status: Active » Needs review
FileSize
510 bytes

I agree. A grep for 'user_register' in D8 shows that it only appears in the D6 and D7 dumps and d6_user_settings.yml.

ultimike’s picture

Do we need to write a new or update an existing test to go along with this?

-mike

chx’s picture

As requested in the meta issue, here's how you test this and here's how you find out how to test it: you need to search the codebase. Searching for visitors_admin_approval finds const USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL = 'visitors_admin_approval'; so then we search for the constant and find AccountSettingsForm which uses this constants. A quick search of USER_REGISTER_ in this file shows that the comparisons are used for #open. So: request the form and assertTrue($form['email_admin_created']['#open']) for example. You will need to run the migration as many times as the map to properly cover it and assert the right form key being open every time.

quietone’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests
quietone’s picture

Status: Needs work » Needs review

Talked to chx on IRC about testing this. He said

i was sighing because that test is not necessary

Therefore, marking as needs review.

chx’s picture

Status: Needs review » Needs work

That IRC discussion was a complete comedy of errors and misunderstanding!

Here's what happened (factor in me being jetlagged to hell): we were talking of implementing #4, I finally found it's AccountSettingsForm::create($this->container); in UserAdminSettingsFormTest and said , this is what we need to use as well. Then I went to sleep. Then you asked what's the significance of UserAdminSettingsFormTest. Nothing, nothing, nothing! It's just an example to show how to create that form. What I was (and now much more) frustrated that my well-meaning mention of UserAdminSettingsFormTest completely threw you off track. So. The test in #4 is necessary, mentioning UserAdminSettingsFormTest was not necessary. It is just a place to copy code from.

quietone’s picture

chx, lol. what else can I say? You were jetlagged and I'm suffering from a sore-throat. Neither of us thinking well.

But, I'm very glad we revisited this.

And thanks to your help I've put something together that works. It tests all three possible values of the user_register variable by building the AccountSettings form. For now, I left the all the existing tests. But probably should have removed the assertion on $config->get('register')?

chx’s picture

This is incredible just as I imagined, thanks much! What about creating a loop?

chx’s picture

Status: Needs work » Needs review
Issue tags: -rc eligible, -Needs tests

Let's see what the bot thinks. Finally, what about using the relevant constants?

Status: Needs review » Needs work

The last submitted patch, 8: 2598376-8.patch, failed testing.

quietone’s picture

Status: Needs work » Needs review
FileSize
3.38 KB
2.77 KB

Yes, I was thinking the same thing. Here it is.

I'm liking this approach.

chx’s picture

Status: Needs review » Reviewed & tested by the community

That's great. I would've used [USER_REGISTER_ADMINISTRATORS_ONLY, USER_REGISTER_VISITORS, USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL] as the map because the keys happen to be 0,1,2 but that's perhaps the wrong kind of clever. This is explicit and nice.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Fixed some whitespace and a trailing period on commit.

Committed/pushed to 8.1.x and cherry-picked to 8.0.x. Thanks!

Failed to add chx to the commit message, but adding commit credit to issue.

  • catch committed 4ad9cf7 on 8.1.x
    Issue #2598376 by quietone: d6_user_settings migration user_register...

  • catch committed 75cc4c7 on
    Issue #2598376 by quietone: d6_user_settings migration user_register...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.