---
title: 'Understand how PHPUnit test works with this amazing example Drupal 10, Drupal 9 | D4Drupal'
source: 'https://youtube.com/watch?v=4nyPJhmGUYY'
video_id: '4nyPJhmGUYY'
date: 2026-06-14
duration_sec: 827
---

# Understand how PHPUnit test works with this amazing example Drupal 10, Drupal 9 | D4Drupal

> Source: [Understand how PHPUnit test works with this amazing example Drupal 10, Drupal 9 | D4Drupal](https://youtube.com/watch?v=4nyPJhmGUYY)

## Summary

This video explains how PHPUnit test reports are generated in Drupal, using the Quick Node Clone module as an example. The presenter walks through the test code and the corresponding HTML test report to demonstrate how functional tests work.

### Key Points

- **Introduction to PHPUnit testing in Drupal** [00:00] — The video explains how PHPUnit test reports are generated and how tests run, using the Quick Node Clone module.
- **Quick Node Clone module overview** [00:38] — The module allows cloning a node with a prepended title and excluding specific fields like the body field.
- **Test file structure** [02:51] — The test is a functional test using the standard profile, depending on the Quick Node Clone module. Tests are placed under module/tests/src/Functional.
- **Setup function** [03:38] — The setup function creates an admin user with necessary permissions and edits the configuration to exclude the body field for basic page content type.
- **Test function execution** [05:31] — The test function logs in as admin, changes configuration (title prepend text to 'cloned from', enables basic page bundle, selects body field), and submits the form.
- **Creating a node for testing** [07:07] — A node is created with random title and body values. The test verifies the node page contains both title and body.
- **Cloning the node** [08:00] — The test clicks the Clone tab, submits the clone form without changes, and verifies the new node has 'cloned from' prepended to the title and no body field.
- **HTML test report walkthrough** [09:55] — The presenter shows the HTML report step by step, confirming login, configuration changes, node creation, and clone verification.

### Conclusion

The PHPUnit functional test for Quick Node Clone successfully verifies that the module clones a node with a prepended title and excludes the body field as configured.

## Transcript

hello everyone welcome to D for Drupal
Channel today we are going to understand
how the PHP unit test reports are
generated and how the PHP unit test is
running all those we are going to uh see
now and that's why I'm going to explain
how the test report they have written in
the code so I will be explaining all so
in previous video you have seen how to
set up and run the test report
and in that video I have explained how
the test reporter is working with the
contrary model called quick node clone
so I'm going to use the same module now
so that you can understand it better
so uh
before that you have to understand how
the module works so this module
basically provides a cloning option of a
node so by using this module you can
clone your complete node so you no need
to provide value again for new node if
you are going to duplicate the same node
and if you are going to alter something
very few so in that case you can go with
this module
so here you can see I have created some
notes here so when you click on the
operation you will be able to see a
option called clone
so then you click on it
so it will take you to the Clone page
where you can see the complete node is
cloned so let me explain it
so this is the node so let me give some
body value
so that I can explain it well
so now I created a node
and I have a body value as body value
and when I click on clone
so you can see here the title is
prepared with the text of clone of and
the body value is empty so all these are
happening because of the configuration
what we are having from the crypto clone
module so this is the configuration what
we have so I am going to explain only
the node part not the paragraph part so
here uh text to prepare to the title so
that is clone of you can see the text is
prepended and then next uh what they are
doing they are excluding some fields
from cloning so in the basic con basic
page content that they are excluding the
body field value so the body filled
value is not cloned here and you can
save the
node
now the node is saved you can see now
the complete node is saved and you don't
have body field in the new as as we
configured here so uh this is what we
are going to understand now
in test report so this is the file which
I ran in the previous video
so first how uh here they have written
test in the functional so uh there are
four types of testing I will create a
separate video on proper example in
future so now in this functional testing
so here uh what they are doing they are
using the standard profile and this test
is depend on a module called quick node
clone so all those should be enabled so
that this will work properly and they
are creating one admin user so whenever
you are creating any test that will be
under the module test SRC functional
folder
and then here the first function called
setup will get called for the first time
so in this function you can have all the
required statements so which means so
here I am going to use the testing with
the admin user so I am creating a user
with all this
access conditions so the user will be
created with this permission once the
user is created next you can see here
they are editing the configuration so
config Supply will be helping us to edit
the configuration whatever we are having
in the Drupal so this is the
configuration quick clone settings this
is a configuration for the
so you can go to your development
configuration export
so simple quick note one so you can see
quick note rule settings this is the yml
file which hold the complete
configuration whatever you are saving
here so we are editing that oml file and
we are keeping excluding node page so
which means we are excluding the basic
page
content type body fill so the same
configuration whatever I'm having here
so for the node for the basic page they
are excluding the body field and they
are just saving the configuration so
here all these values are
as like in the yml effect so when you
see the yml file so exclude
node
and then page so exclude dot note Dot
Page and the value is body
okay so they are just saving the
configuration once that is done so the
next function what we'll get call is
that whatever function you are starting
with the test
the word so the function will be started
executing so in the next function what
they are doing they are just logging in
by using the function called Drupal
login and they are logging in with the
user admin user which we created on the
setup function okay this user will be
logged in
once the user is logged in they are just
giving the value for all the
configurations form so here
text to print title so when I default
the value was
flown off they are just changing the two
cloned from and then uh in the bundle
they are enabling basic page so Pages
page they are enabling which means here
so in the bundle they are enabling the
basic page and then in the page they are
enabling only for this particular body
field
so in the field list they are enabling
only the body field so once this is
created they are once they just uh
assign the value in Array they are just
going to the path of this bracket so
admin configure flow and they are using
all this value edit value and they are
just submitting the form
so once this is done the configuration
form will be submitted here
and then next here we excluding the
basic page right so now we have to
create a node so that we can test
whether the field excluding
functionality is working or not
so they are generating randomly uh 10
words for uh title and sentence 10
length
for body value and then they are just
recreating one new array so as like here
for the body field
and then title field and they are just
getting the node at page of node add
page and they are passing the tradit
value and they are just saving so which
means here they completely saved the
node the new node which they created so
once they say
in the asset session in the response
when you see the node slash node ID page
it can be node slash one or two or three
whatever
the response should contain title value
and the body value
which you passed and which you've saved
by sure that will be there
once that is done
they are just clicking on the Clone tab
what we have in the node view page
so they are just loading the node so
whatever by using this node title
by using the value of the node title
they are loading the same node and they
are just going to flown slash node ID
slash quick clone
so this is the page
and you click on clone
clone slash node ID slash Quick Loan so
clone slash node ID slash quick clone
and they are just submitting the form
without passing any value so the value
is getting submitted without passing any
new value so by default when you clone
it what will happen the title value will
be pre-populated with the text of flown
from and then body value will not be
there because we excluded that body body
field value here
right so that's what they are doing here
here
when they click on clone slash no ready
slash node they are just saying they are
not altering anything so when you see
the response of the node which we create
a newly the response should contain
cloned from
because we saved the configuration
text has cloned from so that will be
cloned from the title value of the or
default node and then the response the
body value should not be there in the
node slash no ready page of the Clone
download because we excluded that body
field in the configuration
okay so this is how this should work
that so they have written all the uh
test report here and we have run it so
uh here we have all the test report as a
HTML file okay so now when you go here
so I already opened all the HTML file
line by line here so that I can explain
you explain you to you efficiently so
when you see here here first they are
clicking on login page because they are
doing admin login first right
scroll up
and here you can see admin user is
logged in first so they are going to
login page you can see the file is
coming from site simple test browse row
so the login page is getting hit and
they are just posting the value for the
login page once that is done so they are
getting the request once that is done
the user slash one is logged in
successfully now the login process is
Success so which means this single line
is completed next what they are doing
they are going here and giving these
values and they are just sharing it that
will be the next
so when you scroll up they are hitting
get request they are hitting admin slash
config slash quick note clone
so here you can see this is these are
default value clone from all those so
they will be giving all this value here
and they will be posting the form again
so here again the form is posted once it
is posted when you scroll down
now it is guess get again so when you
have scroll down you can see the text is
cloned from the value what we have given
and then basically it's selected and the
body field is selected
and then click now clone setting has
been saved successfully
so once until this done now we are going
to create a Content node that's what
here right so this is the node add page
get request
so this is the fields
in the next they will be posting it the
value
will be posted is the random text to
whatever generated here okay so that
will be posted now it will be node slash
node one or something
it will be node one you have node one so
now the node is created we are in node
one page
here you can see the randomness
generated text title and the body fields
are there
so this response also contain title and
the body
and the next one they are going to click
on clone slash node ID slash Quick Loan
so
next they are going to click on clone
slash node ID slash quick clone so in
this page
here you can see the prep and text is
added as per our configuration and also
the body value is empty because we
disabled it from cloning
and this is done now and next now the
value is posted because we are not going
to alter anything so they are just
saving it so here they are just saving
it
and and the final one
so now the node 2 is created in the node
to
type in title we will have cloned from
so clone to from with the title value
responsible content is it is has and
then response not containing body values
so here you can see the body value is
not there only the title we have as per
our
test what we have written and this is
how the PHP unit test will work with the
explanation and the example whatever we
are having here and if you have any
queries please post it in the chat
and that's it about today's video if you
like the video please share like And
subscribe to my channel thank you bye
