Test patches

Video loading...

  • 0:00
    Test patches
  • 0:01
    Learn Drupal Ladder
  • 0:03
    with Addison Berry
  • 0:07
    In this lesson, we're going
  • 0:08
    to be looking at a really important task, which is testing patches.
  • 0:12
    You don't have to be a coder in order to test patches.
  • 0:14
    And if you are a coder, you learn a lot
  • 0:16
    about how the community codes together from testing
  • 0:18
    other people's patches.
  • 0:20
    So we'll be playing around a little bit with our Git
  • 0:22
    we'll be grabbing a patch from Drupal.org,
  • 0:25
    we'll be applying that to our local a solution of Drupal 8,
  • 0:29
    and then testing it to see if it actually works properly,
  • 0:31
    so that we can report back to the issue queue.
  • 0:35
    So we're going to start off on the DrupalLadder.org website.
  • 0:39
    And I'll go to the Drupal ladder tab,
  • 0:41
    which is the main Drupal ladder.
  • 0:42
    And if we scroll down here, we'll find the steps that we've already
  • 0:46
    completed-- the first three steps.
  • 0:49
    And we're going to do the test patches step this time.
  • 0:53
    And once we get here-- so we have the overview,
  • 0:56
    it sort of explains what we're going to be doing.
  • 0:58
    And you'll also see that there are a list of prerequisites.
  • 1:02
    So we need to have a sandbox Drupal 8 site, which
  • 1:06
    already has a bug in it for us.
  • 1:08
    And we need to have Git installed in order for us
  • 1:11
    to complete the lesson that we have.
  • 1:13
    So I already have my sandbox site set up,
  • 1:16
    and I do have Git installed on here.
  • 1:18
    The other thing that you'll notice is, before we begin,
  • 1:20
    you can optionally run some Git commands to add some configuration
  • 1:25
    to your Git config file.
  • 1:27
    That just makes things a little prettier when you're using Git,
  • 1:31
    adding some coloring to make it easier to read some of the output
  • 1:34
    from Git.
  • 1:35
    So you can go ahead and do that if you'd like.
  • 1:37
    And I already have that on my local version of Git.
  • 1:40
    I've already run these commands earlier.
  • 1:43
    So the first thing that we're going to want to do to get started here
  • 1:47
    testing our patch is-- the first three steps are basically making
  • 1:51
    sure that we are in our sandbox, and that we're
  • 1:53
    using the correct branch.
  • 1:55
    And then, we'll go on and actually read an issue, get a patch,
  • 1:59
    and see if it works.
  • 2:01
    So first, let me actually get to where I need to be.
  • 2:05
    Right now, I'm in my home directory.
  • 2:08
    So I'm going to go ahead and cd into where I have my Drupal sandbox,
  • 2:11
    which I've already Git cloned.
  • 2:16
    And then I'm going to just to git branch,
  • 2:18
    and that will list the branches that I have.
  • 2:20
    And right now, I only have one, which is 8.x,
  • 2:22
    and that has a star next to it.
  • 2:23
    That means that's the current branch that I'm on.
  • 2:27
    So I just want to make sure I'm in the right place.
  • 2:29
    I am, so I don't need to change around or check anything out.
  • 2:33
    And so now, we're going to actually go
  • 2:34
    to the example issue that's on Drupal.org
  • 2:37
    that we're going to be working from here.
  • 2:39
    So let me open that up in another tab.
  • 2:42
    And you can see, this is in the Drupal 8 sandbox issue queue.
  • 2:46
    And this has an issue that's explaining
  • 2:49
    sort of what's going on here.
  • 2:52
    There's a bug that's been found, and there's
  • 2:54
    a proposed solution to that.
  • 2:57
    So that's the issue we're trying to do.
  • 3:00
    So we should first make sure that we can actually find this bug that's
  • 3:04
    being reported in our current code base,
  • 3:07
    so that we know what it is, when we test
  • 3:09
    the patch, what should be changing.
  • 3:12
    So I'm going to go over to my sandbox site.
  • 3:15
    And once in here, I just want to add some content,
  • 3:18
    because that's where this bug is found.
  • 3:19
    So I'm going to add just an article.
  • 3:21
    I'm not going to actually create one.
  • 3:23
    But if we go down to the bottom of the create article page here,
  • 3:28
    you'll see the URL path settings tab.
  • 3:31
    And that's where this unclear help text is that they want to improve.
  • 3:37
    So I can see what the issue is actually about.
  • 3:40
    I can see that here in my local site.
  • 3:43
    And now what I'm going to do is download a patch that's
  • 3:46
    been created to correct that, and see if it actually works,
  • 3:49
    and make sure it doesn't break anything else
  • 3:51
    or do anything else weird.
  • 3:53
    So I want to download the patch that is in the second comment,
  • 3:57
    the latest patch.
  • 3:57
    There are two patches, but I want the latest patch-- there's no point
  • 4:01
    in testing something from earlier.
  • 4:02
    First, I can click-- I can actually just read it in my browser
  • 4:05
    and see what the changes are.
  • 4:07
    This is a relatively small and simple patch,
  • 4:10
    so I can actually just sort of see what's happening here.
  • 4:12
    But it's always a good idea just to take a look.
  • 4:16
    And then, to actually get a copy of it,
  • 4:18
    there are sort of two ways I can do this.
  • 4:19
    I can copy the link address and use something like wget or cURL
  • 4:23
    from the command line.
  • 4:24
    Or I can just save it, however in your browser you would save a link,
  • 4:28
    I just want to save this file onto my local system here.
  • 4:31
    So I'm going to go into my site's Drupal 8 sandbox,
  • 4:35
    and I'm going to put it directly in the root
  • 4:36
    of my Drupal 8 sandbox site.
  • 4:41
    And then, now if I come back to my command line and list,
  • 4:44
    you'll see that I have that patch file, that .patch
  • 4:46
    file is now in my Drupal directory.
  • 4:50
    It's just a handy place to have it, to make sure that we know what's
  • 4:53
    going on when I come to apply it.
  • 4:56
    And so the next step is going to be actually apply that.
  • 4:59
    And you can see there's this git apply command.
  • 5:01
    And then we just need the actual path to that patch file.
  • 5:08
    So git apply, and then since I'm already here, where the patch is,
  • 5:12
    I don't need a full path.
  • 5:13
    I just need to put the file name.
  • 5:16
    And go ahead and hit Enter, and ta-da.
  • 5:19
    I didn't get any errors or a report back that there was anything wrong.
  • 5:23
    So everything applied correctly.
  • 5:25
    If I do a git status, I can see that there's
  • 5:29
    a file that's been modified now.
  • 5:30
    So the path module got modified when I applied that patch.
  • 5:35
    And if other files had been modified,
  • 5:37
    they would all be listed there.
  • 5:39
    And now let's go back to the site, and I'm going to reload this page,
  • 5:44
    and then come back down and look at that same setting.
  • 5:47
    And now we can see the new text.
  • 5:49
    So I can review this, and I can put forth my opinion on whether I
  • 5:54
    think that text is correct.
  • 5:56
    But the patch certainly works, and that's the main thing.
  • 6:00
    So at this point, we would go back and we would make
  • 6:03
    a comment saying, yes, it worked.
  • 6:05
    I think this language is good.
  • 6:07
    If I had suggestions for new language,
  • 6:08
    I could put that in there.
  • 6:11
    And then once we're done with all of that-- I'm
  • 6:13
    going to clear my screen-- to get rid of that change,
  • 6:17
    I would use git reset --hard.
  • 6:21
    And then that will remove the patch that I put on there so that I
  • 6:25
    have sort of a clean state again.
  • 6:27
    And if I do a git status, you'll see that there are no files that are
  • 6:30
    modified, so I've sort of reset my local site,
  • 6:33
    which is how I want things to be, unless I'm in the midst of working
  • 6:37
    on something in particular.
  • 6:40
    So that's the basics of testing a patch.
  • 6:44
    If you scroll down on this page, there's tips for other stuff
  • 6:48
    that may come up when you're working on a patch.
  • 6:50
    In particular, if you need to do things like run
  • 6:52
    update.php, because there might be database changes, in which case
  • 6:56
    you'll need to do that in order to see the changes.
  • 6:59
    But this is very, very simple, to test patches.
  • 7:03
    It's a few commands, you just need to have things set up,
  • 7:06
    and use git applied.
  • 7:08
    And you can use git reset, that pretty much takes care
  • 7:11
    of everything you need for testing.
  • 7:14
    Last thing I want to do is, people often ask me
  • 7:16
    how I get this little branch tag on my command line,
  • 7:20
    because it's really handy, instead of having
  • 7:21
    to do git branch all the time, to see which branch I'm on.
  • 7:25
    I have it actually print out.
  • 7:27
    So I'm going to go and show you how I'm doing this in my bash profile.
  • 7:32
    So in my home directory-- let me just open up my bash profile.
  • 7:39
    Here we go.
  • 7:39
    And then this is the section in this file.
  • 7:44
    I just added this in so that, on my command line prompt,
  • 7:47
    it's actually checking the branch, and then
  • 7:49
    printing that out onto my command line prompt for me
  • 7:52
    every time whenever I'm in a git repo.
  • 7:55
    It's handy, and I just thought I would show, because a lot of people
  • 7:57
    do ask about that.
  • 7:58
    And it is super useful.
  • 8:01
    It saved my life more than once for sure.
  • 8:04
    So that is testing a patch.
  • 8:06
    And I hope you can see how easy it really is, and it's
  • 8:10
    a huge, huge help to people who are working
  • 8:12
    on issues to have someone just test and make
  • 8:15
    sure, a little sanity check.
  • 8:16
    Is it working?
  • 8:18
    So I hope you go ahead and find yourself an issue,
  • 8:21
    and start testing.
Loading ...

Test Patches

Loading...

In this video we will walk through the process of testing existing patches in the Drupal.org issue queue. We will read an issue, download and apply the patch with Git, and then test it to see if it works. This video follows the instructions on the Test patches lesson on learndrupal.org.

The lines that I have in my .bash_profile (shown at the end of this video) to add the Git branch to my command line prompt is:

function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
export PS1="\h:\W \u\$(parse_git_branch)\$ "

I'm using a Mac, so your mileage may vary on other systems.

Additional resources: