Route Page One landed

Failure is mine

Getting back to the last failing test
Codeception output of page generation failing test
I’ve tracked the problem down to a dumb error of mine. The method RoutePages_PageManager::createRoutePages will use WordPress environment functions to work and those are not loaded when I make the call: the option and the functions will return null breaking the test.

Success at last

The simple solution is to use a more macro approach for the test using WordPress UI to do it; I’ve modified the test to

<?php

class PageGenerationCest
{
    /**
     * @test
     * it should create a route page if a persisted route meta info is in the db
     */
    public function it_should_create_a_route_page_if_a_persisted_route_meta_info_is_in_the_db(AcceptanceTester $I)
    {
        // Prepare
        // arrays are stored serialized in wp db
        $routeMeta = serialize(array('route-one' => array('title' => 'Route one', 'permalink' => 'route-one', 'generate' => 'page')));
        $I->haveOptionInDatabase(RoutePages_GeneratingRoute::OPTION_ID, $routeMeta);

        // Execute
        $I->loginAsAdmin();
        $I->amOnPluginsPage();
        $I->activatePlugin('wp-router');
        $I->activatePlugin('route-pages');

        // Verify
        $I->amOnPagesPage();
        $I->see('Route one', '.page-title');
    }
}

and that works. The “Route one” page is created with the proper permalink (given a /%postname%/ permalink structure) with no user intervention but the plugin activation.
The route page generated for the Route One appears in the Pages administration screen

Next step

Activating the plugin will automatically generate a page for each route supposed to generate one but that might not be the desired behaviour.
I’d like the plugin to enable the generation of route pages when explicitly requested by the administrator and that means backend UI to a later stage and isolating the page creation process now.
While I still want to test the plugin at the acceptance level I also want to nail down the generation, removal and updating of route pages to a more functional level and will hence move into that testing scope next.
The functional part will also need loading WordPress on the machine running the tests and that will be the goal of my next effort.

Probably related

One thought on “Route Page One landed

I appreciate your input