Functional Testing - Imaginary Functional Testing in MODX

Considering what a functional test would look like for MODX

In the previous article, we tested the MODX modUserCreate processor. In this one we'll get our first look at functional testing with Codeception.

MODX logo

This article assumes that you've installed and configured Codeception and PhpUnit. The test files and classes are available at GitHub here.

Functional Testing

Functional testing is best explained in reference to acceptance testing (which we'll see in the following articles). In acceptance testing, the test platform acts as a kind of robot that launches a browser, travels to various pages of a web site, checks the content, fills and submits forms, clicks on links and buttons, and verifies the results. Functional testing does the same thing but with no browser.

Functional testing uses the platform modules provided by Codeception to do what might be called "pseudo-navigation". It mimics the actions that the browser and platform would take.

Codeception has modules for the Symfony2, Laravel5, Yii2, Zend Framework platforms and others. Unfortunately, there's no module for MODX, which is the platform we've been using, though there may be one by the time you read this.

Because there's no module for MODX, we'll have to imagine one (unless one exists). I considered writing a module for MODX, but after a couple dozen articles on software testing, I'm almost out of steam. Maybe later.

Imaginary MODX Module

Here are the most commonly used commands and tests in a platform module:

$I->fillField('username', 'JoeTester');
$I->fillField('password', 'TesterPassword');
// or
$I->see('Welcome, JoeTester!');

In acceptance tests, the process above would launch a browser and actually perform the steps. In a functional platform module, we might use cURL to get the pages and write our own methods for each of the lines above. In MODX, we could speed that up by getting the page referenced by amOnPage() directly from the database, integrate it with its template, and parse it with the MODX parser. We could do something similar with $I->click(). We'd implement fillField() by modifying the $_POST or $_GET array. We'd implement the see... and dontSee... with a string search or with an XPath parser.

Functional Tests Vs Acceptance Tests

Functional tests are more fragile and prone to error than acceptance tests. They're also more likely to generate false errors because of changes made to page code and CSS, and they're not very good at distinguishing visible from hidden elements. On the other hand, they are *much* faster.

Since Functional tests essentially test the same things as acceptance tests, which are much more reliable, many people skip functional testing and just create acceptance tests to make sure things work as they should.

In the following articles, we'll see acceptance testing in action.

Coming Up

In the next article, we'll take a look at acceptance testing in MODX with Codeception.

For more information on how to use MODX to create a web site, see my web site Bob's Guides, or better yet, buy my book: MODX: The Official Guide.

Looking for high-quality, MODX-friendly hosting? As of May 2016, Bob's Guides is hosted at A2 hosting. (More information in the box below.)

Comments (0)

Please login to comment.