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

Testing course exclusion0:00

Okay, so this means we are ready to move on to the next test, which says it does not list other courses. So what we need here is again another User, and we again need a Course. So I'm just creating just a Course without any connection to the User. Now let's copy this here, we're acting as a specific User. We are locked in, we're making a request to the dashboard, and we want to see something. Or actually, we don't want to see something. Assert that we don't see the title of our Course. And as we've learned, we always need to make sure that we check that everything is okay before we make any other assertions.

Testing purchase ordering0:45

And as we've learned, we always need to make sure that we check that everything is okay before we make any other assertions. Okay, let's run this, and this is true. Yeah, so we don't see any other courses, and this is now tested as well. Okay, next test. It shows latest purchase course first. Okay, so again, we are having a User. Let's copy this, and then we have two courses. One is the first purchase course, and the second will be the last purchase course. And we want to see the latest purchase course first.

One is the first purchase course, and the second will be the last purchase course. And we want to see the latest purchase course first. Now we also need to add those courses to our User. And another way to do this is through the courses relationship. And here we can now attach a given Course. And let's also do this for the second one. Okay, now we have two courses attached to our User, but how do we define that this one is the first one and this is the second one? And we can do this by adding here some data for the pivot table. So this means in the intermediate table, we want to make sure that we set the created_at

And we can do this by adding here some data for the pivot table. So this means in the intermediate table, we want to make sure that we set the created_at field. So let us set the first one to yesterday, and the second one to now. So this should be enough that we have now this as our latest PurchaseCourse, and this is the first one. Then here again, we are acting as a specific User. Then we're making a GET request to our dashboard again. We already know that we need to assert that everything is okay first. And then we want to make an assertion that we see something in a specific order, which

We already know that we need to assert that everything is okay first. And then we want to make an assertion that we see something in a specific order, which we already have done on our homepage. So what do we want to see first? First we want to see the lastPurchaseCourseTitle, and then the firstPurchaseCourseTitle, like this. And again, we are acting and asserting here at the same time. And if we run this, we see an error that the output contains some dummyTitle here in a specific order. So probably just the order is what is not correct yet.

Ordering by pivot timestamp2:58

specific order. So probably just the order is what is not correct yet. So let's think about how we can fix this. So I guess that by default, we are getting the order back, which the courses are inside its own table. So what we need to do is we need to adapt our relationship inside our User model here. So I want to make sure that we're going to get back our courses here, order by, I think it should be descending again. Now we want to do this for our pivot table. And we can do this by providing pivot_, and then the name of the field, created_at.

Now we want to do this for our pivot table. And we can do this by providing pivot_, and then the name of the field, created_at. Because the created_at of our purchase_courses table is what we are interested in here. And fingers crossed, let's see, is this already working? And it is. So now we have successfully changed the order of our courses and how they are shown on our dashboard page. And we're going to see the latest purchase_course first. All right, what about next? It includes the link to product videos.

Testing videos link3:59

All right, what about next? It includes the link to product videos. All right, again, we're going to need a new User, factory create. And we also need a Course. Let's do this together again. User has a Course factory. And then here, I want to make sure that we're acting as a User again, the User which we have just created. Okay, and how do we test this now? Again, we're making a get request to dashboard.

Okay, and how do we test this now? Again, we're making a GET request to /dashboard. We want to make sure that everything's okay, that we get a 200 response back. And then we want to see some text. So maybe you watch videos, which should be a link then to the videos of this course. But we also want to make sure that we see a URL for this. Okay, and what will the URL look like? So probably will be a route for, let's say, another page. And let's call this courseVideos. So we don't have this yet, but we're just thinking about what this could look like.

And let's call this course videos. So we don't have this yet, but we're just thinking about what this could look like. And I think we also need to provide here a course. Yes, we do. So which course do we need? Let's just grab the first one. Because we only have one course in the database. So if we see a correct URL for the first course, I will be happy. Okay, let's run this. We don't see watch videos inside our view file.

Okay, let's run this. We don't see watch videos inside our view file. So this means for every course, which we're showing here, we want to also provide a link to a page where we can see the videos of this course. And then here, let's also provide the string now, watch videos, which we are also testing against. And we see a different error now. Now the route page courses video is not defined yet. And yeah, that's true. So let's create this new route now.

Adding videos route controller6:05

And yeah, that's true. So let's create this new route now. So we're going to add here a new route. How do we want the URL to be like, let's start with videos. And then we want the slug of our course. And I think this should be enough to get to the main page of the videos. And it should be connected to a page VideosController. And then the route name should be page and courseVideos. I think that's what we have used. Let's run the test again, invalid route action, fine.

I think that's what we have used. Let's run the test again, invalid route action, fine. Let's create a controller, PageVideosController, let's run this again. Still the same error because we haven't imported the class yet. Let's do this. And now it is green. So we don't even need to provide anything inside our controller, in the PageVideosController here, because we are only interested in that the URL exists and that we can create it through the route helper. So I'm talking about this route, which we are using here to define a link for a course.

Running full test suite7:09

it through the route helper. So I'm talking about this route, which we are using here to define a link for a course where you can watch all the videos about this course. So back in our dashboard.test. So this was not the last test, which we have made past so that we can make sure that we include a link to product videos. Okay, now it's a good time to run all the tests here of this file. This looks good. And maybe all of the tests of this application. And you can see that we have some warning and risky tasks here in between.

And maybe all of the tests of this application. And you can see that we have some warning and risky tasks here in between. And that's because we have now some tests in here from chat stream itself. Let me show you what we have done on the test features here. So all these tests are now new tests that come with Laravel chat stream. And I think we're going to deal with them in the next video, but it's good to know that they are here. And since we have used the --past flag while installing Laravel chat stream, all of these tests here are using past as well. Okay, this looks good.

tests here are using past as well. Okay, this looks good. We can check the next to do see purchase courses. But again, we will need to refactor some of the code, which we just wrote. And this is what we're going to do in the next video.

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