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.
Add a getCredentials helper method instead of repeating a 20-25 line block of code in the tests.
Comment | File | Size | Author |
---|---|---|---|
#15 | interdiff_11-15.txt | 1.44 KB | pavnish |
#15 | 3143719-15.patch | 14.52 KB | pavnish |
#9 | 3143719-9.patch | 14.41 KB | quietone |
#9 | interdiff-7-9.txt | 2.76 KB | quietone |
#7 | 3143719-7.patch | 12.25 KB | quietone |
Comments
Comment #2
quietone CreditAttribution: quietone as a volunteer commentedComment #3
quietone CreditAttribution: quietone as a volunteer commentedComment #4
benjifisherThis is a great idea! It takes all that code that confused me when I was reviewing #2925899: MigrateUpgradeImportBatch does not use source_private_file_path & source_base_path correctly, making it impossible to have public & private files in separate locations and puts it in one place, where we can add some better documentation.
See (3) below before making any changes to the
@param
comments.This is for posting to the credential form, right? I think it should say so in the one-line description: "Creates an array of credentials to post to the credential form". Also add an
@see
for that form. Then someone who has never looked at this code before, like me, will know where to look for the expected keys.Can you say something more about the Source database connection options? From the code, I can see that it has keys
'driver'
and'prefix'
, but that is all I know.The legacy Drupal version can only be 6 or 7, right? That seems obvious today, but wait until Drupal 10 is released. ;)
It looks as though we can delete the first few lines of this function: everything before the comment, "Get valid credentials".
It seems that every call to this function starts with
Why not do that inside the function instead of passing these as parameters?
I am a little worried about how this will be affected by #2925899: MigrateUpgradeImportBatch does not use source_private_file_path & source_base_path correctly, making it impossible to have public & private files in separate locations:
Will it be as simple as replacing the line that defines
'source_private_file_path'
with the newgetSourcePrivateBasePath()
(which defaults toNULL
)? Even if it is that simple, we will have to update one of these issues when we commit the other, so I will add it as a related issue.Related to the previous point:
This makes it impractical for the calling function to modify the returned result. If we just
return $edit
, then it is a lot easier. The only cost is that the calling function has to call$this->translatePostValues()
. It is an instance of the single-responsibility principle: what is the one thing that this function is responsible for doing?Comment #5
quietone CreditAttribution: quietone as a volunteer commentedConfusing, indeed!
1. It seems reasonable to remove that input parameters, this->sourceDatabase which is created in setUp() and get the legacy version from that.
2. Nice, I missed that.
3. At the time there was a reason but I can't think of it and I can't see a reason now. Fixed.
4. Yes, If #2925899: MigrateUpgradeImportBatch does not use source_private_file_path & source_base_path correctly, making it impossible to have public & private files in separate locations gets in first then this will need a reroll. What is here is keeping the current behaviour.
5. Not sure I agree in this case but not enough to make an argument. Fixed.
Comment #7
quietone CreditAttribution: quietone as a volunteer commentedRight, $edits is no longer defined in the base class.
Comment #8
benjifisherThe patch in #7 looks a lot better. Thanks! In particular, removing the parameters to
getCredentials()
means we do not need extensive@param
comments. The API docs fordrupal_get_database_types()
are a few links away fromgetFormOptions()
, which makes the structure pretty clear. I think we could add some information to$sourceDatabase
, but that is out of scope for this issue.I have just a couple more requests:
Follow-up to #4.5:
It should now be
@return array
. The following description needs to be updated as well. Maybe "… suitable for BrowserTestBase::translatePostValues()"? Certainly, remove "flattened".To be honest, I am not sure #4.5 is a good idea, either. Some day, if we are adding a new test and we need to change one of the nested array values, we will be glad we did it this way. That day may never come, but if it does then we do not want to do more of the copy/paste that we are fixing in this issue.
I see you took the opportunity to use the new helper function in another file, MultilingualReviewPageTestBase.php. Good! That made me wonder if there are any other places we should use it, so I searched for
getFormOptions()
. Is there any reason not to use it inMigrateUpgradeExecuteTestBase::testMigrateUpgradeExecute()
?Comment #9
quietone CreditAttribution: quietone as a volunteer commentedYes, it is coming along nicely.
1. Fixed. Not sure the comments are right but it is start.
2. The reason is that that file is going to be removed so I thought, just leave alone for now. But it is better to make the change everywhere now. Done.
Comment #10
benjifisherGiven the one-line description and the
@see
comment, I think we can remove the extra comment and just use "An array of values suitable for BrowserTestBase::translatePostValues()." as the@return
comment. I think that fits one one line; if not, then both lines should be indented.We can remove a few more lines here.
Comment #11
pavnish CreditAttribution: pavnish at Srijan | A Material+ Company for Drupal India Association commentedworking on it
Comment #12
pavnish CreditAttribution: pavnish at Srijan | A Material+ Company for Drupal India Association commented@benjifisher Could you please review this patch for #10
Comment #13
benjifisher@pavnish:
Thanks for trying to finish off this issue.
If you remove the words "to post that are", then the
@return
comment should fit on a single line. I do not think the meaning suffers.In addition to the blank line(s), every line I quoted in #10.2 that includes
$connection_options
can be removed. But do not take my word for it: check that the variables$connection_options
and$driver
are not used later.Comment #14
benjifisherComment #15
pavnish CreditAttribution: pavnish at Srijan | A Material+ Company for Drupal India Association commented@benjifisher sorry for that.
Could you please review this patch.I have also remove unused code from "testMigrateUpgradeExecute"
Yes $connection_options and $driver are used in $this->drupalPostForm(NULL, [$driver . '[database]' => 'wrong'] + $edits, t('Review upgrade'));
$driver = $connection_options['driver'];
So we can not remove this.
Comment #16
benjifisher@pavnish:
I am not sure what you mean by this:
Comment #17
pavnish CreditAttribution: pavnish at Srijan | A Material+ Company for Drupal India Association commented@benjifisher sorry for late reply .I mean that the $connection_options and $driver are using in code so we cannot remove this.
Comment #18
quietone CreditAttribution: quietone as a volunteer commented@pavnish, thanks. Changing back to NR
Comment #19
benjifisherLooking at it again, I see that you are right.
We should at least rearrange those lines:
We can combine the first two lines, eliminating the
$connection_options
variable. For the purposes of this test, do we need to use the same$driver
or could we just use'mysql[database]' => 'wrong'
? Or should I not worry about it--is this one of the tests we plan to remove in #3143720: Create a separate CredentialFormTest?This test is close to the situation I described in #8.2, where we want to modify the value we get from
getCredentials()
. In this case, we are not modifying a nested key, so we can work with the flattened array.Comment #20
quietone CreditAttribution: quietone as a volunteer commentedYes, this is one of the tests that is being moved to a separate test in #3143720: Create a separate CredentialFormTest. Personally, I think it would be better to improve that code while working in the other issue and keep this focused on the new getCredentials() method.
Comment #21
quietone CreditAttribution: quietone as a volunteer commentedComment #22
benjifisherOK. We will be moving the code, not removing it, but we can clean it up as part of the move if you prefer. RTBC.
Comment #24
catchCommitted 4df1ca4 and pushed to 9.1.x. Thanks!