Backend only WordPress 02

I setup a first test and look into bare bones routing for a backend WordPress installation.

Installing WordPress

With a fresh installation from the previous post I go through WordPress 5 minutes install.
With a root domain of http://test.local I browse to the /wp/wp-admin/install.php file and find the installation screen
WordPress 5 minute install
and after going through the installation process I end up in WordPress admin area at the relative path of /wp/wp-admin/.

Getting to the admin

Since I will be using WordPress for the backend alone by now I will not follow the procedure to give WordPress its own directory but would like to deal with the backend access procedure.
Imagining a WordPress site installed and configured like this I’d like the client to be able to access the backend using an easier path than the /wp/wp-admin/ one: ideally /admin should redirect there.

The first test

I will use the .htaccess file to do redirect the user to the proper path and will use Codeception to try out the first path. I bootstrap WP Browser in the project root folder

wpcept bootstrap

and see its expected output
wpcept bootstrap
After that I create the first acceptance test

codecept generate:cest acceptance BackendRedirection

to end up with a skeleton BackendRedirectionCest.php file in the tests/acceptance folder.

<?php
use \AcceptanceTester;

class BackendRedirectionCest {

    public function _before( AcceptanceTester $I ) {
    }

    public function _after( AcceptanceTester $I ) {
    }
}

I add a first test to make sure that pointing to the / relative path will land me in the site index page. To make the verification easier I’ve added an index class to the body element to have something to target for the test; the class prove useful in the project development and it’s a replica of the WordPress body_class function.
Adding the first test method to the cest file I run it to verify that’s working

<?php
use \AcceptanceTester;

class BackendRedirectionCest {

    public function _before( AcceptanceTester $I ) {
    }

    public function _after( AcceptanceTester $I ) {
    }

    /**
     * @test
     * it should allow accessing the index going to the site root
     */
    public function it_should_allow_accessing_the_index_going_to_the_site_root(AcceptanceTester $I) {
        $I->wantTo( "go to the index page accessing the root path" );
        $I->amOnPage( '/' );
        $I->seeElement( 'body.index' );
    }
}

I get a passing test on the first run so that’s working for the moment
/ path test
The current version of the .htaccess file is the one below

RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteRule ^login/*(.*) /wp/wp-login.php$1 [L]
RewriteRule ^admin(/*)(.*) /wp/wp-admin$1$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /index.php [L]

While it’s currently working I might change it as the testing goes on.

Configuring the suite

While it’s a known drill to me the configuration of WP Browser might not be trivial if a little experience with Codeception is not in place already; this is the current project configuration I’m using, the content of the codeception.yml file in the project root folder. Some parameters apply to my configuration only but it might be used as a guideline nonetheless

actor: Tester
paths:
    tests: tests
    log: tests/_output
    data: tests/_data
    helpers: tests/_support
settings:
    bootstrap: _bootstrap.php
    colors: true
    memory_limit: 1024M
modules:
    config:
        Db:
            dsn: 'mysql:host=127.0.0.1;dbname=wordpress-tests'
            user: root
            password: root
            dump: tests/_data/dump.sql
        WPBrowser:
            url: 'http://test.local'
            adminUsername: root
            adminPassword: root
            adminUrl: /wp/wp-admin
        WPDb:
            dsn: 'mysql:host=127.0.0.1;dbname=wordpress-tests'
            user: root
            password: 'root'
            dump: tests/_data/dump.sql
            populate: true
            cleanup: true
            url: 'http://test.local'
            tablePrefix: wp_
            checkExistence: true
            update: true
        WPLoader:
            wpRootFolder: /Users/Luca/Dropbox/Developer/WebDeveloper/websites/test/wp
            dbName: wordpress-tests
            dbHost: 127.0.0.1
            dbUser: root
            dbPassword: root
            wpDebug: true
            dbCharset: utf8
            dbCollate: ''
            tablePrefix: wp_
            domain: test.local
            adminEmail: [email protected]
            title: 'Test'
            phpBinary: php
            language: ''

Next

I test the other paths and begin some tinkering.

I appreciate your input