Laravel 5: Testing – Cheatsheet: Laravel Dusk testing – cookies

Cheatsheet: Laravel Dusk testing – cookies

Get, or set testing cookies.

[one_third]
set encrypted cookie()
get encrypted cookie()
[/one_third][one_third]
set plainCookie()
get plainCookie()
[/one_third][one_third_last]
addCookie
deleteCookie
[/one_third_last]


A small cookie reminder.

Parameter Description
name Required. Specifies the name of the cookie
value Optional. Specifies the value of the cookie
expire Optional. Specifies when the cookie expires. The value: time()+86400*30, will set the cookie to expire in 30 days. If this parameter is omitted or set to 0, the cookie will expire at the end of the session (when the browser closes). Default is 0
path Optional. Specifies the server path of the cookie. If set to “/”, the cookie will be available within the entire domain. If set to “/php/”, the cookie will only be available within the php directory and all sub-directories of php. The default value is the current directory that the cookie is being set in
domain Optional. Specifies the domain name of the cookie. To make the cookie available on all subdomains of example.com, set domain to “example.com”. Setting it to www.example.com will make the cookie only available in the www subdomain
secure Optional. Specifies whether or not the cookie should only be transmitted over a secure HTTPS connection. TRUE indicates that the cookie will only be set if a secure connection exists. Default is FALSE
httpOnly Optional. If set to TRUE the cookie will be accessible only through the HTTP protocol (the cookie will not be accessible by scripting languages). This setting can help to reduce identity theft through XSS attacks. Default is FALSE
above table taken from: w3schools.com



This is same as setting encrypted cookies, you just change method name cookie(), to plainCookie().
Click here to see how it is done


This is same as getting encrypted cookies, you just change method name cookie(), to plainCookie().
Click here to see how it is done


addCookie()

This method is used internally by cookie() and plainCookie() methods.
It is used pretty much same way.
It has last parameter $encrypt, which is set to true in cookie(), and to false in plainCookie().

For examples, look above.


deleteCookie()