How to write an appropriate test for backpack admin crud functionality? - laravel

I've implemented a laravel project which involves backpack admin, now I want to know is there any appropriate way to test its CRUD functionality (like the store, delete, etc actions)?
It doesn't matter what kind of test is needed (functional or unit test), I just want to test its functionality.

The easiest way I found was to create browser tests using Laravel Dusk - https://laravel.com/docs/8.x/dusk

Related

Laravel CRUD Application Dusk vs PHPUnit

I am currently working on a Laravel CRUD application and I was wondering why PHPUnit does not support crawling the browser (anymore, as I read). I already covered the basement of my project via PHPUnit, but I do also want to test links, a tags, button clicks etc. So I do already have a strong basement of unit tests.
Now I read about Dusk providing a crawler for DOM tests. Shall I use both together (is it even possible?) or should I migrate to Dusk? I'm not sure whether Dusk provides the same functionality as PHPUnit does and as stated, I do already have a strong phpunit testing base.
From now on I'm kinda stuck, because of 50:50 testcases, as I do also need to test whether the DOM does provide the correct information.
Appreciate any help or expert advice.
Thank you in advance!
Dusk is not a crawler but a browser driver, it can control a (headless) browser.
Specifically designed on top of PHPunit to do E2E (end to end) testing.
So convert to Dusk what is browser tests (html/javascript), but everything else keep as unit tests.
API tests for example you don't need dusk at all.

Laravel testing without specific midleware

I've write a middleware to build a menu, but when I run my tests It tooks about an hour (It's a huge menu)
I want to know if there's a way to disable this specific middleware for testing but not using:
use withoutMiddleware;
because this also disable the auth middeware and my tests depends on it.
Thank you.

Is it possible to turn off JavaScript for some tests using Codeception?

We have client-side validation and server-side validation as a back up in this Laravel application, and we want to test both, but I can't figure out if that's possible. Is it possible to turn off JavaScript for a single run of the tests, then run them again with it on using Codeception?
Test with PhpBrowser or Laravel5 module.
They can't execute Javascript, so only server side validation is possible.
You will have to create a separate test suite (or use functional if you aren't using it yet) for these tests, because you can have only one of WebDriver, PhpBrowser and Laravel5 modules enabled at a time.

SPA using DurandalJS and laravel

im trying to create a Single Page Website with DurandalJS in the frontend and Laravel as the Backend. Do you think this is a good Idea?
If yes how would I do the following:
What would your recommendation for the basic interaction between both frameworks be?
Would you rather have all the computation done in JS instead of Laravel sending calculated and styled returns?
How Do I setup Laravels controller in order to only get dynamic Data for, say a Div, instead of a whole page?
How can I adjust the browser URLs?
I hope I was specific enough, thank You in advance.
Laravel does not actually care about what framework you use to build the Frontend. Laravel is just a framework that helps you build your application with. It gives you great advantage with respect to the time spent and effort.
You can use any frontend framework that you want to build your app with. I have actually not used Durandal, but from the first look of it here is my opinion.
Durandal is built on top of jQuery, knockoutJS and requireJS. It also has a MV* architecture in place with support for eventing as well. So you could basically define routes on Laravel and initiate the communication between both the frameworks through events and ajax. Again this completely depends on the functionality that you are building.
In the overall flow of your app, consider Laravel as a Model that just gives data from a source to your app and Durandal as your views and controllers. This way, it will keep your data flow cleaner and easier to build. Computation of your functionality depends on how important and secretive the app is. If there are functionalities/implementations that you need to be secretive about, you can keep it on Laravel and just send computed data to Durandal. If its a web app that you are building, then keeping all implementation on the JS is just a right click away from knowing what and how you have built it. One can just see how the implementation is done just looking at the Javascript source of the web app. If you are building Mobile Device App, then the case is different.
Take a look at Restful Controllers. Will give you an idea on how to setup controllers to return only data. But if you need to return the div itself, then you can make use of the Basic Controllers of Laravel to perform them.
You can setup cleaner routes for the browser URL's. Take a look at Laravel Routing

How to use Behat with CodeIgniter?

We are toying with Behat to start writing specifications for our PHP applications. All step definition implementation examples are for plain PHP classes, but we are using CodeIgniter as a our prefered framework.
We rule out writing features and scenarios that are UX/UI oriented (that would abstract away the underlying framework) until later in the development stage, and would like instead to test the application layer by accessing the CodeIgniter models.
How do you get Behat to use these models? i.e. how do you integrate Behat with CI?
Download here Behat CI Test
Simple test with Behat and CodeIgniter. The CodeIgniter controller just displays a login page and returns a data array that use to make assertions. There are various debug statements printed with error_log, which Behat displays on stdout, to follow the flow of execution.

Resources