SlideShare a Scribd company logo
WELCOME!
Testing in Craft CMS
Charlotte Craft CMS Meetup
Nov 13, 2019
Justin Holt - Presenter
Thank You
Providing
Meeting
Hosting
Sponsoring
Food &
Beverages
Testing in Craft CMS
Agenda
1. How can tests help? 

Are they worth the effort?
2. Types of tests.
3. Craft and Codeception
4. How to run Codeception tests in
Craft.
5. Tips for successful testing.
6. Testing modules and plugins.
7. Mock data with Fixtures.
8. Offloading tests to Queue.
9. Other kinds of tests.
10. Wrap up.
How can tests help? 

Edge Cases
New Developers
You* 

(one year later on same project)
Are they worth the effort?
Scale your level of effort
- One and done? (prob not)
- Maintenance & kicking can down the
road? (might be worth it)
- Crucial workflow, several developers?
(most def)
- Bleeding edge? (Yes but only stable)
Types of Tests
Manual tests (you already run these)

Refresh page, submit form, click stuff. 

Log what happens.
Somewhat measurable.
Somewhat repeatable.
Types of Tests
Unit tests
Test specific results from a single “action”.
Test results of a function, possibly classes.
Measurable, repeatable.
In Craft, unit tests will primarily cover Services.
Test high in the call trace.
Save Controller method testing for functional.
Types of Tests
Functional / Acceptance tests
Test complete package from USER perspective.
Primarily will test your Craft Controller methods.
Typical Controller functional flow:
1) Process a request.
2) Invoke Craft services (Unit test)
3) Return a response
Testing is all about strategy and
approaches. Manual testing and automated
testing work best together. You can use
your judgement to detect/prevent issues
that computers cannot see whilst computers
can execute many tests in short time.
Tip:
Pixel & Tonic
Craft & Codeception
+
Codeception in Craft
Fully featured PHP testing suite.
Requires Craft v3.2
Possible prior, requires bootstrapping
Yii Codeception module yourself.
How to run Codeception
tests in Craft
1. Installing Codeception.
2. Setting up required directories.
3. Setting up required files.
4. Setting up required config.
5. Codeception requirements.
6. Adding a test.
7. Running a test.
Installing Codeception
Install via composer in project root:
Installing Codeception
Test that Codeception installed correctly.
Setting up required
directories.
In your /tests dir create /_craft
In your /_craft create: 

/storage
/templates
/migrations
/config
/translations
You can also copy/paste from your existing dirs
Into /tests/_craft for testing sites.
Command line:
Setting up required
directories.
Bootstrap file
structure
Setting up required directories.
Setting up required
files.
Open /codeception.yaml
Replace with:
Setting up required
files.
Create /tests/.env
Populate variables:
Setting up required
files.
Create /tests/_bootstrap.php
Add:
Setting up required
files.
Create /tests/_craft/config/test.php
Add:
Setting up required
files.
Check /tests/acceptance.suite.yml
/tests/functional.suite.yml
/tests/unit.suite.yml
Ensure Codeception module is added:
Setting up required
config.
Add /tests/_craft/configdb.php
Codeception
Requirements.
Add /tests/unit/_bootstrap.php
/tests/functional/_bootstrap.php
/tests/acceptance/_bootstrap.php
Codeception will only run these when told.
You can run test-type specific business logic.
Adding a Test.
Add /tests/unit/ExampleTest.php
Codeception will use
UnitTester and Craft
classes to check the
Craft Edition for
“Pro” using 

$this->assertSame(…).
Running a Test.
Running a Test.
Running a Real World Test.
Add /tests/acceptance/SeasonActiveHomeCest.php
Codeception will use
AcceptanceTester and
Craft classes to
check the presence
of a schedule
carousel based on
element/classname.
Running a Real World Test.
Running a Real World Test.
Tips for Successful
Testing
Maintain your Database using
cleanup and transaction.
Cleanup ensures removal of any
Fixture data in your DB during your test.
Transaction ensures any DB changes are
rolled back using a Yii2 transaction.
Tips for Successful
Testing
Use .gitignore for /storage
And also new /tests/_output/.
Stick to the namespaces conventions
unit, functional, acceptance.
Testing Modules &
Plugins
Modules: once registered as normal
the module will be loaded and available
via MyModule::getInstance() to your test suites.
Plugins: Register in codeception.yml
then the plugin will be loaded and available
via MyPlugin::getInstance() to your test suites.
Testing Modules &
Plugins
Plugins: Register in codeception.yml
Mock Data with Fixtures
Fixtures: used to setup data in a test suite
That is predictable and the
same for each test run.
Craft gives us extras for Fixtures of Craft data:
Element, Asset, Category, Entry, Global set, Tag,
User and Element fixtures.
Extend crafttestfixtureselements…Fixture
Offloading Tests to Queue
1. Ensure your test class has a $tester property.
2. Call the following method:
First argument is the class of your job.
Second argument is any arguments
to pass to your job.
Other Kinds of Tests
-Testing emails with Mailtrap
-Visual Regression testing
tools and services
-Form Testing
-Testing at Twig level
-Performance, A11y tests (in
browser)
Testing Emails with
Mailtrap
Signup for account on website.
Copy credentials from SMTP settings.
Add to .env:
Testing Emails with
Mailtrap
Edit /config/app.php:
Testing Emails with
Mailtrap
Now all emails going out from Craft
including System messages and any
custom methods, will land at Mailtrap
in your account for testing and debugging.
*Free account = 500/month limit
Visual Regression testing
tools and services
Form Testing
-Validation.
-Honeypots 

(kind of).
-Recaptchas.
-Trap submission
notifications with
Mailtrap.
We already do most
of this!
Form Testing
Testing at Twig Level
Testing at Twig Level
Performance/A11y Testing
-Lighthouse (in Chrome devtools)
-Google Pagespeed
-webpagetest.org
-GTMetrix.com
-aXe tool (commandline)
-pA11y tool (commandline)
-KoA11y tool (gui)
-Google Accessibility Developer Tools
-Tenon.io
Thank You!
Thank You
Providing
Meeting
Hosting
Sponsoring
Food &
Beverages
Thank You!

More Related Content

PDF
Data Visualization 101: How to Design Charts and Graphs
PPT
Learn MS Powerpoint basics
PPTX
Ms Excel
PPT
Microsoft Excel VLOOKUP Function
PPTX
Gatways And Portal
DOC
Function of microsoft word
PPTX
What is ETL testing & how to enforce it in Data Wharehouse
PPTX
Data Visualization 101: How to Design Charts and Graphs
Learn MS Powerpoint basics
Ms Excel
Microsoft Excel VLOOKUP Function
Gatways And Portal
Function of microsoft word
What is ETL testing & how to enforce it in Data Wharehouse

What's hot (20)

PPT
Digital and Electronic Libraries
PPTX
Data Analysis with MS Excel.pptx
PDF
Digital Analytics Bar Graph Line Chart
DOCX
Introduction to ms word
PDF
Academic library system in Europe, India, UK and USA: A brief overview
PDF
USE OF MOBILE TECHNOLOGY IN LIBRARY AND INFORMATION SERVICES
PPT
New Education Policy (NEP)-2020 and Digital Library Services
PPTX
PPT On Microsoft Excel 2007 Full Information.
PPTX
Ms word 2013
PPTX
Using Excel Functions
PPTX
power point presentation
PPTX
INTRODUCTION TO MS EXCEL 2010
PPTX
Evidence based nursing resources
PPTX
Spreadsheet Concepts
PPTX
Search strategy
PPTX
Circulation control presentation new
PPTX
PowerPoint basics
PPTX
Ms excel ppt
PPT
World cat
Digital and Electronic Libraries
Data Analysis with MS Excel.pptx
Digital Analytics Bar Graph Line Chart
Introduction to ms word
Academic library system in Europe, India, UK and USA: A brief overview
USE OF MOBILE TECHNOLOGY IN LIBRARY AND INFORMATION SERVICES
New Education Policy (NEP)-2020 and Digital Library Services
PPT On Microsoft Excel 2007 Full Information.
Ms word 2013
Using Excel Functions
power point presentation
INTRODUCTION TO MS EXCEL 2010
Evidence based nursing resources
Spreadsheet Concepts
Search strategy
Circulation control presentation new
PowerPoint basics
Ms excel ppt
World cat
Ad

Similar to Testing in Craft CMS (20)

PDF
Gallio Crafting A Toolchain
PDF
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
PDF
TDD for joomla extensions
PPT
Nguyenvandungb seminar
PPTX
Code igniter unittest-part1
PPTX
Automated Acceptance Tests & Tool choice
PDF
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
PPT
Stopping the Rot - Putting Legacy C++ Under Test
PPT
Review of an open source unit test tool- Cucumber_Presentation
PPT
Justmeans power point
PPT
Assessing Unit Test Quality
PPT
Testing Options in Java
PDF
Testing - How Vital and How Easy to use
PPSX
Test Complete
PPTX
Useful practices of creation automatic tests by using cucumber jvm
PDF
[xp2013] Narrow Down What to Test
PDF
Python and test
PPTX
Presentation
PPT
Behavior Driven Development by Example
PPT
Simple tools to fight bigger quality battle
Gallio Crafting A Toolchain
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
TDD for joomla extensions
Nguyenvandungb seminar
Code igniter unittest-part1
Automated Acceptance Tests & Tool choice
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Stopping the Rot - Putting Legacy C++ Under Test
Review of an open source unit test tool- Cucumber_Presentation
Justmeans power point
Assessing Unit Test Quality
Testing Options in Java
Testing - How Vital and How Easy to use
Test Complete
Useful practices of creation automatic tests by using cucumber jvm
[xp2013] Narrow Down What to Test
Python and test
Presentation
Behavior Driven Development by Example
Simple tools to fight bigger quality battle
Ad

Recently uploaded (20)

PPTX
artificial intelligence overview of it and more
PPT
FIRE PREVENTION AND CONTROL PLAN- LUS.FM.MQ.OM.UTM.PLN.00014.ppt
PPTX
artificialintelligenceai1-copy-210604123353.pptx
DOCX
Unit-3 cyber security network security of internet system
PPT
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
PDF
Exploring VPS Hosting Trends for SMBs in 2025
PDF
FINAL CALL-6th International Conference on Networks & IOT (NeTIOT 2025)
PDF
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
PPTX
Database Information System - Management Information System
PPTX
Internet___Basics___Styled_ presentation
PDF
💰 𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓 💰
PDF
SASE Traffic Flow - ZTNA Connector-1.pdf
PPTX
newyork.pptxirantrafgshenepalchinachinane
PPT
250152213-Excitation-SystemWERRT (1).ppt
PPTX
Module 1 - Cyber Law and Ethics 101.pptx
PDF
Smart Home Technology for Health Monitoring (www.kiu.ac.ug)
PPTX
Introduction to cybersecurity and digital nettiquette
PDF
Sims 4 Historia para lo sims 4 para jugar
PPTX
INTERNET------BASICS-------UPDATED PPT PRESENTATION
DOC
Rose毕业证学历认证,利物浦约翰摩尔斯大学毕业证国外本科毕业证
artificial intelligence overview of it and more
FIRE PREVENTION AND CONTROL PLAN- LUS.FM.MQ.OM.UTM.PLN.00014.ppt
artificialintelligenceai1-copy-210604123353.pptx
Unit-3 cyber security network security of internet system
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
Exploring VPS Hosting Trends for SMBs in 2025
FINAL CALL-6th International Conference on Networks & IOT (NeTIOT 2025)
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
Database Information System - Management Information System
Internet___Basics___Styled_ presentation
💰 𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓 💰
SASE Traffic Flow - ZTNA Connector-1.pdf
newyork.pptxirantrafgshenepalchinachinane
250152213-Excitation-SystemWERRT (1).ppt
Module 1 - Cyber Law and Ethics 101.pptx
Smart Home Technology for Health Monitoring (www.kiu.ac.ug)
Introduction to cybersecurity and digital nettiquette
Sims 4 Historia para lo sims 4 para jugar
INTERNET------BASICS-------UPDATED PPT PRESENTATION
Rose毕业证学历认证,利物浦约翰摩尔斯大学毕业证国外本科毕业证

Testing in Craft CMS