 Hello, everyone. Thank you for joining the session. So today, I, Radhima Braul and my colleague, Sujit Kumar Verma, will be presenting the session and we'll be discussing about understanding automated tests in Drupal. We both worked as Drupal developers in Strogen Technologies in India. So let's see what we are going to cover today. We'll be talking about what automated tests are, what are the different kind of test categories that we have in Drupal, and then we'll see how to set up the testing framework on our local machine so that we can run our tests. And then we will see each kind of test type in detail. We'll see that those test types with examples. So beginning with what automated tests are. So automated tests, they are basically a process of writing code to test your software. So whenever we test our software, we do certain kind of steps or certain things that we manually perform. So automated tests, what we do, we write those steps in the form of a code so that whenever our application starts or our software starts running, those tests automatically runs and if there are any errors, they throw them there as well. So it really improves the stability and performance of the site of your application and also it reduces the manual QA time that we spend on doing the performance, doing the QA of our sites after we deploy our code or after we build our applications. So we'll see that these tests are really important to build an application and we'll see how to write these tests. So coming to the test categories. So prior to Drupal 8, there was a testing framework called Simple Test Framework in Drupal 7. So there were no categories in the Simple Test Framework. There was just one kind of test and it didn't matter that what kind of test you have to write, whether you are testing a small function or a class or you are testing the whole end-to-end functionality. You'll have to write the same code, same kind of test. So you'll have to install the Drupal. You have to install all the modules for even testing a small function also. So again, learning that test was easy because you just have to write one kind of test. But again, there was one downside to it that was the performance. So performance was not good because each time a test runs, it did all those things, Drupal install, modules install. So it took a lot of time. Hence the performance wasn't good. Therefore PHP on a testing framework was introduced in Drupal 8. So there are these four kinds of tests that PHP on a testing framework has. So we'll see about each of them in detail in the later slides. So now firstly, we'll look at how to set up our test, how to set up our machine so that we can run our tests on our local machines. So whenever we install Drupal, we'll see that inside the core directory, there is a file named PHP on a dot XML dot DIST. So what you'll have to do, you copy that file into PHP on a dot XML file. And then you edit this file and you have to input some values. So for example, there is simple test base URL. So you have to enter the site URL into this value. Then there is simple test DB. So you have to enter the DB credentials and the DB name here. Then there is one more value that you have to enter, which is browser test output directory. So browser this directory basically saves all the HTML output that it tests generate. So whenever we run functional or functional JavaScript test, there are a certain set of HTML outputs that are generated. So all those HTML outputs are saved within this browser output directory. So once you have made this changes, you can save this file. And after that make this browser output directory inside the site simple test folder. So and give these give this directory writable permissions. After you have done this, you'll see that your setup is done. And now you can test this by running a test. So just navigate to your core directory and run this command vendor been PHP unit and path of your test file. So for example, I have to test this to test dot PHP. So what I'll have I have to run this command that is shown here. So that is how we set up the test on our local machines. Moving on to different kind of tests. So we'll begin with unit tests. So unit test basically they are intended to test the smallest part of your code. So basically the smallest part can be your functions, your methods, your classes, all those things can be tested by unit test. So but then there is one thing that you'll have to keep in mind that these are this, these kind of tests that part of your code that can run without Drupal. So wherever there is no Drupal interaction required. So we do not need any Drupal hooks or any Drupal module. So there we can use unit test. Also the folder structure for unit test is somewhat like this inside your module directory. There is a test directory, then SRC unit and inside the unit directory you have your test file. So we'll see one example. So because it's in the PHP unit framework is in PHP. So it's in the PHP format. So you have to include the namespace, then the use statements that are required. So I've initiated one class. So you can see there is a there is one annotation given here. So PHP unit testing framework. It provides us with certain annotations that we can use in our test. So the most common one that you'll see around is at the red group annotation. So what this does that it categorizes your certain kind of test into one group. So it helps in running a certain kind of test together. So for example, I have to run a certain group of test together. So I can run that by using the command and I can use this group name in my command that I run on the terminal. So it makes that easy. So there are several other annotations that are provided so we can use them as per our requirement. So here you can see that I've extended this unit test class by from unit test class unit test case class. So in the previous slide we saw that we included this unit test, our unit test file inside the unit directory, but just including your test file inside the unit directory doesn't like Drupal won't identify that it's a unit test just by including that inside the unit directory. So how how the system identifies it. So it identifies by certain classes that Drupal gives us. So for each kind of test there is one base class that Drupal provides us with. So for example, for unit test there is a unit test class unit test case class. So all the tests that will be extended from this class will be recognized as unit tests. So for for other methods also you will see that there is an there is one certain class that is derived from a certain class. So the next we see that there is a setup method that we have. So before call before a test method gets run each time this setup method is invoked. So setup method basically it involves all our basic fun basic things that that we need for a test. So for example, you can say that logging in creating an admin user and log in into a into our system with an admin user. Also, so you can see here that I have created an object a new object inside the setup method. So that was about the setup method. Now we can see that there is a test method that we have. So there is a naming convention that we use for the test method. Your test method has to start with the keyword test. So if there is not a if you are just right this set get length without the keyword test. So it will not get executed. Hence this is important. So now we'll see what we are doing here. I'm setting the length of this object to nine and then I'm checking this by this method assert equal. So I have given the static value nine here and I'm getting the length of this object. And this should be equal to nine as we have set this as nine. So this will be equal and hence the test will pass. So again, you've seen that there are some assert methods here. So again PHP unit provides us with certain assert methods or you can say Drupal code provides us with certain assert methods. So we can use those assert methods in a test as per our requirement. So this is how we write unit tests moving forward to kernel tests. So kernel tests some lie somewhere between your unit test and functional tests. So for functional tests, you will need a proper end to end task that need to be performed. But again, unit test is the simple. You are testing your simple functions or methods, but kernel test that kernel test also tests your methods or your functionality also. But it, it tests that part of your code that need Drupal interaction. So if anywhere you're writing a unit test and you you require the need of a Drupal interaction or Drupal module, you can say. So you there you'll have to go for kernel test. So also one more thing that kernel test do not provide us with a browser interaction. So if anywhere in the test, you'll need a browser interaction. You need a UI. So there you cannot write kernel tests. So this is the folder structure for kernel tests similar to the unit test. So inside your module directory test SRC, then the kernel directory and then your test file. So we'll see one example for kernel test base also. So again, kernel test, all the kernel tests are extended from this kernel test base class. So what we're doing here, I'm, I need the language module here. So I have enabled this module here. So again, a Drupal module is involved and hence unit test cannot be used here. So now we are writing a test method. So what we are testing here, we're testing these get name and set name methods of this configurable language class in this method. So what I'm doing here, I've generated a random name, random name. And then I've generated a langcode and I've created a new object and I've assigned this label, this name and language to the label and ID here. So now I'm checking by this assert equal method that my get name should be equal to the name I have set here. And also now you can see that I'm setting my name to test language and now I'm getting the name. So this should be equal to the test language and hence this method should pass. So this is how we write kernel test. So moving forward, I'll hand over to Sujit for the rest of the part. Thank you. Thank you, Ritma. Hello, everyone. So now we discuss about functional test. What is functional test in the functional test you are working with a complete and working version of the software. And you writing when you write a functional test, we need to follow four important set of tasks, like login as a user with a given set of permissions, never get to the given URL, given page, perform a specific action on the page, check if the page shows expected result or not. So these are the four simple, simple tasks for running any functional test. So as we can say, functional tests are called full stack or integration test these tests put all the piece of software together with and execute them. So to write a functional test, you can take the perspective of end user attempt to perform a scripted set of tasks. So we can say this is all about the functional test. Now, if we check on the left side, we have a directory structure like all other test. The directory structure also similar, but only one different is the directory name. Here we talk about the functional test. So now this is a functional directory. So the naming convention for test to file like a class name of a file and test dot PHP. So this is a very simple naming convention. We have an example related to functional tests in the next slide. Let's move functional test example. First, we understand about this example. It is related to two tip. It's drawn user attention to critical components of the interface. We can say that guide the user through a workflow. In this test case, block layout to test we have extend to test based class class and to test based class extent browser test based class. So we can say that browser test based class is necessary for functional test. As like other tests to we need to add a default variable and as per the requirement we can add modules also. And in the current example, we check there is an admin user also. So admin user is there because we need to log into the system and then perform the functional test. So in this example, we have a setup method. So in the setup method, we check we log in with some appropriate permissions and then place a block there. So now we talk about the method test method in the test method we go to the block structure page and check the tool tip available over there or not. So this is how we can check we can run the functional test and write the functional. So this is all about the functional test. Now move to the next one functional JavaScript test. So first we talk about the basic requirement like browser what browser we required for as prospect of functional JavaScript test we can use Chrome and Chromium. And other thing is Chromium Chrome driver required. So we can say for run the functional JavaScript at both the application are required. First we need to install and run both the application or our local system and then run the test. So the main difference from other tests is that the functional JavaScript test are executed in a real browser. JavaScript behavior are executed meaning the test will have the same experience and requirement that you have in a normal browser. So this is all about the functional JavaScript test. In the left side we have a direct structure like we already explained in the previous one. So the only difference is the name of the directory. So here we took functional JavaScript as a directory name as we see that. So we have attached an example. Let's move to the next slide. In this slide we are discussing about the example. So this example is basically related to the media module and contextual links available on the media page or not. So this example class media contextual link test extend media JavaScript test base class. So if we see in the media JavaScript test base class, so we check that there is a this class is also extend web driver test base class. So finally web driver test base class extend browser test base. So we can say that browser test base class is necessary for functional JavaScript test. Now come to the test method first create a media type and then create a media item and then create a user with the appropriate permissions. Finally login with this user and access the media page for accessing the media page we are using media slash media ID. So this is how we can access the media page in the test. In the next line contextual links are populated by JavaScript after the page is loaded wait until they are on the page click on the pencil so we make sure they are visible and then we assert their contents. And after this we check until contextual links container is there or not. And finally at the last check all the links available or not like added update metadata and lead. So this is the example ready to functional JavaScript test. Thank you. We have added link for our feedback form please share your valuable feedback. It will help us to improve our skills and knowledge. Thank you once again. Thank you. So I've got about a minute and a half left questions the first question that two people have asked is, will there be the slides about one line. Are you able to put this into your website. So are you able to, will you be putting the slides up on your company's website. Yeah, we can put the links also here. That'd be great. The only two questions that we've got so far. Yeah. And granted it's hard to read codes examples in the presentation. So if you've got to have a look at that for the fact. Are there any other questions I've got about 45 seconds left. Okay. That's I don't think we do. So just like thank you both for presenting and it's very important that people have testing in their sites and you probably seen a few other sessions today people have talked about that. So thanks again for presenting. Thank you. Thank you for that question. Okay. Thanks everyone.