تماشای این درس نیاز به اشتراک حرفه‌ای دارد.

Introducing SEO test plugin0:00

In the last video, we have included some tests regarding meta tags and the social tags. And as I have already told you, this looks a little bit messy and it's a little bit difficult. So if some of those tags here are changing, then you have to change all of them here. So it's a little bit messy. And I told you that there is a nicer way we can write this by using a plugin. So let's check this out. This plugin is called Test-CEO by Drumpy92. Thank you for this package. And what it does, it helps you to test those meta tags. So we're going directly here to the past section, which I think is pretty nice.

And what it does, it helps you to test those meta tags. So we're going directly here to the test section, which I think is pretty nice. So we're creating a new CEO object from the content, from the response of a specific request. And then we can expect that the title is something, description, robots, and other things which we want to test, we can now do here directly. And we don't have to think about what are the meta tags, the HTML. We're just interested in the content of some of those specific tags here. And I think this is just amazing because this will be so much cleaner. All right, let's install this. And we're going to start again inside our pageHomeTest.

Installing and using plugin1:15

All right, let's install this. And we're going to start again inside our page_home_test. So as we've learned, first, we need to store the response here from our request. We're going to separate this a little bit. And I think we're going to keep this. OK. And now instead of doing this here, we're now creating a new CEO object. And by the way, this is now just acting. And the real assertion we are going to make here. So we're creating now a new CEO object.

And the real assertion we are going to make here. So we're creating now a new CEO object. And we're providing the content of the response. Like this. Yes. Now we're going to expect that when we get the data from the CEO object, we need to create a new CEO object. We now have access to the title. And we can say it should be our expected title. Like this. Clean this up a little bit.

Like this. Clean this up a little bit. Take another look. Yeah. And I think this should work. Let's run it. And it does. And now let's take a look at how much cleaner this is as before. And how much readable it is. We're talking here about CEO data.

Refactoring homepage SEO tests2:29

And how much readable it is. We're talking here about CEO data. And we want to make sure that the title is a specific title. So I think this is pretty amazing. And now we can also refactor this whole chunk here, which is, yeah, as I mentioned, super messy. Let's get rid of the whole test here. I have this already prepared. And let's take a look now again. So again, we're making a request to the homepage. We're getting the CEO data.

So again, we're making a request to the homepage. We're getting the CEO data. And now we're expecting, again, the description to be the OpenCraft type. So now we have some object here for the OpenCraft. And here we have now access to the type, the URL, the title, description, image. And we're just making sure that we see the right text. But we don't care about all the other HTML thing around it. And at the end, we have also something here for Twitter. Twitter card to be our large image. And now again, take a look at the difference.

Twitter card to be our large image. And now again, take a look at the difference. Take a look at the difference in your repository. This is a huge difference because this is so much more readable than before. And I really like this. So great work by this package. Let's also run this again. It's now failing because, yeah, I think I got this wrong here. I somehow changed this to pages because I think it reads better. And somewhere else we should also have this now.

I somehow changed this to pages because I think it reads better. And somewhere else we should also have this now. Oh, yeah, here we have it. Okay. Now it's working perfect. Let's run the whole test as well. PageHomeTest and all those tests are passing. Let's also copy this first one here for the title because, or maybe just this part here. Now let's also go to the PageCourseDetails test.

Updating course details tests4:13

or maybe just this part here. Now let's also go to the courseDetails page. And again, we're going to deal with this chunk here with the title. Let's bring in this class here. Let me check. I'm more interested in the courseDetails page. And I need to provide the course here. And the rest is the same. We're getting the content, we're getting the ceoData, and we expect the title to be our expected title.

We're getting the content, we're getting the CEO data, and we expect the title to be our expected title. And this will work. Yes, it does. And now for the page course details social text here. Again, we're going to get rid of the whole test because I don't want you to see me writing all of this because, yeah, it's pretty much the same as before. We are using the right URL here. I kind of think the rest should be fine now.

We are using the right URL here. I kind of think the rest should be fine now. Again, we are making sure that in the CEO data we see a specific description, open graph text, type URL, title description, image. And also for Twitter, we have our large summary image. Let's run this. Again, we are missing here an S. Again, this probably is because we haven't released the course. Let's do this together. And I think now finally it should work.

Verifying tests and wrap-up5:30

Let's do this together. And I think now finally it should work. And it does. This means we have now made sure that we have all those nice meta tags for our application. And we also have some really nice tests. And they are not only easy to read, but also easy to change, which I also always like. Yeah, if someone else is going to change one of these, you will easily find where you have to do this.

Yeah, if someone else is going to change one of these, you will easily find where you have to do this. And yeah, more tests are always good.

دوست دارید گاهی خبرهای Laracasts را ایمیل کنیم؟