Tests of WordPress for companies of hosting

Last update: 26 of April of 2020

Table of contents

The companies of hosting can have lodged situated hundreds of Web with WordPress, and for that reason it is important that their configuration is most compatible possible with software.

In order to verify this compatibility, the equipment of the Community Hosting de WordPress makes available a series of PHPUnit tests with which to be able to verify the operation of WordPress in any surroundings.

Requirements

In order to test not much it is necessary. First it is to have an infrastructure with the habitual configuration of your system. On the other hand, a data base in which tests (since can be done it will be created and it destroyed).

Installing the phpunit-test-runner

The phpunit-test-runner is a small piece of tests of PHPUnit specifically thought for companies of hosting. All a documentation exists on this tool. In addition, if you want it, you can make appear the results of your tests in the page of Host Test Results de WordPress.

The tool can be executed of form manual or through a system automated with Travis. In order to see the operation and the objective of this document we will test of form manual.

Installation of the test

First that we will do it will be to unload and to synchronize the tool.

CD /tmp/ git clones https://github.com/WordPress/phpunit-test-runner.git CD phpunit-test-runner/

The following step will be the one to form the surroundings. For it first we will make a copy of the example file and later we will form it.

cp .env.default .env vim .env

The content (of summarized form) can thus be something:

export WPT_PREPARE_DIR=/tmp/wordpress export WPT_TEST_DIR=/tmp/wordpress export WPT_REPORT_API_KEY= export WPT_REPORT_URL= export WPT_DB_NAME=wordpress export WPT_DB_USER=wordpress export WPT_DB_PASSWORD=__PASSWORD export WPT_DB_HOST=localhost export WPT_TABLE_PREFIX=$ \ {WPT_TABLE_PREFIX-wptests_} export WPT_PHP_EXECUTABLE=$ \ {WPT_PHP_EXECUTABLE-php} WPT_PHPUNIT_CMD= WPT_RM_TEST_DIR_CMD= export WPT_SSH_CONNECT= export WPT_SSH_OPTIONS= export WPT_SSH_PRIVATE_KEY_BASE64=

We will form the folder where the tests of unloading of the software of WordPress and the accesses of the data base will be made to be able to prepare the tests.

Proving the test

Before testing we will update all the necessary one to the last version and will activate the configuration of the surroundings.

CD /tmp/phpunit-test-runner/ git pull npm update source .env

From here, we only have to execute the 4 files that make the set of the tests.

First of them it is the system that verifies that the surroundings are ready to work.

php prepare.php

The second of them is the one that realises the tests in himself.

php test.php

Once the tests finish, can be generated report. IF you have formed a user and password will be sent to WordPress.org.

php report.php

This system generates two files in which is the information than it will be sent as answer to the tests that are being analyzed. You can see the content of the files easily.

cat /tmp/wordpress/env.json cat /tmp/wordpress/junit.xml

And, to finish, once you have the finished system, we only have to clean to the files and the data base to be able to realise a following test in another moment.

php cleanup.php

Creating your bot for WordPress.org

IF you want that the test resultses appear in the page of WordPress.org you can create a user for it.

First it will be to create a user in WordPress.org. If your company is called, for example, We are Hosting, LIMITED LIABILITY COMPANY, you can call to your users something as somoshostingbot. Ten in account that the associate account of mail must verify frequently, since post office with respect to the possible operation will arrive from the tests.

Issue in the page of the test creates one asking the inclusion of bot in the page of results as €œReporter Test€, indicating the mail account that you have used with that user.

When he has been created the user in the system will occur access you to a password so that you can form that the system sends the information of automatic form. You will have to enter Users - > Your Profile and to generate the application password there. Later you will be able to modify the constant of the surroundings with something similar to export WPT_REPORT_API_KEY='somoshostingbot: ABCD 1234 abcd 4567 EFGH efgh'.

Proving surroundings from zero

If you want to test in surroundings of development (without needing sending the data), you can do it without trouble. The objective of this test is to work with multiple options and configurations, with the ultimate goal of which you find the best surroundings to work.

Requirements

Although there are some no requisite minimums of in case, in the tests that I have been able to do I have found that, at least, it is recommended:

  • VPS (also local surroundings can be used)
    • 1 CPU
    • 2 GB RAM
    • 10 GB SSD
  • Ubuntu, CentOS, Debian€¦ (the example is with Ubuntu 18,04 LTE)
  • MySQL, MariaDB, for Percona MySQL (the example is with MariaDB 10.4)
  • PHP (the example is with PHP 7.4)

It is necessary to consider that this example does not raise a machine in production, if not an example of different elements and tests that can be executed, telling to the installation cache systems, extensions of PHP€¦

Installation bases

The installation base raises to arrange the minimum elements so that the system works.

Configuration of the Operating system

First that we will do it will be to put the system in hour. In order to avoid problems and considering that can be a machine that sends information to WordPress, the best thing would be to form the clock in way UTC of universal form.

timedatectl UTC set-timezone timedatectl set-NTP on

The following thing that we will do is to put the machine to the day in all their system. With this we will make sure that everything is and that the conflicts are reduced to the minimum.

apt - and update && apt - and upgrade && apt - and dist-upgrade && apt - and autoremove

We will install some necessary and habitual tools as curl, vim, zip or own git.

apt - and install software-properties-common curl vim unzip git

Installation of the data base

We will install MariaDB 10,4 in the test. In principle it serves any compatible data base with WordPress.

curl - foll https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | I sweat bash - s -- --mariadb-server-version= " mariadb-10.4€ apt - and update && apt - and upgrade && apt - and dist-upgrade && apt - and autoremove apt - and install mariadb-server mariadb-client systemctl restart mysql.service

Once finished the installation we will make one first configuration to leave lists it.

mysql_secure_installation

As of this moment the system will do a series to us of questions and we will form the password of root of the own data base.

For Enter current password root (to enter for none): Switch to unix_socket authentication [Y/n] n Change the root password? [Y/n] and Remove anonymous users? [Y/n] and Disallow root login remotely? [Y/n] and Remove test database and Access to it? [Y/n] and Reload privilege tables now? [Y/n] and

We will reinitiate the data base so that it takes all the data and it leaves the ready system.

systemctl restart mysql.service

Installation of PHP

For this test we will install PHP 7.4. Initially we are only going to install the minimum elements, reason why surely we must extend later with some extensions. As it shelp to the home, the objective is to prove the system, reason why at this moment it has sense that us of error for want of elements.

add-apt-repository - and ppa: ondrej/php apt - and update && apt - and upgrade && apt - and dist-upgrade && apt - and autoremove apt - and install php7.4 php7.4-curl php7.4-dev php7.4-fpm php7.4-mbstring php7.4-mysql php7.4-mysqlnd apt - and install to php-pear pkg-config pecl channel-update pecl.php.net

Although we can leave the PHP configuration as we have it in the habitual system that is offered to the clients, for this test we do some small changes.

vim /etc/php/7.4/fpm/php.ini

And we will change these configurations.

max_execution_time = 60 memory_limit = 256M post_max_size = 128M upload_max_filesize = 128M date.timezone = €˜UTC€™

Once the reconfiguration would finalize, we will reinitiate the service and we will activate it by defect.

systemctl stop php7.4-fpm.service systemctl inable php7.4-fpm.service systemctl start php7.4-fpm.service

Installation of Node

So that the tests work correctly we will need some elements that habitually are not perhaps available. Among them ets¡ NodeJS, Grunt and PhantomJS.

First we installed NodeJS

CD curl - sL https://deb.nodesource.com/setup_13.x | bash - apt - and update && apt - and upgrade && apt - and dist-upgrade && apt - and autoremove apt - and install nodejs

Later we installed Grunt

npm install - g grunt

And finally we installed PhantomJS

apt - and install build-essential chrpath libssl-dev libxft-dev libfreetype6 libfreetype6-dev libfontconfig1 libfontconfig1-dev CD wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2 to tar xvjf phantomjs-2.1.1-linux-x86_64.tar .bz2 - C /usr/local/share/ ln - sf /usr/local/share/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin rm - RF phantomjs-2.1.1-linux-x86_64.tar .bz2

Finalizing the configuration

In order to finish the configuration of the machine, we will make some adjustments. In order to begin, we will update everything again and we made sure that it has not been any hung library.

apt - and update && apt - and upgrade && apt - and dist-upgrade && apt - and autoremove

And we will form the data base of tests that we are going to use in the test. We will enter the servant.

mysql - or root - p

And we will create a data base of test. In this case wordpress will be called and the user also will be wordpress. He forms the password that you see advisable.

Wordpress CHARACTER CREATES DATABASE to YOU SET = utf8mb4 COLLATE = utf8mb4_bin; GRANT ALL ON wordpress.* TO €˜wordpress'@'localhost€™ IDENTIFIED BY €˜__PASSWORD€™; GRANT ALL ON wordpress.* TO €˜wordpress'@'127.0.0.1€™ IDENTIFIED BY €˜__PASSWORD€™; FLUSH PRIVILEGES; quit

As of this moment we have all the base to be able to make our first test.

Installation of the PHPUnit test

We will follow the instructions that we have had previously. By defect we will test in the /tmp/ folder.

CD /tmp/ git clones https://github.com/WordPress/phpunit-test-runner.git CD /tmp/phpunit-test-runner/ cp .env.default .env

And we will establish the contents of the surroundings with the access data that we have created previously.

vim .env

It remembers to include the folder where software is installed and where WordPress will be installed, in addition to the data of access to the data base.

export WPT_PREPARE_DIR=/tmp/wordpress export WPT_TEST_DIR=/tmp/wordpress export WPT_REPORT_API_KEY= export WPT_REPORT_URL= export WPT_DB_NAME=wordpress export WPT_DB_USER=wordpress export WPT_DB_PASSWORD=__PASSWORD export WPT_DB_HOST=localhost export WPT_TABLE_PREFIX=$ \ {WPT_TABLE_PREFIX-wptests_} export WPT_PHP_EXECUTABLE=$ \ {WPT_PHP_EXECUTABLE-php} WPT_PHPUNIT_CMD= WPT_RM_TEST_DIR_CMD= export WPT_SSH_CONNECT= export WPT_SSH_OPTIONS= export WPT_SSH_PRIVATE_KEY_BASE64=

Preparing the surroundings

Before testing first, we will bring up to date all. This process can be executed before testing each in this surroundings if we want to have it to the day, although will depend more if it is in surroundings in production.

apt - and update && apt - and upgrade && apt - and dist-upgrade && apt - and autoremove CD /tmp/phpunit-test-runner/ git pull npm update source .env

Preparing the test

Now that we have the ready surroundings, we can execute the preparation of the test.

CD /tmp/phpunit-test-runner/ php prepare.php

The system will execute one long series of facilities, configurations and compilations of different elements to be able to prepare the test. If they leave warnings and warnings you would not have to worry much, since it is quite normal. The fnal of the process it will warn to you if it needs something that it does not have. In principle, it would have to be something like this:

It donates. Replacing variable in wp-tests-config.php Success: Prepared environment.

If the surroundings have been preparation, the following step is to test one first.

Executing the test

Now that already we have the ready surroundings, we go to by the test. For it we will execute the file that will realise it.

CD /tmp/phpunit-test-runner/ php test.php

What means the symbols?

  • .: Each point means that the test has been passed correctly.
  • S: It means that the test has skipped. Usually it is because these tests are only valid in certain configurations.
  • F: It means that the test has failed. In the end it appears information of because.
  • E: It means that the test has failed due to a PHP error, that can be error, warning or notice.
  • I: It means that the test has been marked as incomplete.

If you have followed all the passages until this moment are very probable that the test that you have executed fails enough (for example, because by defect it will not be able to make the treatment of images). But it does not pass anything, since I have commented, this is an example to verify and to verify the operation.

Creating a report

Although the test has failed, we can generate the report and (if the case occurred) send it. But first first, that is the creation of the information. For it we will execute the file that does.

CD /tmp/phpunit-test-runner/ php report.php

This system will both generate files that are sent as information.

In first of them we can see the information on our surroundings.

cat /tmp/wordpress/env.json

The content of this file is something similar to this:

\ {€œphp_version€: €œ7.4.5€, €œphp_modules€: \ {€œbcmath€: false, €œcurl€: €œ7.4.5€, €œto filter€: €œ7.4.5€, €œgd€: false, €œlibsodium€: false, €œmcrypt€: false, €œmod_xml€: false, €œmysqli€: €œ7.4.5€, €œimagick€: false, €œpcre€: €œ7.4.5€, €œxml€: €œ7.4.5€, €œto xmlreader€: €œ7.4.5€, €œzlib€: €œ7.4.5€}, €œsystem_utils€: \ {€œcurl€: €œ7.58.0 (x86_64-pc-linux-gnu) libcurl \/7.58.0 OpenSSL \/1.1.1g zlib \/1.2.11 libidn2 \/2.3.0 libpsl \/0.19.1 (+libidn2 \/2.0.4) nghttp2 \/1.30.0 librtmp \/2,3€, €œghostscript€: "", €œimagemagick€: false, €œopenssl€: €œ1.1.1g 21 Apr 2020€}, €œmysql_version€: €œmysql Ver 15,1 Distrib 10.4.12-MariaDB, for debian-Linux-gnu (x86_64) using readline 5,2€, €œos_name€: €œLinux€, €œos_version€: €œ4.15.0-20-generic€}

As it is possible to be verified, between the detacados elements more they are the extensions that habitually are used in WordPress and some utilities that by general norm are also ºltiles.

The other file is the one that includes all the tests that are realised (more than 10,000) giving information of the time which they tandan in executing itself, problems that have been able to arise€¦

cat /tmp/wordpress/junit.xml

Cleaning the surroundings for other tests

Now that already we have the tests working, which we have left to do is to eliminate all the files that have been created to be able to return to begin. For it we will execute the following commando:

CD /tmp/phpunit-test-runner/ php cleanup.php

Improving the configuration

It is not necessary to forget that the objective of this tools is the verification of which our surroundings and infrastructure are o³ptima so that WordPress works, reason why, following the example of before, we could make several improvements as the installation of the extension of bcmath, gd, libsodium, mcrypt, mod_xml and imagick or utilities as ghostscript and imagemagick.

The objective? That there are not errors and to have green light for the perfect configuration.

Equipment of Hosting in the WordPress Community

IF you are a company that somehow is in the day to day to offer services related to WordPress I recommend you that you follow kind publications of the Hosting equipment of the WordPress Community, in addition to kindly following the conversations of the channel of Slack #hosting-community (to see the schedules of meetings of the equipment), where you could be in touch with the people in charge of other companies of hosting.