Acceptance Testing XIX - MODX 3 bootstrap file

Creating a separate bootstrap file for MODX 3


In the previous article, we used environment settings in separate files to run our test in separate browsers. In this one, we'll begin setting up our test to run in MODX 3 as well as MODX 2 by creating separate _bootstrap.php files for the two platforms.


MODX logo

This article assumes that you've installed and configured Composer, Codeception, PhpUnit, MODX, Java, WebDriver, and ChromeDriver as described in earlier articles, and that you've created the acceptance test support files from those articles.


Installing MODX 3

We can't run our test in MODX 3 until we have a MODX 3 installation. At this writing, the instructions for setting up MODX 3 are here.

Put the installation in a directory called modx3 just under your web root (e.g. localhost/). Make a note of your database username and password. When you run setup, MODX 3 will try to create a database, but it doesn't always work. In that case you'll have to create one yourself and then run setup again.

For the MODX Manager credentials, use JoeTester for the Manager username and TesterPassword for the password in case you want to try some of your earlier acceptance tests in MODX 3.


Separate _bootstrap Files

For MODX 3, we'll need to instantiate the MODX 3 object. We'll also need to change the path to the test MODX 3 installation you just created. The current .yml files in the _build/envs/ directory should be close to what you need, but you may have to adjust the paths and URLs for your local setup.

We're going to create a MODX 3 _bootstrap file, but first, to avoid confusion, we're going to create a MODX 2  _bootstrap file. Since you already have a working MODX 2  _bootstrap.php file in the _build/tests/acceptance directory, simply copy it to a file called _bootstrap2.php in the same directory.

Put this comment at the top, just under the PHP tag:

/* MODX 2 _bootstrap file */

Also, add this code at the very end to test and display the exact version number:

$v = $modx->getVersionData();
$name = $v['full_appname'];
$isMODX2 = strpos($name, 'MODX Revolution 2') !== false;
assertTrue($isMODX2);
echo ' - ' . $name;

Now create a new file in that same directory called  _bootstrap3.php with this code:

<?php
/* MODX 3 _bootstrap file */
use Codeception\Util\Fixtures;

require_once 'c:/xampp/htdocs/addons/vendor/autoload.php';
require_once 'c:/xampp/htdocs/addons/vendor/phpunit/phpunit/src/Framework/Assert/Functions.php';

require_once 'c:/xampp/htdocs/modx3/core/model/modx/modx.class.php';
echo "Getting MODX 3";
$modx = new modX();
$modx->getRequest();
$modx->getService('error', 'error.modError', '', '');
$modx->initialize('mgr');
Fixtures::add('modx', $modx);
$v = $modx->getVersionData();
$name = $v['full_appname'];
$isMODX3 = strpos($name, 'MODX Revolution 3') !== false;
assertTrue($isMODX3);
echo ' - ' . $name;

Adjust the paths in the files if necessary. You can try running some of the acceptance test files we created earlier in MODX 3 with a command like this:

codecept run acceptance testname --env modx3

Some will work and some won't. The LoginCest test should run. The files that depend on a local file like the contact form test won't run because the contact form .html file doesn't exist in the MODX 3 installation. Other files may not run because the locators are different in MODX 3. We'll see how to handle that in the next two articles.


Coming Up

In the next article, we'll create new PageObjects for MODX 3.



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.

  (Login)