I am new to PHP laravel framework.
My application is very basic:
User first log-in with login and password (html form)
The user can add items in a mysql table. This are numeric values. There are 2 controllers: One to see all rows and another to add/edit row
Another Controller computes statistics (sum, average, etc.) on the numeric values stored in the table.
What i want do to is to test this application.
I want to write a test that:
Creates an empty database
Creates a user
Log-in this user on my application
Creates entries in my table throw my application (not directly in mysql)
Check in the listing page if each entry has been created properly
And i want to check if the statistics are good (check good values displayed on the webpage.
I have read about Testing section on Laravel's website documentation.
Here are my questions:
I do not se how i can automated database initialization
I do not see how i can check if a span or div contains a specific value (i only can test http response code and if webpage contains a given string).
I have worked with phpunit.
Thanks a lot
Related
Recently downloaded XAMPP on Windows and I would like to request a tutorial on how to navigate the program. I'm not sure how to open myPHP and test SQL Queries or create databases. Any help would be appreciated.
Welcome to XAMPP,
By now you should have the program installed in the location of your choice from the Apache friends website. I understand that it is quite difficult to get started on a new project utilizing unfamiliar tools, by the end of this short tutorial you can start building all sorts of ideas!
1. To start, open the application from the desktop. On windows, the opening screen will display as shown below. Click on "Start" for the Apache and MySQL modules.
Homepage of XAMPP
The port value will be 80 for Apache in most cases, this varies dependent on module type and other applications with respect to their assigned port numbers.
These can be viewed by navigating to "Netstat" which displays socket properties. Configurations can be completed under "Config" in the top right of the application and under "Service and Port Settings". Common issues to modules not working correctly is due to port error or overlapping and changing values will prevent this.
2. The status of the modules is portrayed in the panel below. In your preferred internet browser, type "http://localhost". The dashboard of Apache with given instructions will show when entered. Navigate to "PHPMyAdmin" at the top right of the webpage.
PHPMyAdmin
The critical step for this dashboard to be functional is to have the MySQL module running. On the left of the screen, databases are displayed when created.
3. Next, type "Create database test;" in the SQL tab queries text box. The console is displayed at the bottom of the page representing errors and program messages. Click the "Go" button. The "test" database will join the list of databases on the left side of the window.
This verifies that MySQL and Apache servers are functional on the local computer. URL's define locations for pages that are requested and identify webserver addresses. Apache is an application that provides access to these requested locations to the user.
4. A simple webpage can be generated by the user through XAMPP. Create a .txt file with its contents only including "<h1>StackOverFlow</h1>" and under this type "<p>I am learning, this is a test</p>". Save this file in the htdocs folder inside the xampp installation location as "StackOverFlow.html". Go to your browser and insert "http://localhost/StackOverFlow.html".
The process listed allows the browser URL to request the existing web server to obtain the page's contents "http://localhost/StackOverFlow.html"
5. Next, go back to step 3 where queries will be used to construct tables for relationships of entities and test values.
The test database was created previously and still exists. Keep the query tab open and edit the initial script to be "create database if not exists test;". Add the statement "drop database if exists test;". These steps permit the program to refresh the database and scripted queries each time the user clicks "Go" resulting in the removal of overlapping data.
Two tables will be created and their relationship can be expressed shortly. In the next step, a simple Company and Product association is used. Basic terms to know to write SQL queries:
SELECT -> extracts data from a database
UPDATE -> updates data in a database
DELETE -> deletes data from a database
INSERT INTO -> inserts new data into a database
CREATE DATABASE -> creates a new database
CREATE TABLE -> creates a new table
DROP TABLE -> deletes a table
VarChar -> Varying variable character of desired length
Char -> character of set length
Not Null -> term cannot be null
Date -> date term reference
Integer -> term must be an integer
Key -> uniquely identifies row(s) in a table
SQL Syntax
6. Insert "use test;" under the creation of the database query. Then structure the code in an organized fashion for easy reading for the user.
Add "create table Company(" and under insert "companyName varchar(40) not null primary key,", then "street varchar(40),". Also, "city varchar(40)," and "province char(2)," with "postalCode char(6));".
Add "create table Product(" and under insert "producedBy varchar(40) not null,", then "dateMade date not null,". Also, "productName varchar(40) not null);".
The Company and Product tables are now created with specific dimensions, ordering, and terms.
7. There are many types of relations within SQL that allow individuals to retrieve specific data, store, and construct relationships between many tables with set parameters through additional queries. This example is simple where producedBy references the companyName containing relevant data.
Position the following below both the table queries:
Test values for Company table
Test values for Product table
Select "Go" and this will create tables that can be viewed by clicking the database "test" on the left side.
Here, the statement INSERT INTO is used to input the data below into the table with the parameters created. Appropriate ordering of data from first to last must match with the corresponding table. Invalid inputs will result in the console returning an error. Selecting specific data from a larger database with numerous tables can be accessed by "SELECT * FROM TABLENAME", creating temporary relations and returning desired data. This concept can be further discussed in another tutorial. The interface is extremely useful and can be implemented within html websites to store, calculate, or retrieve data/user processes.
XAMPP is an exceptional tool to create and integrate into different areas of development, I would recommend taking a look at "https://www.w3schools.com/" to further learn SQL, HTML, and other skills to extend your range of capabilities.
Thank you for going through this tutorial! If you have any questions feel free to leave a comment.
I have an APEX form I'm developing for "user settings". I have a table with a sequence as a primary key and the users ID in another column...in addition to a few columns where each users saved settings are stored (things like "N" for do not receive notices).
I haven't used Oracle APEX in a while so excuse this likely newbie question...The insert works fine, but I'm having trouble with making the form only show the current users values. In my Form Region the source is set to my Table, and I have a WHERE clause like this:
USER_ID = 813309
But that's not working (813309 is my id and I'm just hard-coding it for now). The form always comes up with a "New" record.
For a form to load a specific record you can set the primary key page item to the value you need. You can do so in the url using the link builder from another page or you can set a computation on the item. That is what I would try in your case: add a computation to your item P_USER_ID of type "Static Value" with value 813309. Make sure the computation happens before the "Fetch Row" - the value obviously needs to be set before the process runs.
In such cases, I prefer creating a Report + Form combination (using the Wizard, of course): it creates an interactive report (so that you can review data in a table), and a form which is used to add new records or update/delete existing ones.
Doing so, when you pick a user in interactive report and click the icon at the beginning of a row, Apex redirects you to the form page, passing primary key column value to the form which then fetches appropriate data from the table.
Not that it won't work the way you're trying to do it, it's just simpler if you let Apex do everything for you.
So: did you create an automatic row fetch pre-rendering process? If not, do so because - without it - Apex doesn't know what to fetch. Also, if you hardcoded user_id, it won't do much good. Consider storing username into the table so that you could reference it via :APP_USER Apex variable.
Scenario:
In an integration in Magento 2 with Full Caching.
We have two types of customers Type 1 and Type 2. Both these types of customers are saved under same Customer Group we are distinguishing the customers based on a customer type attribute.
Customer of type 1 can belong to different departments (1 to many). When he first visits the site after login, he is redirected to select his department.
This value is saved in customer session, on run time customer can change his department that value is updated in the existing customer session.
When we access a new page we get the updated session, but if we access a page that was accessed earlier, we get the old data from session.
Options tried:
We tried to load the data from customer session factory instead of customer session, but still we are facing the issue. Our understanding is that data which is saved in customer object is loaded as new, but since our data is saved under customer session it is not returning the latest data.
For some section of the page we have used sections to load the data, but in that scenario also, if a page is accessed earlier the correct data is not loaded in first refresh, in second refresh the data is loaded properly.
We also tried to update the session data from AJAX, but that was also not much useful since that data is not getting loaded on the pages.
We also tried to use context variables, but when we log the data while saving the context variable the correct data is logged but when we try to fetch the context data, no data was returned. Also even if different context variable is set for each department, the page seems to be rendered from cache.
We can’t use Cookie since this is sensitive data, this will be the last option.
In Magento 1 we had an option to generate new Cache key by extending app\code\local\Enterprise\PageCache\Model\Processor.php,
Example
if
(isset($_COOKIE[Enterprise_PageCache_Model_Cookie::IS_USER_ALLOWED_SAVE_COOKIE]))
{ $uri .= '_' .
$_COOKIE[Enterprise_PageCache_Model_Cookie::IS_USER_ALLOWED_SAVE_COOKIE];
}
Is there any similar option available in Magento 2. If yes, please share some reference links to integrate the same.
I am currently providing support to an existing Oracle Apex 4.2.5 application. One of the pages (Page 1003) contains a process that submits information from the Page 1003 page items (e.g. P1003_ITEM1) to our database tables. The contents of these page items are associated with a primary key (Assessment ID) in the database table to which the page items are submitted. Of a few dozen or so page item variables, the primary key is one of only three variables that are passed in through the URL. The URL is as follows:
https://[DOMAIN]/f?p=[APPLICATION ID]:[PAGE NUMBER]:[SESSION ID]:SELECT:NO:1003:P1003_ENTITY_ID,P1003_ASSESSMENT_ID,P1003_PARENT_ID:353767,700177,5716
We have encountered an issue that occurs when our users load Page 1003 in multiple tabs in their browser for different Assessment#'s. Every time a new Page 1003 is loaded in a new tab, the session variables from the previous tab are overwritten. Regardless of which tab the user submits first, the only variables submitted to the database are the ones from the last tab that was loaded by the user. I've seen a few examples online of how to handle similar issues with other programming languages, but I'd like to know if there is an APEX specific solution that I might have overlooked that can handle this situation.
We'd prefer to pass as few variables as possible in to the page through the URL. In fact, some variable are calculated after the page loads and cannot be passed in through the URL.
Im using custom profile plugin found at http://library.logicsistemi.it/images/joomla/plg_user_testprofile.zip
I have created several fields, both, optional and required and they all work. But there is a tiny problem.
When I enter some value in that custom fields and submit the form it can happen that some fields dont pass validation (which is good). However values entered are cleared and I must fill all the fields from the beggining.
Demo: http://goo.gl/eH1G2
Enter some (not all) data under the 'legend' named User Registration
Enter some (not all) data under the 'legend' named Company
Informations
Press Register button
Error message will pop in. -
Data entered in the User Registration will be saved
Data entered in the Company Informations (which are custom fields)
will not be saved.
If all required fields are entered, form will submit data to database
(which is ok).
I want that data in the Company Informations are saved, so users dont have to type in all over again.
The problem in your demo is on the template you are using.
For some reason it gives Javascript errors. These errors blocks the Javascript client side validation and your form is submitted with invalid data.
If you want only server side validation you can modify the onContentPrepareData function in your plugin by loading posted information from the user state. To do this you have to permeform a different action when user_id is not set under "Merge the profile data." comment.
I think next week I will write a new tutorial on http://library.logicsistemi.it to explain this. For now try to fix your Javascript code.
Regards