Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Currently, we have two methods to create flags in FlagTestBase, createFlag() and createFlagFromForm(). While the latter provides full options, it is slow as it relies on the form. The createFlag() method, on the other hand, is limited.
Proposed resolution
Create a new method in FlagTestBase, createFlagFromArray(). This method provides sensible defaults, which can be overridden by a parameter.
Refactor createFlag() to use createFlagFromArray().
Remaining tasks
Create, test patch.
User interface changes
None.
API changes
Additional methods will be available on FlagTestBase.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#4 | interdiff-2701399-2-4.txt | 1.67 KB | martin107 |
#4 | createFlagRefactor_2701399.4.patch | 3.46 KB | martin107 |
| |||
#2 | createFlagRefactor_2701399.1.patch | 3.21 KB | socketwench |
|
Comments
Comment #2
socketwench CreditAttribution: socketwench at FFW commentedAlso added createGlobalFlag() to simplify global flag tests.
Comment #3
socketwench CreditAttribution: socketwench at FFW commentedComment #4
martin107 CreditAttribution: martin107 commentedI think this change is worthwhile.
A few minor things
1) entiyManager is deprecated
the replacement is \Drupal::service('entity_type.bundle.info')
2) I want to lock down a few parameter input type that we are touching.
In short we should prefix inputs like $edit with array.
This could be done to other methods in the class .. but hey that is for another issue.
3) When I first glanced at createFlagFromArray() my first impression was ok cool that is a pattern I recognise.
I wonder if it is whitelisting key values pairs or if I am free to add values outside the default.
I want the annotations to try and answer that question without the next reader to having to inspect the code, so I added an extra sentence.
Comment #6
joachim CreditAttribution: joachim commentedLogically, if we have both of these, then it should be create(Global|Personal)Flag.
I considered adding something like this when I was working on tests last week.
What made me reconsider was the thought that: a) it doesn't save on that much code, and b) it means that when you see createFlagFromArray([STUFF]) in a test, you then have to go and look in the base class to see what the defaults are for the properties not in STUFF. I am concerned that will make tests harder to read and understand.
Comment #7
socketwench CreditAttribution: socketwench at FFW commentedThat's true, but there's an existing issue to fix this that needs review. But, *shrug* no reason to not fix it here.
I thought about that, but that would require even more refactoring of existing code. The other option would be to just add a $global param to createFlag(). Honestly, I don't think it's that big of a deal.
I think it will make it easier, since there'll be less boilerplate in most of the tests. That was going to be another issue.