Running Codeception tests on multiple WordPress environments

Using the –env flag in Codeception. Running tests against multiple versions of WordPress.

Suppose you want to run your test suite against multiple environments? Perhaps with different browsers or with different versions of WordPress or PHP? Codeception makes this easy with the –env flag.

This is a plugin I made that rolls back a new feature added to WordPress 4.9. I want to run an acceptance test against the latest version of WordPress, and also against a legacy version of WordPress.

Setup multiple environments

I use an Ubuntu laptop with apache2. Your mileage will vary. When I develop a website, say site.com, I setup my laptop to redirect site.dev to a local directory on my laptop. There I keep a copy of the production site to work on.

Directions to setup multiple hosts from Rackspace.com

On my machine, I setup two distinct WordPress installs, one at http://localhost and the other at http://wp.dev. One running version 4.9 and the other running version 3.9.

WordPress v 3.9.23
WordPress v 3.9.23

WordPress v 4.9
WordPress v 4.9

In this example, I’ll be running an acceptance test against both versions of WordPress. I’ll need to setup the YML file like this:

I use this command:
bin/codecept run acceptance -vvv --html --env remotehost --env localhost

bin/codecept is the executable [might be wpcept or codecept]
acceptance is the suite
remotehost and localhost are the envs
-vvv very very verbose [one dash]
–html report to html [two dashes]

Codeception runs:

Passing Tests!
Passing Tests!

WordPress Plugin: Change Admin Email

WordPress Plugin: Change Admin Email Setting Without Outbound Email



As of WordPress 4.9, the administrator cannot change the site admin email without outgoing email setup on the server, and recipient email credentials. This plugin restores the admin’s ability to change this setting without sending a confirmation email.

Plugin in the .org repo
Plugin on Github


Bonus BDD!
As a bonus, for developers I’m distributing some BDD Codeception tests with this plugin. The tests are designed to run via the WordPress module from Codeception. To run them, you’ll need composer, selenium, and chrome. To pull the framework, use the instructions here.

I use this as an example of running tests in multiple environments.

When building this, I used TDD / BDD by creating an acceptance test that worked on v3.9 so that I could run the same test against v4.9. This is overkill, but I wanted to show how to run tests against different environments.

7 FREE Plugins

I will help you build a WordPress plugin – 100% for free – in exchange for letting me blog about the experience.


I’m John Dee – an expert WordPress plugin developer. I am going to be making 7 WordPress plugins for business stakeholders using my Behavior Driven Development / Test Driven Development method. This is an attempt to write a book on WordPress plugin development. I’m looking for business partners who wish to get involved.

My claim

Using BDD / TDD, I can decimate production costs and increase quality for WordPress plugin development. Rough guess, I can reduce costs by 90% at most enterprises.

You get


Directions for the toolkit.

  • A WordPress plugin made for you, which you then own, 100%.
  • A development work-flow for your own team to use in the future.
  • A comparison of your current work flow to other small and medium sized development teams. [Except any proprietary information]

Your requirements

  • You must come up with an IDEA for a WordPress plugin. That’s mostly it.
  • You have to pay for programmers. I am a developer – I am an expert programmer who manages other programmers [usually lower skilled, lower paid programmers, but I love working with experts too!]. If you are running an Agile team already, great! If you’re a one man shop, great! If you already have programmers or developers, great! This might be a very large cost, or a very small cost, but I promise it will be cheaper by an exponential factor than you can do on your own. Again, I will receive zero percent of this, and I’m not shilling for someone else. I prefer outsourcers, but if you already employ human beings who know PHP, great let’s use them!
  • This is for WordPress plugins! Business scripting [which is perfect for WordPress], PHP APIs in general, WP-API, PHP SPAs with WP backend etc.
  • This is for backend plugin development, not frontend theme design. Not content, not hosting – although I’ll throw in development hosting if you want it. I use dev servers on AWS, which are nearly free.
  • Assuming this is a business project, you will have to provide for all aspects of your project not specifically related to development. [i.e. if there is a marketing component to your project, you’ll need to manage that.]

Workflow

  • One of the main points I’m trying to develop is the ability to work remotely. All work is done via Skype.
  • I will provide development servers. I use
    cloud based development servers on Amazon AWS domain with some garbage like ec2-34-197-124-101.compute-1.amazonaws.com The main obstacle to doing WordPress BDD is setting up the frameworks. It’s really hard.
    That’s what I bring.
  • Code is stored on Github or Bitbucket. If you require a firewall, no problem. I make everything compatible on any site, so I don’t need access to your production servers. You can do that.
  • I am doing semi strict TDD / BDD. Programmers DO NOT NEED TO UNDERSTAND TDD IN ADVANCE.
  • I’m doing modified pair programming. I monitor the programmers and direct how they write the code. I generally check in every hour with them. This preserves my brain to take a higher level view of the project while the programmer can work doggedly on the smaller scale without worrying about the higher live architecture.
  • Toolkit is 100% open source, Codeception with WordPress module [PHPUnit etc.]

Contact John Dee to get involved.
e. johndeebdd@gmail.com
p. (702)748-5491 [call or text]

Types of WordPress automated tests

state browser database SUT
WP Acceptance tests carries from test to test assumed headfull JS browser [ie. Selenium with Chrome] not reset after each test entire WP application executed with each browser call
Stateless acceptance tests tests run in isolation assumed headless JS browser [ie. PhantomJS] reset after each test entire WP application executed with each browser call
WP Unit tests tests run in isolation assume no browser or only cURL reset after each test WP application NOT executed
WP API tests tests run in isolation cURL only reset after each test WP application is executed

Live MasterMind BDD Group

Sign up to learn Behavior Driven Development in WordPress!

Hi! I’m John Dee. I’m the BDFL here at WordPress BDD. We have a MasterMind group to meet and do BDD in WP!

As a member of the MMG, you will have an opportunity to learn BDD in WordPress, and even get some free work done for your own projects. We take turns building classes and tests for each member of the MMG, so bring your development issues and we’ll solve them, the devops way!

We do a live screencast on Google Hangouts anytime I get 5 people who want to do TDD.

Topics:

  • Setting up CodeCeption for WordPress in the cloud
  • acceptance testing in WordPress
  • unit testing in WordPress
  • Gherkin feature files

Contact John to sign up!

e. johndeebdd@gmail.com
sms. (702)748-5491

WordPress Plugin: CRG FastRegister

Streamline WordPress’ user registration system to login users BEFORE they confirm their emails.

Try it, just enter your email into the
Sign Up for My Newsletter
box on the right!

WordPress has a very clunky registration system. First the user gives their email, then the system emails them a code, then the user has to copy and paste the code to login. A simpler solution is to trust the user about their email on their first login, and then just log them in. This plugin creates a sidebar widget that asks for the user’s email. If they enter a new email, they immediately get logged in. If they enter an existing email, they are forwarded to the standard login page with their email already filled out. This plugin does away with “user names” and just uses email. It also changes the English label “Username” to “Email” in the login form. Finally, it automatically creates a “Nickname” when the user registers. It is an appended email, so “John@doe.com” would be given the automatic nickname “John”. This plugin should work on any site. Activate it and set the sidebar widget and you’re ready to go.

Source: github.com