Backend only WordPress 03

I start testing the redirection to a friendly WordPress backend.

Getting to the admin

In my earlier post I’ve expressed the wish to allow accessing the WordPress admin area in a friendly way mapping it to the /admin path and not the /wp/wp-admin/ one. I will add a first test in the tests/acceptance/BackendRedirectionCest.php to prove the concept

<?php
use \AcceptanceTester;

class BackendRedirectionCest {

    public function _before( AcceptanceTester $I ) {
    }

    public function _after( AcceptanceTester $I ) {
    }

    // other tests...

    /**
     * @test
 * it should redirect to the admin area when accessing /admin with rights
     */
public function it_should_redirect_to_the_admin_area_when_accessing_admin_with_rights(AcceptanceTester $I) {
        $I->wantTo( "go to the wp admin area using the /admin path" );
        $I->amOnPage( '/admin' );
        $I->seeElement( 'body.wp-admin' );
    }
}

but this test will fail
backend redirection fail
To make sure that’s not a false failure I manually browse to the /admin path and, after some redirection magic, end at the /wp/wp-admin path: the test should pass.
It’s a silly mistake: I need some access rights to get to the WordPress admin area and, specifically, will try to access as administrator; I change the test to use one of WP Browser sugar methods

/**
 * @test
 * it should redirect to the admin area when accessing /admin with rights
 */
public function it_should_redirect_to_the_admin_area_when_accessing_admin_with_rights(AcceptanceTester $I) {
    $I->wantTo( "go to the wp admin area using the /admin path" );
    // this will set a session cookie that will be read...
    $I->loginAsAdmin();
    // ...here
    $I->amOnPage( '/admin' );
    $I->seeElement( 'body.wp-admin' );
}

To make sure that what’s happening is what I think I test that a user with no auth cookies set will be redirected to the WordPress login screen

/**
 * @test
 * it should redirect to WordPress login screen when trying to access admin w/o rights
 */
public function it_should_redirect_to_word_press_login_screen_when_trying_to_access_admin_w_o_rights(AcceptanceTester $I) {
    $I->wantTo( "be redirected to the WordPress login when trying to access /admin w/o rights" );
    $I->amOnPage( '/admin' );
    $I->seeElement( 'body.login' );
}

Both the tests will pass confirming my idea. So far so good.
backend redirection success

Next

I will test the /login path and begin some routing work.

Probably related

I appreciate your input