Testing MagentoFlorinel Chis
@florinelchis
London Magento User Group – December Meetup
whoami
Fully managed cloud PaaS for Magento
Co-Founder and Chief Service Officer
- Development Lead at Warner Music- 11 years in e-commerce- Magento since 2008
Magento Testing
• Unit Testing
– Tools
– EcomDev_PHPUnit
• Functional Testing (CasperJS)
• Performance Testing
– Web page performance testing
– XHProf, Aoe_Profiler
• Resources
Unit Testing
• Available tools:
– plain phpunit
–MTAF
– EcomDev_PHPUnit
– TechDivision_MagentoUnitTesting
–Mage-Test
Plain phpunit
• Test API calls
• Test libraries
• Other basic tests
• Any other aspect of Magento that is
not dependent on things like session
• Requires lots of effort in “setUp()”
EcomDev_PHPUnit
• Integrated with Magento
• Supports Fixtures
• You can test pretty much any aspect
of Magento (Controllers, Models,
Layout, Config, etc)
Database settings
• app/etc/local.xml.phpunit
<phpunit>
<allow_same_db>?</allow_same_db>
</phpunit>
• 0
– Requires a separate db for the tests
• 1
– You can use the same db that Magento uses (local.xml)
Note: Fixtures will delete all existing records (@see ::apply() function in
Fixture/Processor/*)
Module Structure
#Namespace/Module/etc/config.xml <phpunit> <suite> <modules> <Namespace_Module /> </modules> </suite> </phpunit>
#Test files:Namespace/Module/Test/PathTo/Class.phpNamespace/Module/Test/fixtures/*.yamlNamespace/Module/Test/expectations/*.yamlNamespace/Module/Test/providers/*.yaml
Testing Emails
• Extend
Mage_Core_Model_Email_Template
• Mailcatcher.me (+API)
Mage_Core_Model_Email_Template
Mage::getConfig()->setNode(
'global/models/core/rewrite/email_template',
'Namespace_Test_Model_Email_Template'
);
// This is a hack to get the runtime config changes to take
effect
Mage::getModel('core/email_template');
$mailTemplate = Mage::getModel('core/email_template');
//… do your stuff
Note: https://github.com/MageTest/Mage-Test is the inspiration
for this approach
Mailcatcher configuration
$ gem install mailcatcher
$ mailcatcher
php.ini:
sendmail_path = /usr/bin/env catchmail -f [email protected]
#REST API:
/messages
/messages/1.plain
/messages/1.json
Mailcatcher
CI Integration
• jenkins-php.org
• Book: Integrating PHP Projects with
Jenkins by Sebastian Bergmann
Examples
• Unit Test Demo
Functional Testing with CasperJS
“CasperJS is an open source navigation scripting & testing
utility”
• Writtern for PhantomJS or SlimerJS
• Good for “writing functional test suites,
saving results as JUnit XML”
• Other cool features: take screenshots, test
remote DOM, scrape web documents
‘No more CAPTCHAs, end robot
discrimination’
Why CasperJS
• Friendly
• Javascript
• Quick
• Simple
Performance testing
• Web Page
– webpagetest.org
– PageSpeed
– YSlow
– other tools
• Magento
• CI Integration
– webpagetest.org API
– PhantomJS + YSlow
PhantomJS + YSlowphantomjs yslow.js http://yslow.org
phantomjs yslow.js -i grade -f xml www.yahoo.com www.cnn.com
www.nytimes.com
phantomjs yslow.js --info all --format plain --ua "MSIE 9.0"
http://yslow.org
phantomjs yslow.js -i basic --rulseset yslow1 -d http://yslow.org
phantomjs yslow.js -i grade -b
http://www.showslow.com/beacon/yslow/ -v yslow.org
phantomjs --load-plugins=yes yslow.js -vp 800x600
http://www.yahoo.com
phantomjs yslow.js -i grade -f tap -t 85 http://yslow.org
CSS Testing
• CSSLint
• PhantomCSS
CSSLint
• csslint --warnings=box-model,ids
filename.css
– [--format=junit-xml | checkstyle-xml]
PhantomCSS
• https://github.com/Huddle/
PhantomCSS
PhantomCSS Tips
• Avoid dynamic data (homepage
menu, banners)
• Use version control for the base
pictures (and make sure you update
them when they should change)
• Use the same OS/browser/viewport
Magento Performance - XHProf
“XHProf is a function-level hierarchical profiler for PHP and has a simple HTML based user interface.”
Magento modules: Demac_Xhprof and Liip_Xhprof
Aoe_Profilerhttps://github.com/fbrnc/Aoe_Profiler
Where to go from here?
• https://github.com/EcomDev/EcomDev_PHPUnit
• http://netzarbeiter.com/media/mm13/
• https://github.com/Vinai/test-frameworks-mm13de
• https://github.com/lilmuckers/magento-lilmuckers_queue
• https://github.com/MageTest
• https://github.com/fbrnc/Aoe_Profiler
• https://github.com/facebook/xhprof
• http://magento.stackexchange.com/
• http://casperjs.org/
Questions?
Thank you.
@florinelchis
http://www.linkedin.com/in/chisflorinel
Fully managed cloud PaaS for Magento
www.elastera.com
Top Related